diff --git a/src/main/java/baubles/client/ClientEventHandler.java b/src/main/java/baubles/client/ClientEventHandler.java new file mode 100644 index 00000000..92dc5156 --- /dev/null +++ b/src/main/java/baubles/client/ClientEventHandler.java @@ -0,0 +1,42 @@ +package baubles.client; + +import net.minecraft.client.renderer.block.model.ModelResourceLocation; +import net.minecraft.util.text.TextFormatting; +import net.minecraftforge.client.event.ModelRegistryEvent; +import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.fml.client.FMLClientHandler; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; +import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; +import net.minecraftforge.fml.relauncher.Side; +import baubles.api.BaubleType; +import baubles.api.IBauble; +import baubles.common.items.ItemRing; +import baubles.common.network.PacketHandler; +import baubles.common.network.PacketOpenBaublesInventory; + +public class ClientEventHandler +{ + @SubscribeEvent + public void registerItemModels(ModelRegistryEvent event) { + ModelLoader.setCustomModelResourceLocation(ItemRing.RING, 0, new ModelResourceLocation("baubles:ring", "inventory")); + } + + @SubscribeEvent + public void playerTick(PlayerTickEvent event) { + if (event.side == Side.CLIENT && event.phase == Phase.START ) { + if (ClientProxy.KEY_BAUBLES.isPressed() && FMLClientHandler.instance().getClient().inGameHasFocus) { + PacketHandler.INSTANCE.sendToServer(new PacketOpenBaublesInventory(event.player)); + } + } + } + + @SubscribeEvent + public void tooltipEvent(ItemTooltipEvent event) { + if (!event.getItemStack().isEmpty() && event.getItemStack().getItem() instanceof IBauble) { + BaubleType bt = ((IBauble)event.getItemStack().getItem()).getBaubleType(event.getItemStack()); + event.getToolTip().add(TextFormatting.GOLD + net.minecraft.client.resources.I18n.format("name." + bt)); + } + } +} diff --git a/src/main/java/baubles/client/ClientProxy.java b/src/main/java/baubles/client/ClientProxy.java index 9b240726..e324dddc 100644 --- a/src/main/java/baubles/client/ClientProxy.java +++ b/src/main/java/baubles/client/ClientProxy.java @@ -2,34 +2,33 @@ package baubles.client; import java.util.Map; +import org.lwjgl.input.Keyboard; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.WorldClient; -import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.client.renderer.entity.RenderPlayer; +import net.minecraft.client.settings.KeyBinding; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; -import net.minecraftforge.client.event.ModelRegistryEvent; -import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.client.FMLClientHandler; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.client.registry.ClientRegistry; import baubles.client.gui.GuiEvents; import baubles.client.gui.GuiPlayerExpanded; import baubles.common.Baubles; import baubles.common.CommonProxy; -import baubles.common.event.KeyHandler; -import baubles.common.items.ItemRing; -@Mod.EventBusSubscriber(Side.CLIENT) public class ClientProxy extends CommonProxy { + public static final KeyBinding KEY_BAUBLES = new KeyBinding("keybind.baublesinventory", Keyboard.KEY_B, "key.categories.inventory"); + @Override - public void registerKeyBindings() { - keyHandler = new KeyHandler(); + public void registerEventHandlers() { + super.registerEventHandlers(); + + ClientRegistry.registerKeyBinding(KEY_BAUBLES); + + MinecraftForge.EVENT_BUS.register(new ClientEventHandler()); MinecraftForge.EVENT_BUS.register(new GuiEvents()); - MinecraftForge.EVENT_BUS.register(keyHandler); } @Override @@ -47,11 +46,6 @@ public World getClientWorld() { return FMLClientHandler.instance().getClient().world; } - @SubscribeEvent - public static void registerItemModels(ModelRegistryEvent event) { - ModelLoader.setCustomModelResourceLocation(ItemRing.RING, 0, new ModelResourceLocation("baubles:ring", "inventory")); - } - @Override public void init() { Map skinMap = Minecraft.getMinecraft().getRenderManager().getSkinMap(); diff --git a/src/main/java/baubles/client/gui/GuiPlayerExpanded.java b/src/main/java/baubles/client/gui/GuiPlayerExpanded.java index c8fe2d74..ef95e1ff 100644 --- a/src/main/java/baubles/client/gui/GuiPlayerExpanded.java +++ b/src/main/java/baubles/client/gui/GuiPlayerExpanded.java @@ -14,7 +14,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Slot; import net.minecraft.util.ResourceLocation; -import baubles.common.Baubles; +import baubles.client.ClientProxy; import baubles.common.container.ContainerPlayerExpanded; public class GuiPlayerExpanded extends InventoryEffectRenderer { @@ -156,7 +156,7 @@ protected void actionPerformed(GuiButton button) @Override protected void keyTyped(char par1, int par2) throws IOException { - if (par2 == Baubles.proxy.keyHandler.key.getKeyCode()) + if (par2 == ClientProxy.KEY_BAUBLES.getKeyCode()) { this.mc.player.closeScreen(); } else diff --git a/src/main/java/baubles/common/Baubles.java b/src/main/java/baubles/common/Baubles.java index 978a4b8b..64e351ae 100644 --- a/src/main/java/baubles/common/Baubles.java +++ b/src/main/java/baubles/common/Baubles.java @@ -3,14 +3,12 @@ import java.io.File; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.capabilities.CapabilityManager; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.Instance; import net.minecraftforge.fml.common.SidedProxy; import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLServerStartingEvent; import net.minecraftforge.fml.common.network.NetworkRegistry; @@ -18,7 +16,6 @@ import baubles.api.cap.BaublesContainer; import baubles.api.cap.IBaublesItemHandler; import baubles.common.event.CommandBaubles; -import baubles.common.event.EventHandlerEntity; import baubles.common.network.PacketHandler; @Mod( @@ -39,7 +36,6 @@ public class Baubles { @Instance(value=Baubles.MODID) public static Baubles instance; - public EventHandlerEntity entityEventHandler; public File modDir; public static final Logger log = LogManager.getLogger(MODID.toUpperCase()); @@ -60,11 +56,8 @@ public void preInit(FMLPreInitializationEvent event) { CapabilityManager.INSTANCE.register(IBaublesItemHandler.class, new CapabilityBaubles(), BaublesContainer.class); + proxy.registerEventHandlers(); PacketHandler.init(); - - entityEventHandler = new EventHandlerEntity(); - - MinecraftForge.EVENT_BUS.register(entityEventHandler); ///////////////////// Config.save(); @@ -73,14 +66,9 @@ public void preInit(FMLPreInitializationEvent event) { @EventHandler public void init(FMLInitializationEvent evt) { NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy); - proxy.registerKeyBindings(); proxy.init(); } - @EventHandler - public void postInit(FMLPostInitializationEvent evt) { - } - @EventHandler public void serverLoad(FMLServerStartingEvent event) { diff --git a/src/main/java/baubles/common/CommonProxy.java b/src/main/java/baubles/common/CommonProxy.java index 14e4fc6e..64d74d5c 100644 --- a/src/main/java/baubles/common/CommonProxy.java +++ b/src/main/java/baubles/common/CommonProxy.java @@ -3,14 +3,13 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.network.IGuiHandler; import baubles.common.container.ContainerPlayerExpanded; -import baubles.common.event.KeyHandler; +import baubles.common.event.EventHandlerEntity; public class CommonProxy implements IGuiHandler { - public KeyHandler keyHandler; - @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { return null; @@ -28,7 +27,9 @@ public World getClientWorld() { return null; } - public void registerKeyBindings() { } + public void registerEventHandlers() { + MinecraftForge.EVENT_BUS.register(new EventHandlerEntity()); + } public void init() { } } diff --git a/src/main/java/baubles/common/event/EventHandlerEntity.java b/src/main/java/baubles/common/event/EventHandlerEntity.java index c7ed0beb..3fc84a86 100644 --- a/src/main/java/baubles/common/event/EventHandlerEntity.java +++ b/src/main/java/baubles/common/event/EventHandlerEntity.java @@ -4,7 +4,6 @@ import java.util.HashMap; import java.util.List; import java.util.UUID; -import net.minecraft.client.resources.I18n; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; @@ -12,15 +11,12 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.MathHelper; -import net.minecraft.util.text.TextFormatting; import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent; -import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.event.entity.player.PlayerDropsEvent; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent; -import baubles.api.BaubleType; import baubles.api.BaublesApi; import baubles.api.IBauble; import baubles.api.cap.BaublesContainer; @@ -151,12 +147,4 @@ public void dropItemsAt(EntityPlayer player, List drops, Entity e) { } } } - - @SubscribeEvent - public void tooltipEvent(ItemTooltipEvent event) { - if (event.getItemStack()!=null && !event.getItemStack().isEmpty() && event.getItemStack().getItem() instanceof IBauble) { - BaubleType bt = ((IBauble)event.getItemStack().getItem()).getBaubleType(event.getItemStack()); - event.getToolTip().add(TextFormatting.GOLD + I18n.format("name." + bt)); - } - } } diff --git a/src/main/java/baubles/common/event/KeyHandler.java b/src/main/java/baubles/common/event/KeyHandler.java deleted file mode 100644 index c8c28388..00000000 --- a/src/main/java/baubles/common/event/KeyHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -package baubles.common.event; - -import org.lwjgl.input.Keyboard; -import net.minecraft.client.settings.KeyBinding; -import net.minecraftforge.fml.client.FMLClientHandler; -import net.minecraftforge.fml.client.registry.ClientRegistry; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; -import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; -import net.minecraftforge.fml.relauncher.Side; -import baubles.common.network.PacketHandler; -import baubles.common.network.PacketOpenBaublesInventory; - -public class KeyHandler { - - public KeyBinding key = new KeyBinding("keybind.baublesinventory", Keyboard.KEY_B, "key.categories.inventory"); - - public KeyHandler() { - ClientRegistry.registerKeyBinding(key); - } - - @SubscribeEvent - public void playerTick(PlayerTickEvent event) { - if (event.side == Side.SERVER) return; - if (event.phase == Phase.START ) { - if (key.isPressed() && FMLClientHandler.instance().getClient().inGameHasFocus) { - PacketHandler.INSTANCE.sendToServer(new PacketOpenBaublesInventory(event.player)); - } - } - } -} -