2013-07-26 21:18:53 -07:00
|
|
|
package tconstruct.client;
|
|
|
|
|
|
2014-11-10 18:37:27 -05:00
|
|
|
import cpw.mods.fml.client.registry.ClientRegistry;
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
|
import cpw.mods.fml.common.gameevent.InputEvent;
|
2014-06-01 21:20:12 -04:00
|
|
|
import mantle.common.network.AbstractPacket;
|
2014-11-10 18:37:27 -05:00
|
|
|
import modwarriors.notenoughkeys.api.Api;
|
|
|
|
|
import modwarriors.notenoughkeys.api.KeyBindingPressedEvent;
|
2013-07-26 21:18:53 -07:00
|
|
|
import net.minecraft.client.Minecraft;
|
|
|
|
|
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-11-10 18:37:27 -05:00
|
|
|
import org.lwjgl.input.Keyboard;
|
|
|
|
|
import org.lwjgl.input.Mouse;
|
2014-02-01 17:28:41 +11:00
|
|
|
import tconstruct.TConstruct;
|
2014-11-10 18:37:27 -05:00
|
|
|
import tconstruct.armor.ArmorProxyClient;
|
|
|
|
|
import tconstruct.armor.ArmorProxyCommon;
|
|
|
|
|
import tconstruct.armor.PlayerAbilityHelper;
|
2014-07-21 12:52:39 -08:00
|
|
|
import tconstruct.armor.items.TravelGear;
|
2014-11-10 18:37:27 -05:00
|
|
|
import tconstruct.util.network.AccessoryInventoryPacket;
|
|
|
|
|
import tconstruct.util.network.BeltPacket;
|
|
|
|
|
import tconstruct.util.network.DoubleJumpPacket;
|
|
|
|
|
import tconstruct.util.network.GogglePacket;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-11-10 18:37:27 -05:00
|
|
|
public class ArmorControls {
|
2014-11-10 18:47:15 -05:00
|
|
|
public static final String keybindCategory = "tconstruct.keybindings";
|
|
|
|
|
public static KeyBinding armorKey = new KeyBinding("key.tarmor", 24, keybindCategory);
|
|
|
|
|
public static KeyBinding toggleGoggles = new KeyBinding("key.tgoggles", 34, keybindCategory);
|
|
|
|
|
public static KeyBinding beltSwap = new KeyBinding("key.tbelt", 48, keybindCategory);
|
|
|
|
|
public static KeyBinding zoomKey = new KeyBinding("key.tzoom", 44,
|
|
|
|
|
keybindCategory); //TODO: Make this hold, not toggle
|
|
|
|
|
static KeyBinding jumpKey;
|
|
|
|
|
static KeyBinding invKey;
|
|
|
|
|
static Minecraft mc;
|
|
|
|
|
|
|
|
|
|
boolean jumping;
|
|
|
|
|
int midairJumps = 0;
|
|
|
|
|
boolean climbing = false;
|
|
|
|
|
boolean onGround = false;
|
|
|
|
|
public static boolean zoom = false;
|
|
|
|
|
boolean activeGoggles = false; //TODO: Set this on server login
|
|
|
|
|
|
|
|
|
|
int currentTab = 1;
|
|
|
|
|
|
|
|
|
|
// boolean onStilts = false;
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-11-10 18:37:27 -05:00
|
|
|
private final KeyBinding[] keys;
|
|
|
|
|
|
2014-11-10 18:47:15 -05:00
|
|
|
public ArmorControls() {
|
2014-11-10 18:37:27 -05:00
|
|
|
getVanillaKeyBindings();
|
|
|
|
|
this.keys = new KeyBinding[] {
|
|
|
|
|
ArmorControls.armorKey,
|
|
|
|
|
ArmorControls.toggleGoggles,
|
|
|
|
|
ArmorControls.beltSwap,
|
|
|
|
|
ArmorControls.zoomKey,
|
|
|
|
|
null, null
|
|
|
|
|
};
|
|
|
|
|
|
2014-11-10 18:47:15 -05:00
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-11-10 18:37:27 -05:00
|
|
|
public void registerKeys() {
|
|
|
|
|
// Register bindings
|
|
|
|
|
for (KeyBinding key : this.keys) {
|
|
|
|
|
if (key != null)
|
|
|
|
|
ClientRegistry.registerKeyBinding(key);
|
|
|
|
|
}
|
|
|
|
|
// Add mc keys
|
|
|
|
|
this.keys[4] = ArmorControls.jumpKey;
|
|
|
|
|
this.keys[5] = ArmorControls.invKey;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-10 18:47:15 -05:00
|
|
|
private static KeyBinding[] getVanillaKeyBindings() {
|
|
|
|
|
mc = Minecraft.getMinecraft();
|
|
|
|
|
jumpKey = mc.gameSettings.keyBindJump;
|
|
|
|
|
invKey = mc.gameSettings.keyBindInventory;
|
|
|
|
|
return new KeyBinding[] { jumpKey, invKey };
|
|
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-11-10 18:37:27 -05:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public void mouseEvent(InputEvent.MouseInputEvent event) {
|
|
|
|
|
if (!Api.isLoaded())
|
|
|
|
|
this.checkKeys();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void keyEvent(InputEvent.KeyInputEvent event) {
|
|
|
|
|
if (!Api.isLoaded())
|
|
|
|
|
this.checkKeys();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void keyEventSpecial(KeyBindingPressedEvent event) {
|
|
|
|
|
this.keyPressed(event.keyBinding);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkKeys() {
|
|
|
|
|
for (KeyBinding key : this.keys) {
|
|
|
|
|
if (this.isKeyActive(key.getKeyCode())) {
|
|
|
|
|
this.keyPressed(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isKeyActive(int keyCode) {
|
|
|
|
|
if (keyCode < 0)
|
|
|
|
|
return Mouse.isButtonDown(keyCode + 100);
|
|
|
|
|
else
|
|
|
|
|
return Keyboard.isKeyDown(keyCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void keyPressed(KeyBinding key) {
|
|
|
|
|
if (key == ArmorControls.armorKey) {
|
|
|
|
|
openArmorGui();
|
|
|
|
|
}
|
|
|
|
|
if (key == ArmorControls.jumpKey) {
|
|
|
|
|
if (mc.thePlayer.capabilities.isCreativeMode)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (jumping && midairJumps > 0) {
|
|
|
|
|
mc.thePlayer.motionY = 0.42D;
|
|
|
|
|
mc.thePlayer.fallDistance = 0;
|
|
|
|
|
|
|
|
|
|
if (mc.thePlayer.isPotionActive(Potion.jump)) {
|
|
|
|
|
mc.thePlayer.motionY += (double) (
|
|
|
|
|
(float) (mc.thePlayer.getActivePotionEffect(Potion.jump).getAmplifier()
|
|
|
|
|
+ 1) * 0.1F);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
midairJumps--;
|
|
|
|
|
resetFallDamage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!jumping) {
|
|
|
|
|
jumping = mc.thePlayer.isAirBorne;
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (mc.currentScreen == null) {
|
|
|
|
|
if (key == ArmorControls.toggleGoggles) {
|
|
|
|
|
ItemStack goggles = mc.thePlayer.getCurrentArmor(3);
|
|
|
|
|
if (goggles != null && goggles
|
|
|
|
|
.getItem() instanceof TravelGear) //TODO: Genericize this
|
|
|
|
|
{
|
|
|
|
|
activeGoggles = !activeGoggles;
|
|
|
|
|
PlayerAbilityHelper.toggleGoggles(mc.thePlayer, activeGoggles);
|
|
|
|
|
toggleGoggles();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (key == ArmorControls.beltSwap) {
|
|
|
|
|
if (ArmorProxyClient.armorExtended.inventory[3] != null) {
|
|
|
|
|
PlayerAbilityHelper.swapBelt(mc.thePlayer, ArmorProxyClient.armorExtended);
|
|
|
|
|
toggleBelt();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (key == ArmorControls.zoomKey) {
|
|
|
|
|
zoom = !zoom;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-10 18:49:54 -05:00
|
|
|
public void landOnGround() {
|
|
|
|
|
midairJumps = 0;
|
|
|
|
|
jumping = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-10 18:47:15 -05:00
|
|
|
public void resetControls() {
|
2014-11-10 18:37:27 -05:00
|
|
|
midairJumps = 0;
|
|
|
|
|
jumping = false;
|
2014-11-10 18:47:15 -05:00
|
|
|
climbing = false;
|
|
|
|
|
onGround = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void resetFallDamage() {
|
|
|
|
|
AbstractPacket packet = new DoubleJumpPacket();
|
|
|
|
|
updateServer(packet);
|
2014-11-10 18:37:27 -05:00
|
|
|
}
|
2013-07-26 21:18:53 -07:00
|
|
|
|
2014-11-10 18:47:15 -05:00
|
|
|
public static void openArmorGui() {
|
|
|
|
|
AbstractPacket packet = new AccessoryInventoryPacket(ArmorProxyCommon.armorGuiID);
|
|
|
|
|
updateServer(packet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void openKnapsackGui() {
|
|
|
|
|
AbstractPacket packet = new AccessoryInventoryPacket(ArmorProxyCommon.knapsackGuiID);
|
|
|
|
|
updateServer(packet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void toggleGoggles() {
|
|
|
|
|
AbstractPacket packet = new GogglePacket(activeGoggles);
|
|
|
|
|
updateServer(packet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void toggleBelt() {
|
|
|
|
|
AbstractPacket packet = new BeltPacket();
|
|
|
|
|
updateServer(packet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void updateServer(AbstractPacket abstractPacket) {
|
|
|
|
|
TConstruct.packetPipeline.sendToServer(abstractPacket);
|
|
|
|
|
}
|
2014-02-02 12:06:48 -05:00
|
|
|
|
2013-07-26 21:18:53 -07:00
|
|
|
}
|