2013-07-26 21:18:53 -07:00
|
|
|
package tconstruct.client;
|
|
|
|
|
|
2014-06-01 21:20:12 -04:00
|
|
|
import mantle.common.network.AbstractPacket;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.client.Minecraft;
|
2014-02-05 10:28:54 -05:00
|
|
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
|
|
|
|
import net.minecraft.client.gui.inventory.GuiInventory;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.client.settings.KeyBinding;
|
2014-06-30 22:26:00 -08:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-02-08 13:30:19 -05:00
|
|
|
import net.minecraft.potion.Potion;
|
2014-08-07 19:14:17 -04:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2014-02-01 17:28:41 +11:00
|
|
|
import tconstruct.TConstruct;
|
2014-07-21 12:52:39 -08:00
|
|
|
import tconstruct.armor.ArmorProxyClient;
|
2014-06-06 19:46:05 -08:00
|
|
|
import tconstruct.armor.ArmorProxyCommon;
|
2014-07-21 12:52:39 -08:00
|
|
|
import tconstruct.armor.PlayerAbilityHelper;
|
|
|
|
|
import tconstruct.armor.items.TravelGear;
|
2013-08-15 01:31:12 -04:00
|
|
|
import tconstruct.client.tabs.TabRegistry;
|
2014-07-21 12:52:39 -08:00
|
|
|
import tconstruct.util.network.AccessoryInventoryPacket;
|
|
|
|
|
import tconstruct.util.network.BeltPacket;
|
|
|
|
|
import tconstruct.util.network.DoubleJumpPacket;
|
|
|
|
|
import tconstruct.util.network.GogglePacket;
|
2014-06-30 22:26:00 -08:00
|
|
|
import cpw.mods.fml.common.gameevent.TickEvent.Type;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-09-05 21:31:20 +02:00
|
|
|
public class ArmorControls extends TKeyHandler
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-07-02 23:37:28 -08:00
|
|
|
public static final String keybindCategory = "tconstruct.keybindings";
|
2014-02-26 12:23:11 +11:00
|
|
|
public static KeyBinding armorKey = new KeyBinding("key.tarmor", 24, keybindCategory);
|
2014-06-30 22:26:00 -08:00
|
|
|
public static KeyBinding toggleGoggles = new KeyBinding("key.tgoggles", 34, keybindCategory);
|
|
|
|
|
public static KeyBinding beltSwap = new KeyBinding("key.tbelt", 48, keybindCategory);
|
2014-07-06 22:59:44 -08:00
|
|
|
public static KeyBinding zoomKey = new KeyBinding("key.tzoom", 44, keybindCategory); //TODO: Make this hold, not toggle
|
2013-07-26 21:18:53 -07:00
|
|
|
static KeyBinding jumpKey;
|
|
|
|
|
static KeyBinding invKey;
|
|
|
|
|
static Minecraft mc;
|
|
|
|
|
|
|
|
|
|
boolean jumping;
|
2014-02-08 13:30:19 -05:00
|
|
|
int midairJumps = 0;
|
2013-07-26 21:18:53 -07:00
|
|
|
boolean climbing = false;
|
|
|
|
|
boolean onGround = false;
|
2014-06-30 22:26:00 -08:00
|
|
|
public static boolean zoom = false;
|
2014-07-21 12:52:39 -08:00
|
|
|
boolean activeGoggles = false; //TODO: Set this on server login
|
2013-07-26 21:18:53 -07:00
|
|
|
|
|
|
|
|
int currentTab = 1;
|
|
|
|
|
|
2014-02-16 14:23:50 -05:00
|
|
|
// boolean onStilts = false;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-09-05 21:31:20 +02:00
|
|
|
public ArmorControls()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-08-01 22:48:20 -04:00
|
|
|
super(new KeyBinding[] { armorKey, toggleGoggles, beltSwap, zoomKey }, new boolean[] { false, false, false, false }, getVanillaKeyBindings(), new boolean[] { false, false });
|
2014-07-06 22:59:44 -08:00
|
|
|
/*ClientRegistry.registerKeyBinding(armorKey);
|
2014-07-02 23:37:28 -08:00
|
|
|
ClientRegistry.registerKeyBinding(refreshCapes);
|
|
|
|
|
ClientRegistry.registerKeyBinding(toggleGoggles);
|
|
|
|
|
ClientRegistry.registerKeyBinding(beltSwap);
|
2014-07-06 22:59:44 -08:00
|
|
|
ClientRegistry.registerKeyBinding(zoomKey);*/
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static KeyBinding[] getVanillaKeyBindings ()
|
|
|
|
|
{
|
|
|
|
|
mc = Minecraft.getMinecraft();
|
|
|
|
|
jumpKey = mc.gameSettings.keyBindJump;
|
2014-02-05 08:28:53 -05:00
|
|
|
invKey = mc.gameSettings.keyBindInventory;
|
2013-07-26 21:18:53 -07:00
|
|
|
return new KeyBinding[] { jumpKey, invKey };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-02 12:06:48 -05:00
|
|
|
public void keyDown (Type types, KeyBinding kb, boolean tickEnd, boolean isRepeat)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
|
|
|
|
if (tickEnd && mc.theWorld != null)
|
|
|
|
|
{
|
2014-02-16 14:23:50 -05:00
|
|
|
if (kb == armorKey && mc.currentScreen == null) // Extended Armor
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-16 14:23:50 -05:00
|
|
|
openArmorGui();// mc.thePlayer.username);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
2014-08-07 19:14:17 -04:00
|
|
|
if (kb == invKey && mc.currentScreen != null && mc.currentScreen.getClass() == GuiInventory.class)// &&// !mc.playerController.isInCreativeMode())
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-08-07 19:14:17 -04:00
|
|
|
MinecraftForge.EVENT_BUS.register(new TabRegistry());
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
2014-02-16 14:23:50 -05:00
|
|
|
if (kb == jumpKey) // Double jump
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2013-11-14 14:26:37 -08:00
|
|
|
if (mc.thePlayer.capabilities.isCreativeMode)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-02-11 21:35:05 -05:00
|
|
|
if (jumping && midairJumps > 0)
|
|
|
|
|
{
|
|
|
|
|
mc.thePlayer.motionY = 0.42D;
|
|
|
|
|
mc.thePlayer.fallDistance = 0;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-02-11 21:35:05 -05:00
|
|
|
if (mc.thePlayer.isPotionActive(Potion.jump))
|
|
|
|
|
{
|
|
|
|
|
mc.thePlayer.motionY += (double) ((float) (mc.thePlayer.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.1F);
|
|
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-02-11 21:35:05 -05:00
|
|
|
midairJumps--;
|
2014-02-26 20:30:13 +11:00
|
|
|
resetFallDamage();
|
2014-02-11 21:35:05 -05:00
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-02-11 21:35:05 -05:00
|
|
|
if (!jumping)
|
2014-06-30 22:26:00 -08:00
|
|
|
{
|
2014-02-11 21:35:05 -05:00
|
|
|
jumping = mc.thePlayer.isAirBorne;
|
2014-06-30 22:26:00 -08:00
|
|
|
ItemStack shoes = mc.thePlayer.getCurrentArmor(0);
|
|
|
|
|
if (shoes != null && shoes.hasTagCompound() && shoes.getTagCompound().hasKey("TinkerArmor"))
|
|
|
|
|
{
|
|
|
|
|
NBTTagCompound shoeTag = shoes.getTagCompound().getCompoundTag("TinkerArmor");
|
|
|
|
|
midairJumps += shoeTag.getInteger("Double-Jump");
|
|
|
|
|
}
|
|
|
|
|
ItemStack wings = mc.thePlayer.getCurrentArmor(1);
|
|
|
|
|
if (wings != null && wings.hasTagCompound() && wings.getTagCompound().hasKey("TinkerArmor"))
|
|
|
|
|
{
|
|
|
|
|
NBTTagCompound shoeTag = wings.getTagCompound().getCompoundTag("TinkerArmor");
|
|
|
|
|
midairJumps += shoeTag.getInteger("Double-Jump");
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-02-08 13:30:19 -05:00
|
|
|
}
|
2014-06-30 22:26:00 -08:00
|
|
|
|
2014-07-21 12:52:39 -08:00
|
|
|
if (mc.currentScreen == null)
|
2014-06-30 22:26:00 -08:00
|
|
|
{
|
|
|
|
|
if (kb == toggleGoggles)
|
|
|
|
|
{
|
|
|
|
|
ItemStack goggles = mc.thePlayer.getCurrentArmor(3);
|
|
|
|
|
if (goggles != null && goggles.getItem() instanceof TravelGear) //TODO: Genericize this
|
|
|
|
|
{
|
2014-07-21 12:52:39 -08:00
|
|
|
activeGoggles = !activeGoggles;
|
|
|
|
|
toggleGoggles();
|
2014-06-30 22:26:00 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (kb == beltSwap)
|
|
|
|
|
{
|
2014-07-21 12:52:39 -08:00
|
|
|
if (ArmorProxyClient.armorExtended.inventory[3] != null)
|
2014-06-30 22:26:00 -08:00
|
|
|
{
|
2014-07-21 12:52:39 -08:00
|
|
|
PlayerAbilityHelper.swapBelt(mc.thePlayer, ArmorProxyClient.armorExtended);
|
|
|
|
|
toggleBelt();
|
2014-06-30 22:26:00 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (kb == zoomKey)
|
|
|
|
|
zoom = !zoom;
|
2014-07-21 12:52:39 -08:00
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2014-02-02 12:06:48 -05:00
|
|
|
public void keyUp (Type types, KeyBinding kb, boolean tickEnd)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-16 14:23:50 -05:00
|
|
|
// landOnGround();
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void landOnGround ()
|
|
|
|
|
{
|
2014-02-08 13:30:19 -05:00
|
|
|
midairJumps = 0;
|
2013-07-26 21:18:53 -07:00
|
|
|
jumping = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void resetControls ()
|
|
|
|
|
{
|
2014-02-08 13:30:19 -05:00
|
|
|
midairJumps = 0;
|
2013-07-26 21:18:53 -07:00
|
|
|
jumping = false;
|
|
|
|
|
climbing = false;
|
|
|
|
|
onGround = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-03 22:28:37 -04:00
|
|
|
void resetFallDamage ()
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-07-21 12:52:39 -08:00
|
|
|
AbstractPacket packet = new DoubleJumpPacket();
|
2014-02-26 20:30:13 +11:00
|
|
|
updateServer(packet);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void openArmorGui ()
|
|
|
|
|
{
|
2014-07-21 12:52:39 -08:00
|
|
|
AbstractPacket packet = new AccessoryInventoryPacket(ArmorProxyCommon.armorGuiID);
|
2014-02-26 20:30:13 +11:00
|
|
|
updateServer(packet);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void openKnapsackGui ()
|
|
|
|
|
{
|
2014-07-21 12:52:39 -08:00
|
|
|
AbstractPacket packet = new AccessoryInventoryPacket(ArmorProxyCommon.knapsackGuiID);
|
|
|
|
|
updateServer(packet);
|
|
|
|
|
}
|
2014-08-07 19:14:17 -04:00
|
|
|
|
|
|
|
|
private void toggleGoggles ()
|
2014-07-21 12:52:39 -08:00
|
|
|
{
|
|
|
|
|
AbstractPacket packet = new GogglePacket(activeGoggles);
|
|
|
|
|
updateServer(packet);
|
|
|
|
|
}
|
2014-08-07 19:14:17 -04:00
|
|
|
|
|
|
|
|
private void toggleBelt ()
|
2014-07-21 12:52:39 -08:00
|
|
|
{
|
|
|
|
|
AbstractPacket packet = new BeltPacket();
|
2014-02-26 20:30:13 +11:00
|
|
|
updateServer(packet);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
|
|
|
|
|
2014-02-26 20:30:13 +11:00
|
|
|
static void updateServer (AbstractPacket abstractPacket)
|
2013-07-26 21:18:53 -07:00
|
|
|
{
|
2014-02-26 20:30:13 +11:00
|
|
|
TConstruct.packetPipeline.sendToServer(abstractPacket);
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|
2014-02-02 12:06:48 -05:00
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|