From 4de5c805939f046bb205d9da6405028cbc150350 Mon Sep 17 00:00:00 2001 From: pahimar Date: Mon, 26 Nov 2012 15:59:26 -0500 Subject: [PATCH] Reworking how keybindings work with items, more refactoring to be done here --- .../ee3/client/core/handlers/KeyBindingHandler.java | 2 +- ee3_common/ee3/common/item/ItemMiniumStone.java | 13 ++++++++++++- ee3_common/ee3/common/network/PacketKeyPressed.java | 7 ++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ee3_client/ee3/client/core/handlers/KeyBindingHandler.java b/ee3_client/ee3/client/core/handlers/KeyBindingHandler.java index 20670560..c3029340 100644 --- a/ee3_client/ee3/client/core/handlers/KeyBindingHandler.java +++ b/ee3_client/ee3/client/core/handlers/KeyBindingHandler.java @@ -48,7 +48,7 @@ public class KeyBindingHandler extends KeyBindingRegistry.KeyHandler { // Only operate at the end of the tick if (tickEnd) { // If we are not in a GUI of any kind, continue execution - if (FMLClientHandler.instance().getClient().currentScreen == null) { + if (FMLClientHandler.instance().getClient().inGameHasFocus) { // TODO Clean this up properly if (kb.keyDescription == Reference.KEYBINDING_EXTRA) { ItemStack currentItem = FMLClientHandler.instance().getClient().thePlayer.getCurrentEquippedItem(); diff --git a/ee3_common/ee3/common/item/ItemMiniumStone.java b/ee3_common/ee3/common/item/ItemMiniumStone.java index 2b26ff76..533f949d 100644 --- a/ee3_common/ee3/common/item/ItemMiniumStone.java +++ b/ee3_common/ee3/common/item/ItemMiniumStone.java @@ -14,6 +14,7 @@ import ee3.common.lib.Colours; import ee3.common.lib.ConfigurationSettings; import ee3.common.lib.CustomItemRarity; import ee3.common.lib.GuiIds; +import ee3.common.lib.Reference; import ee3.common.lib.Strings; import ee3.common.network.PacketKeyPressed; import ee3.common.network.PacketTypeHandler; @@ -27,7 +28,8 @@ import ee3.common.network.PacketTypeHandler; * @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html) * */ -public class ItemMiniumStone extends ItemEE implements ITransmutationStone { +public class ItemMiniumStone extends ItemEE + implements ITransmutationStone, IKeyBound { public ItemMiniumStone(int id) { super(id); @@ -84,5 +86,14 @@ public class ItemMiniumStone extends ItemEE implements ITransmutationStone { */ PacketDispatcher.sendPacketToServer(PacketTypeHandler.populatePacket(new PacketKeyPressed(keyPressed))); } + + @Override + public void doKeyBindingAction(String keyBinding, boolean isSneaking) { + + if (keyBinding.equals(Reference.KEYBINDING_EXTRA)) { + System.out.println("Extra key"); + } + + } } diff --git a/ee3_common/ee3/common/network/PacketKeyPressed.java b/ee3_common/ee3/common/network/PacketKeyPressed.java index 23607a27..e500f1a3 100644 --- a/ee3_common/ee3/common/network/PacketKeyPressed.java +++ b/ee3_common/ee3/common/network/PacketKeyPressed.java @@ -7,6 +7,7 @@ import java.io.IOException; import cpw.mods.fml.common.network.Player; import cpw.mods.fml.common.registry.LanguageRegistry; import ee3.common.EquivalentExchange3; +import ee3.common.item.IKeyBound; import ee3.common.item.ITransmutationStone; import ee3.common.lib.GuiIds; import ee3.common.lib.ItemIds; @@ -52,9 +53,13 @@ public class PacketKeyPressed extends PacketEE { public void execute(INetworkManager manager, Player player) { EntityPlayer thePlayer = (EntityPlayer) player; - + /* if ((this.key.equals(Reference.KEYBINDING_EXTRA)) && (thePlayer.getCurrentEquippedItem().getItem() instanceof ITransmutationStone)) { thePlayer.openGui(EquivalentExchange3.instance, GuiIds.PORTABLE_CRAFTING, thePlayer.worldObj, (int)thePlayer.posX, (int)thePlayer.posY, (int)thePlayer.posZ); } + */ + if ((thePlayer.getCurrentEquippedItem() != null) && (thePlayer.getCurrentEquippedItem().getItem() instanceof IKeyBound)) { + ((IKeyBound) thePlayer.getCurrentEquippedItem().getItem()).doKeyBindingAction(this.key, thePlayer.isSneaking()); + } } }