diff --git a/gradle.properties b/gradle.properties index 383066f..1e55351 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx8G org.gradle.daemon=false -my_version=1.3.6.4 +my_version=1.3.6.7 mc_version=1.19.2 forge_version=43.2.3 diff --git a/run/options.txt b/run/options.txt index d48b5fa..dc9697e 100644 --- a/run/options.txt +++ b/run/options.txt @@ -111,6 +111,7 @@ key_key.hotbar.6:key.keyboard.6 key_key.hotbar.7:key.keyboard.7 key_key.hotbar.8:key.keyboard.8 key_key.hotbar.9:key.keyboard.9 +key_key.otemod.open_vault:key.keyboard.v:ALT soundCategory_master:1.0 soundCategory_music:0.08862526 soundCategory_record:1.0 diff --git a/src/main/java/dev/zontreck/otemod/OTEMod.java b/src/main/java/dev/zontreck/otemod/OTEMod.java index 375836c..8cf8174 100644 --- a/src/main/java/dev/zontreck/otemod/OTEMod.java +++ b/src/main/java/dev/zontreck/otemod/OTEMod.java @@ -19,6 +19,8 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.world.entity.player.Player; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.client.event.InputEvent; +import net.minecraftforge.client.event.RegisterKeyMappingsEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.world.BiomeModifier; import net.minecraftforge.eventbus.api.IEventBus; @@ -57,6 +59,7 @@ import dev.zontreck.otemod.implementation.vault.VaultScreen; import dev.zontreck.otemod.implementation.vault.VaultWatcher; import dev.zontreck.otemod.items.ModItems; //import dev.zontreck.otemod.ore.Modifier.ModifierOfBiomes; +import dev.zontreck.otemod.networking.ModMessages; // The value here should match an entry in the META-INF/mods.toml file @Mod(OTEMod.MOD_ID) @@ -122,6 +125,7 @@ public class OTEMod private void setup(final FMLCommonSetupEvent event) { + ModMessages.register(); } @@ -138,13 +142,6 @@ public class OTEMod return true; } - - private void commonSetup(final FMLCommonSetupEvent event) - { - // Some common setup code - //LOGGER.info("HELLO FROM COMMON SETUP"); - //LOGGER.info("DIRT BLOCK >> {}", ForgeRegistries.BLOCKS.getKey(Blocks.DIRT)); - } // You can use SubscribeEvent and let the Event Bus discover methods to call @SubscribeEvent @@ -243,10 +240,11 @@ public class OTEMod } - @OnlyIn(Dist.DEDICATED_SERVER) @SubscribeEvent public void onItemExpire(final ItemExpireEvent ev) { + if(ev.getEntity().level.isClientSide)return; + if(OTEServerConfig.ITEM_DESPAWN_TIMER.get()<=0)return; @@ -266,7 +264,7 @@ public class OTEMod } - @OnlyIn(Dist.DEDICATED_SERVER) + @SubscribeEvent public void onStop(final ServerStoppingEvent ev) { @@ -292,6 +290,7 @@ public class OTEMod //ItemBlockRenderTypes.setRenderLayer(ModBlocks.AURORA_DOOR.get(), RenderType.translucent()); } + } } diff --git a/src/main/java/dev/zontreck/otemod/chat/ChatServerOverride.java b/src/main/java/dev/zontreck/otemod/chat/ChatServerOverride.java index 96a1906..f1bf9df 100644 --- a/src/main/java/dev/zontreck/otemod/chat/ChatServerOverride.java +++ b/src/main/java/dev/zontreck/otemod/chat/ChatServerOverride.java @@ -12,11 +12,15 @@ import dev.zontreck.otemod.OTEMod; import dev.zontreck.otemod.configs.OTEServerConfig; import dev.zontreck.otemod.configs.PlayerFlyCache; import dev.zontreck.otemod.configs.Profile; +import dev.zontreck.otemod.enchantments.ModEnchantments; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.player.Abilities; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.event.ServerChatEvent; @@ -28,11 +32,12 @@ import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @EventBusSubscriber(modid=OTEMod.MOD_ID, bus=Mod.EventBusSubscriber.Bus.FORGE) public class ChatServerOverride { - @OnlyIn(Dist.DEDICATED_SERVER) @SubscribeEvent public void onJoin(final PlayerEvent.PlayerLoggedInEvent ev) { //Player joined, send custom alert + if(ev.getEntity().level.isClientSide)return; + ServerPlayer play = (ServerPlayer)ev.getEntity(); // Download user data from database try{ @@ -48,18 +53,17 @@ public class ChatServerOverride { has_profile=true; - OTEMod.PROFILES.put(ev.getEntity().getStringUUID(), new Profile(rs.getString("username"), rs.getString("prefix"), rs.getString("nickname"), rs.getString("name_color"), ev.getEntity().getStringUUID(), rs.getString("prefix_color"), rs.getString("chat_color"))); + OTEMod.PROFILES.put(ev.getEntity().getStringUUID(), new Profile(rs.getString("username"), rs.getString("prefix"), rs.getString("nickname"), rs.getString("name_color"), ev.getEntity().getStringUUID(), rs.getString("prefix_color"), rs.getString("chat_color"), rs.getBoolean("flying"))); } if(!has_profile) { // Create profile! - ServerPlayer play = (ServerPlayer)ev.getEntity(); Profile p = Profile.factory(play); OTEMod.PROFILES.put(play.getStringUUID(), p); p.commit(); // Commits the profile to the server - ev.getEntity().displayClientMessage(Component.literal(ChatColor.BOLD+ ChatColor.DARK_GRAY + "["+ChatColor.DARK_GREEN + "OTEMOD" + ChatColor.DARK_GRAY + "] "+ChatColor.DARK_GREEN + "First join! Your server profile has been created"), false); + ev.getEntity().displayClientMessage(Component.literal(ChatColor.doColors( OTEMod.OTEPrefix +" !Dark_Green!First join! Your server profile has been created")), false); } }catch (SQLException e){ e.printStackTrace(); @@ -70,17 +74,36 @@ public class ChatServerOverride { return; } + if(prof.flying) + { + play.getAbilities().flying=true; + play.onUpdateAbilities(); + } + + Abilities playerAbilities = play.getAbilities(); + boolean mayFly = false; + ItemStack feet = play.getItemBySlot(EquipmentSlot.FEET); + ItemStack legs = play.getItemBySlot(EquipmentSlot.LEGS); + if(feet.getEnchantmentLevel(ModEnchantments.FLIGHT_ENCHANTMENT.get())>0)mayFly=true; + if(legs.getEnchantmentLevel(ModEnchantments.FLIGHT_ENCHANTMENT.get())>0)mayFly=true; + + playerAbilities.mayfly=mayFly; + play.onUpdateAbilities(); + if(!OTEServerConfig.USE_CUSTOM_JOINLEAVE.get()) return; - ChatServerOverride.broadcast(Component.literal(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_GREEN + "+" + ChatColor.DARK_GRAY + "] "+ ChatColor.BOLD + ChatColor.DARK_AQUA + prof.nickname), ev.getEntity().getServer()); + ChatServerOverride.broadcast(Component.literal(ChatColor.doColors("!Dark_Gray![!Dark_Green!+!Dark_Gray!] !Bold!!Dark_Aqua!"+prof.nickname)), ev.getEntity().getServer()); + } - @OnlyIn(Dist.DEDICATED_SERVER) @SubscribeEvent public void onLeave(final PlayerEvent.PlayerLoggedOutEvent ev) { + if(ev.getEntity().level.isClientSide)return; // Get player profile, send disconnect alert, then commit profile and remove it from memory Profile px = Profile.get_profile_of(ev.getEntity().getStringUUID()); + ServerPlayer sp = (ServerPlayer)ev.getEntity(); + if(px==null)return; @@ -89,14 +112,15 @@ public class ChatServerOverride { // Send the alert ChatServerOverride.broadcast(Component.literal(ChatColor.DARK_GRAY + "[" + ChatColor.DARK_RED + "-" + ChatColor.DARK_GRAY + "] "+ChatColor.BOLD + ChatColor.DARK_AQUA + px.nickname), ev.getEntity().getServer()); + px.flying=sp.getAbilities().flying; px.commit(); OTEMod.PROFILES.remove(ev.getEntity().getStringUUID()); } - @OnlyIn(Dist.DEDICATED_SERVER) @SubscribeEvent public void onClone(final PlayerEvent.Clone ev) { + if(ev.getEntity().level.isClientSide)return; // Fix for fly ability not copying to new instance on death or other circumstances Player old = ev.getOriginal(); Player n = ev.getEntity(); @@ -105,9 +129,9 @@ public class ChatServerOverride { c.Assert((ServerPlayer)n); } - @OnlyIn(Dist.DEDICATED_SERVER) @SubscribeEvent public void onChat(final ServerChatEvent ev){ + if(ev.getPlayer().level.isClientSide)return; // Player has chatted, apply override if(!OTEServerConfig.USE_CUSTOM_CHATREPLACER.get()) return; diff --git a/src/main/java/dev/zontreck/otemod/commands/CommandRegistry.java b/src/main/java/dev/zontreck/otemod/commands/CommandRegistry.java index 7e935cc..36b3d2b 100644 --- a/src/main/java/dev/zontreck/otemod/commands/CommandRegistry.java +++ b/src/main/java/dev/zontreck/otemod/commands/CommandRegistry.java @@ -103,7 +103,7 @@ public class CommandRegistry { HomeCommand.register(ev.getDispatcher()); DelHomeCommand.register(ev.getDispatcher()); - FlyCommand.register(ev.getDispatcher()); + //FlyCommand.register(ev.getDispatcher()); ChatColorCommand.register(ev.getDispatcher()); NameColorCommand.register(ev.getDispatcher()); diff --git a/src/main/java/dev/zontreck/otemod/commands/vaults/VaultCommand.java b/src/main/java/dev/zontreck/otemod/commands/vaults/VaultCommand.java index 08e38a4..f771e2b 100644 --- a/src/main/java/dev/zontreck/otemod/commands/vaults/VaultCommand.java +++ b/src/main/java/dev/zontreck/otemod/commands/vaults/VaultCommand.java @@ -3,11 +3,16 @@ package dev.zontreck.otemod.commands.vaults; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.IntegerArgumentType; +import dev.zontreck.libzontreck.chat.ChatColor; +import dev.zontreck.otemod.OTEMod; +import dev.zontreck.otemod.chat.ChatServerOverride; import dev.zontreck.otemod.implementation.vault.VaultContainer; import net.minecraft.commands.CommandSourceStack; import net.minecraft.commands.Commands; import net.minecraft.network.chat.Component; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.SimpleMenuProvider; +import net.minecraft.world.entity.player.Player; import net.minecraftforge.network.NetworkHooks; public class VaultCommand { @@ -26,15 +31,25 @@ public class VaultCommand { private static int vault(CommandSourceStack source, int i) { //VaultContainer cont = new VaultContainer(i, source.getPlayer().getUUID()); //cont.startOpen(source.getPlayer()); + if(i <0) + { + ChatServerOverride.broadcastTo(source.getPlayer().getUUID(), Component.literal(ChatColor.doColors(OTEMod.OTEPrefix+" !Dark_Red!You can only specify a vault number in the positive range")), source.getServer()); + return 0; + } + doOpen(source.getPlayer(), i); - VaultContainer container = new VaultContainer(source.getPlayer(), i); - - NetworkHooks.openScreen(source.getPlayer(), new SimpleMenuProvider(container.serverMenu, Component.literal("Vault "+i))); - - // Add to the master vault registry - if(VaultContainer.VAULT_REGISTRY.containsKey(source.getPlayer().getUUID()))VaultContainer.VAULT_REGISTRY.remove(source.getPlayer().getUUID()); - VaultContainer.VAULT_REGISTRY.put(source.getPlayer().getUUID(), container); return 0; } + + public static void doOpen(ServerPlayer p, int i){ + + VaultContainer container = new VaultContainer(p, i); + + NetworkHooks.openScreen(p, new SimpleMenuProvider(container.serverMenu, Component.literal("Vault "+i))); + + // Add to the master vault registry + if(VaultContainer.VAULT_REGISTRY.containsKey(p.getUUID()))VaultContainer.VAULT_REGISTRY.remove(p.getUUID()); + VaultContainer.VAULT_REGISTRY.put(p.getUUID(), container); + } } diff --git a/src/main/java/dev/zontreck/otemod/configs/Profile.java b/src/main/java/dev/zontreck/otemod/configs/Profile.java index b54f8bb..75042be 100644 --- a/src/main/java/dev/zontreck/otemod/configs/Profile.java +++ b/src/main/java/dev/zontreck/otemod/configs/Profile.java @@ -16,8 +16,9 @@ public class Profile { public String name_color; // ChatColor.X public String prefix_color; public String chat_color; + public Boolean flying; - public Profile(String username, String prefix, String nickname, String name_color, String ID, String prefix_color, String chat_color) { + public Profile(String username, String prefix, String nickname, String name_color, String ID, String prefix_color, String chat_color, Boolean isFlying) { this.username = username; this.prefix = prefix; this.nickname = nickname; @@ -25,6 +26,7 @@ public class Profile { this.user_id = ID; this.prefix_color = prefix_color; this.chat_color = chat_color; + this.flying=isFlying; } @@ -41,7 +43,7 @@ public class Profile { public static Profile factory(ServerPlayer play) { - Profile p = new Profile(play.getName().getString(), "Member", play.getDisplayName().getString(), ChatColor.GREEN, play.getStringUUID(), ChatColor.AQUA, ChatColor.WHITE); + Profile p = new Profile(play.getName().getString(), "Member", play.getDisplayName().getString(), ChatColor.GREEN, play.getStringUUID(), ChatColor.AQUA, ChatColor.WHITE, false); return p; } @@ -49,7 +51,7 @@ public class Profile { { // Send player to server! Connection con = OTEMod.DB.getConnection(); - String SQL = "REPLACE INTO `profiles` (username, uuid, prefix, nickname, name_color, prefix_color, chat_color) values (?, ?, ?, ?, ?, ?, ?);"; + String SQL = "REPLACE INTO `profiles` (username, uuid, prefix, nickname, name_color, prefix_color, chat_color, flying) values (?, ?, ?, ?, ?, ?, ?, ?);"; try { PreparedStatement pstat = con.prepareStatement(SQL); pstat.setString(1, username); @@ -59,6 +61,7 @@ public class Profile { pstat.setString(5, name_color); pstat.setString(6, prefix_color); pstat.setString(7, chat_color); + pstat.setBoolean(8, flying); pstat.execute(); } catch (SQLException e) { diff --git a/src/main/java/dev/zontreck/otemod/enchantments/FlightEnchantment.java b/src/main/java/dev/zontreck/otemod/enchantments/FlightEnchantment.java new file mode 100644 index 0000000..7896146 --- /dev/null +++ b/src/main/java/dev/zontreck/otemod/enchantments/FlightEnchantment.java @@ -0,0 +1,99 @@ +package dev.zontreck.otemod.enchantments; + +import dev.zontreck.otemod.OTEMod; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.player.Abilities; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraft.world.item.enchantment.EnchantmentCategory; +import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +public class FlightEnchantment extends Enchantment +{ + @Mod.EventBusSubscriber(modid = OTEMod.MOD_ID, bus=Mod.EventBusSubscriber.Bus.FORGE) + public static class EventHandler{ + @SubscribeEvent + public static void onLivingUpdate(LivingEquipmentChangeEvent ev) + { + if(ev.getEntity() instanceof Player) + { + if(ev.getEntity().level.isClientSide)return; + + ServerPlayer sp = (ServerPlayer)ev.getEntity(); + ItemStack feet = sp.getItemBySlot(EquipmentSlot.FEET); + ItemStack legs = sp.getItemBySlot(EquipmentSlot.LEGS); + + boolean hasFlight = false; + + if(feet.getEnchantmentLevel(ModEnchantments.FLIGHT_ENCHANTMENT.get())>0)hasFlight=true; + if(legs.getEnchantmentLevel(ModEnchantments.FLIGHT_ENCHANTMENT.get())>0)hasFlight=true; + + Abilities playerAbilities = sp.getAbilities(); + if(playerAbilities.mayfly == false) + { + if(hasFlight){ + playerAbilities.mayfly=true; + sp.onUpdateAbilities(); + } + }else { + if(!hasFlight){ + + playerAbilities.mayfly=false; + playerAbilities.flying=false; + + sp.onUpdateAbilities(); + } + } + } + } + } + + public FlightEnchantment() + { + super(Rarity.RARE, EnchantmentCategory.ARMOR, new EquipmentSlot[] {EquipmentSlot.FEET, EquipmentSlot.LEGS}); + + } + + @Override + public int getMaxLevel() + { + return 1; + } + + @Override + public int getMinCost(int level) + { + return 28 + (level - 1) * 15; + } + + @Override + public int getMaxCost(int level) + { + return this.getMinCost(level) + 15; + } + @Override + public boolean canApplyAtEnchantingTable(ItemStack stack) + { + return false; + } + @Override + public boolean isTreasureOnly(){ + return true; + } + @Override + public boolean isTradeable() + { + return true; + } + + // Not a bug. Flight is meant to be a permanent upgrade to a item. It is considered a curse due to unstable behavior that can randomly happen if the enchantment level is now maxxed out. + @Override + public boolean isCurse() + { + return true; + } +} diff --git a/src/main/java/dev/zontreck/otemod/enchantments/MobEggEnchantment.java b/src/main/java/dev/zontreck/otemod/enchantments/MobEggEnchantment.java index b27e939..c1679e0 100644 --- a/src/main/java/dev/zontreck/otemod/enchantments/MobEggEnchantment.java +++ b/src/main/java/dev/zontreck/otemod/enchantments/MobEggEnchantment.java @@ -17,7 +17,7 @@ public class MobEggEnchantment extends Enchantment @Override public int getMaxLevel() { - return 4; + return 6; } @Override @@ -38,5 +38,21 @@ public class MobEggEnchantment extends Enchantment { return super.canApplyAtEnchantingTable(stack); } + + @Override + public boolean isTreasureOnly(){ + return false; + } + @Override + public boolean isTradeable() + { + return true; + } + + @Override + public boolean isDiscoverable() + { + return false; + } } diff --git a/src/main/java/dev/zontreck/otemod/enchantments/ModEnchantments.java b/src/main/java/dev/zontreck/otemod/enchantments/ModEnchantments.java index bed1f19..5d92731 100644 --- a/src/main/java/dev/zontreck/otemod/enchantments/ModEnchantments.java +++ b/src/main/java/dev/zontreck/otemod/enchantments/ModEnchantments.java @@ -12,6 +12,8 @@ public class ModEnchantments { public static final RegistryObject MOB_EGGING_ENCHANTMENT = REGISTERS.register("mob_egging", ()->new MobEggEnchantment()); + public static final RegistryObject FLIGHT_ENCHANTMENT = REGISTERS.register("player_flight", ()->new FlightEnchantment()); + public static void register(IEventBus bus){ REGISTERS.register(bus); } diff --git a/src/main/java/dev/zontreck/otemod/events/ClientEvents.java b/src/main/java/dev/zontreck/otemod/events/ClientEvents.java new file mode 100644 index 0000000..d5042a9 --- /dev/null +++ b/src/main/java/dev/zontreck/otemod/events/ClientEvents.java @@ -0,0 +1,39 @@ +package dev.zontreck.otemod.events; + +import dev.zontreck.otemod.OTEMod; +import dev.zontreck.otemod.integrations.KeyBindings; +import dev.zontreck.otemod.networking.ModMessages; +import dev.zontreck.otemod.networking.packets.OpenVaultPacket; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.client.event.InputEvent; +import net.minecraftforge.client.event.RegisterKeyMappingsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod; + +public class ClientEvents { + @Mod.EventBusSubscriber(modid = OTEMod.MOD_ID, value = Dist.CLIENT) + public static class ForgeEvents + { + + @SubscribeEvent + public static void onKeyInput(InputEvent.Key event) + { + //OTEMod.LOGGER.info("KEY PRESS: "+event.getKey()); + if(KeyBindings.OPEN_VAULT.consumeClick()) + { + ModMessages.sendToServer(new OpenVaultPacket(0, false, 0)); + } + } + } + + @Mod.EventBusSubscriber(modid = OTEMod.MOD_ID, value=Dist.CLIENT, bus=Mod.EventBusSubscriber.Bus.MOD) + public static class ClientModBus + { + + @SubscribeEvent + public static void onKeyRegister(RegisterKeyMappingsEvent event) + { + event.register(KeyBindings.OPEN_VAULT); + } + } +} diff --git a/src/main/java/dev/zontreck/otemod/implementation/vault/VaultContainer.java b/src/main/java/dev/zontreck/otemod/implementation/vault/VaultContainer.java index 7187e5a..4d29be3 100644 --- a/src/main/java/dev/zontreck/otemod/implementation/vault/VaultContainer.java +++ b/src/main/java/dev/zontreck/otemod/implementation/vault/VaultContainer.java @@ -31,15 +31,15 @@ public class VaultContainer public MenuConstructor serverMenu; public UUID owner; private MinecraftServer server; - private final int VAULT_NUMBER; + public final int VAULT_NUMBER; public final UUID VaultID; public VaultContainer(ServerPlayer player, int vaultNum) { myInventory = new ItemStackHandler(54); // Vaults have a fixed size at the same as a double chest - theContainer = new VaultMenu(player.containerCounter+1, player.getInventory(), myInventory, BlockPos.ZERO); + theContainer = new VaultMenu(player.containerCounter+1, player.getInventory(), myInventory, BlockPos.ZERO, player, vaultNum); VaultID = theContainer.VaultMenuID; owner = player.getUUID(); server=player.server; - serverMenu = theContainer.getServerMenu(myInventory); + serverMenu = theContainer.getServerMenu(myInventory, vaultNum); VAULT_NUMBER=vaultNum; if(VAULT_NUMBER == -1)return; // Trash ID diff --git a/src/main/java/dev/zontreck/otemod/implementation/vault/VaultMenu.java b/src/main/java/dev/zontreck/otemod/implementation/vault/VaultMenu.java index 1aae203..5e174cb 100644 --- a/src/main/java/dev/zontreck/otemod/implementation/vault/VaultMenu.java +++ b/src/main/java/dev/zontreck/otemod/implementation/vault/VaultMenu.java @@ -8,6 +8,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.ClickType; import net.minecraft.world.inventory.MenuConstructor; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; @@ -19,16 +20,20 @@ public class VaultMenu extends AbstractContainerMenu { //private final ContainerLevelAccess containerAccess; public final UUID VaultMenuID; + public final Player thePlayer; + public final int VAULT_NUMBER; public VaultMenu (int id, Inventory player) { - this(id, player, new ItemStackHandler(54), BlockPos.ZERO); + this(id, player, new ItemStackHandler(54), BlockPos.ZERO, player.player, 0); } - public VaultMenu (int id, Inventory player, IItemHandler slots, BlockPos pos) + public VaultMenu (int id, Inventory player, IItemHandler slots, BlockPos pos, Player play, int vaultNum) { super(ModMenuTypes.VAULT.get(), id); + thePlayer=play; VaultMenuID=UUID.randomUUID(); + VAULT_NUMBER=vaultNum; //this.containerAccess = ContainerLevelAccess.create(player.player.level, pos); final int slotSize = 18; @@ -104,8 +109,8 @@ public class VaultMenu extends AbstractContainerMenu return true; // We have no block } - public static MenuConstructor getServerMenu (ItemStackHandler inventory){ - return (id, player, play) -> new VaultMenu(id, player, inventory, BlockPos.ZERO); + public static MenuConstructor getServerMenu (ItemStackHandler inventory, int vaultNum){ + return (id, player, play) -> new VaultMenu(id, player, inventory, BlockPos.ZERO, player.player, vaultNum); } diff --git a/src/main/java/dev/zontreck/otemod/implementation/vault/VaultScreen.java b/src/main/java/dev/zontreck/otemod/implementation/vault/VaultScreen.java index 4bdfdfe..b552a93 100644 --- a/src/main/java/dev/zontreck/otemod/implementation/vault/VaultScreen.java +++ b/src/main/java/dev/zontreck/otemod/implementation/vault/VaultScreen.java @@ -6,25 +6,39 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import dev.zontreck.otemod.OTEMod; +import dev.zontreck.otemod.commands.vaults.VaultCommand; +import dev.zontreck.otemod.networking.ModMessages; +import dev.zontreck.otemod.networking.packets.OpenVaultPacket; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.components.Button.OnPress; +import net.minecraft.client.gui.font.TextFieldHelper; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.renderer.GameRenderer; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.network.NetworkHooks; public class VaultScreen extends AbstractContainerScreen { // 176x224 public final UUID VaultMenuID; + public final Player thePlayer; + public final VaultMenu THE_CONTAINER; private static final ResourceLocation TEXTURE = new ResourceLocation(OTEMod.MOD_ID, "textures/gui/vault.png"); public VaultScreen(VaultMenu container, Inventory playerInv, Component comp){ super(container, playerInv, comp); + thePlayer=playerInv.player; this.VaultMenuID = container.VaultMenuID; this.leftPos = 0; this.topPos = 0; + this.THE_CONTAINER=container; this.imageWidth = 207; this.imageHeight = 238; @@ -54,6 +68,17 @@ public class VaultScreen extends AbstractContainerScreen { super.init(); // This is where custom controls would be added! + + this.addWidget(new Button(this.leftPos+7,this.topPos+84,16,16,Component.literal(""), (button)->{ + thePlayer.closeContainer(); + + ModMessages.sendToServer(new OpenVaultPacket(0,true,-1)); + } )); + + this.addWidget(new Button(this.leftPos+187,this.topPos+84,16,16,Component.literal(""), (button)->{ + thePlayer.closeContainer(); + ModMessages.sendToServer(new OpenVaultPacket(0, true, 1)); + } )); } @Override diff --git a/src/main/java/dev/zontreck/otemod/integrations/KeyBindings.java b/src/main/java/dev/zontreck/otemod/integrations/KeyBindings.java new file mode 100644 index 0000000..28f30e7 --- /dev/null +++ b/src/main/java/dev/zontreck/otemod/integrations/KeyBindings.java @@ -0,0 +1,15 @@ +package dev.zontreck.otemod.integrations; + +import org.lwjgl.glfw.GLFW; + +import com.mojang.blaze3d.platform.InputConstants; + +import net.minecraft.client.KeyMapping; +import net.minecraftforge.client.settings.KeyConflictContext; + +public class KeyBindings { + public static final String KEY_CATEGORY_OTEMOD = "key.category.otemod"; + public static final String KEY_OPEN_VAULT = "key.otemod.open_vault"; + + public static final KeyMapping OPEN_VAULT = new KeyMapping(KEY_OPEN_VAULT, KeyConflictContext.IN_GAME, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_V, KEY_CATEGORY_OTEMOD); +} diff --git a/src/main/java/dev/zontreck/otemod/networking/ModMessages.java b/src/main/java/dev/zontreck/otemod/networking/ModMessages.java new file mode 100644 index 0000000..2068ac7 --- /dev/null +++ b/src/main/java/dev/zontreck/otemod/networking/ModMessages.java @@ -0,0 +1,46 @@ +package dev.zontreck.otemod.networking; + +import dev.zontreck.otemod.OTEMod; +import dev.zontreck.otemod.networking.packets.OpenVaultPacket; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraftforge.network.NetworkDirection; +import net.minecraftforge.network.NetworkRegistry; +import net.minecraftforge.network.PacketDistributor; +import net.minecraftforge.network.simple.SimpleChannel; + +public class ModMessages { + private static SimpleChannel INSTANCE; + + private static int PACKET_ID = 0; + private static int id() + { + return PACKET_ID++; + } + + public static void register() + { + SimpleChannel net = NetworkRegistry.ChannelBuilder.named(new ResourceLocation(OTEMod.MOD_ID, "messages")) + .networkProtocolVersion(()-> "1.0") + .clientAcceptedVersions(s->true) + .serverAcceptedVersions(s->true) + .simpleChannel(); + + INSTANCE=net; + + net.messageBuilder(OpenVaultPacket.class, id(), NetworkDirection.PLAY_TO_SERVER) + .decoder(OpenVaultPacket::new) + .encoder(OpenVaultPacket::toBytes) + .consumerMainThread(OpenVaultPacket::handle) + .add(); + } + + public static void sendToServer(MSG message){ + INSTANCE.sendToServer(message); + } + + public static void sendToPlayer(MSG message, ServerPlayer player) + { + INSTANCE.send(PacketDistributor.PLAYER.with(()->player), message); + } +} diff --git a/src/main/java/dev/zontreck/otemod/networking/packets/OpenVaultPacket.java b/src/main/java/dev/zontreck/otemod/networking/packets/OpenVaultPacket.java new file mode 100644 index 0000000..ab17aaa --- /dev/null +++ b/src/main/java/dev/zontreck/otemod/networking/packets/OpenVaultPacket.java @@ -0,0 +1,62 @@ +package dev.zontreck.otemod.networking.packets; + +import java.util.function.Supplier; + +import dev.zontreck.otemod.commands.vaults.VaultCommand; +import dev.zontreck.otemod.implementation.vault.VaultContainer; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.level.ServerPlayer; +import net.minecraftforge.event.level.NoteBlockEvent.Change; +import net.minecraftforge.network.NetworkEvent; + +// This packet is only ever sent from the client to the server when requesting to open vaults using the EaseOfUse Buttons +public class OpenVaultPacket { + private int vault=0; + private boolean change = false; // This is set to true when going previous or next. + private int changeDir = 0; // This is only in the packet when change is true. This is either a 1 or a -1. + public OpenVaultPacket(int vaultNum, boolean change, int changeDir) + { + this.vault = vaultNum; + this.change = change; + this.changeDir=changeDir; + } + + public OpenVaultPacket(FriendlyByteBuf buf) + { + this.change = buf.readBoolean(); + if(this.change) + this.changeDir=buf.readInt(); + else + this.vault = buf.readInt(); + } + public void toBytes(FriendlyByteBuf buf) + { + buf.writeBoolean(change); + if(change) buf.writeInt(changeDir); + else buf.writeInt(vault); + } + + public boolean handle(Supplier supplier) + { + NetworkEvent.Context ctx = supplier.get(); + ctx.enqueueWork(()->{ + // On server now + ServerPlayer player = ctx.getSender(); + + if(change){ + if(VaultContainer.VAULT_REGISTRY.containsKey(player.getUUID())){ + VaultContainer cont = VaultContainer.VAULT_REGISTRY.get(player.getUUID()); + vault = cont.VAULT_NUMBER + changeDir; + } + } + + if(vault < 0)vault=0; + + + VaultCommand.doOpen(player, vault); + }); + + return true; + } + +} diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 3edaff2..52d0dfd 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -19,7 +19,7 @@ modId="otemod" #mandatory # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # see the associated build.gradle script for how to populate this completely automatically during a build -version="1.3.6.4" #mandatory +version="1.3.6.7" #mandatory # A display name for the mod displayName="OTEMod" #mandatory # A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/ diff --git a/src/main/resources/assets/otemod/lang/en_us.json b/src/main/resources/assets/otemod/lang/en_us.json index f8c63b6..a908980 100644 --- a/src/main/resources/assets/otemod/lang/en_us.json +++ b/src/main/resources/assets/otemod/lang/en_us.json @@ -1,4 +1,8 @@ { + "key.otemod.open_vault": "Opens Vault 0", + "key.category.otemod": "Only The Essentials", + + "itemGroup.refinedfabric.materials": "RefinedFabric Materials", "itemGroup.refinedfabric.tools": "RefinedFabric Utilities", "itemGroup.refinedfabric.blocks": "RefinedFabric Blocks", @@ -33,6 +37,9 @@ "block.otemod.item_scrubber": "Item Scrubber", "enchantment.otemod.mob_egging": "Mob Egging", + "enchantment.otemod.player_flight": "Flight", + "enchantment.otemod.mob_egging.desc": "Chance of mob spawn eggs to drop", + "enchantment.otemod.player_flight.desc": "Allows you to fly!", "dev.zontreck.otemod.msgs.only_player": "§cOnly players are allowed to execute this command", diff --git a/src/main/resources/assets/otemod/textures/gui/vault.png b/src/main/resources/assets/otemod/textures/gui/vault.png index d43873a..7c3c070 100644 Binary files a/src/main/resources/assets/otemod/textures/gui/vault.png and b/src/main/resources/assets/otemod/textures/gui/vault.png differ diff --git a/src/main/resources/assets/otemod/textures/gui/vaultmenu.aseprite b/src/main/resources/assets/otemod/textures/gui/vaultmenu.aseprite index 6fae224..e229887 100644 Binary files a/src/main/resources/assets/otemod/textures/gui/vaultmenu.aseprite and b/src/main/resources/assets/otemod/textures/gui/vaultmenu.aseprite differ