Reworking how keybindings work with items, more refactoring to be done here

This commit is contained in:
pahimar 2012-11-26 15:59:26 -05:00
parent aa0b4219f6
commit 4de5c80593
3 changed files with 19 additions and 3 deletions

View file

@ -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();

View file

@ -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");
}
}
}

View file

@ -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());
}
}
}