mirror of
https://github.com/GTNewHorizons/TinkersConstruct.git
synced 2026-11-21 04:32:26 +00:00
This should be valid for NEK integration.
This commit is contained in:
1 parent
28a4dfe478
commit
8a0092e147
6 files changed
+642
-642
No files matched your search
@@ -1,19 +1,29 @@
|
||||
package tconstruct.client;
|
||||
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Type;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import mantle.common.network.AbstractPacket;
|
||||
import modwarriors.notenoughkeys.api.Api;
|
||||
import modwarriors.notenoughkeys.api.KeyBindingPressedEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.potion.Potion;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import tconstruct.TConstruct;
|
||||
import tconstruct.armor.*;
|
||||
import tconstruct.armor.ArmorProxyClient;
|
||||
import tconstruct.armor.ArmorProxyCommon;
|
||||
import tconstruct.armor.PlayerAbilityHelper;
|
||||
import tconstruct.armor.items.TravelGear;
|
||||
import tconstruct.util.network.*;
|
||||
import tconstruct.util.network.AccessoryInventoryPacket;
|
||||
import tconstruct.util.network.BeltPacket;
|
||||
import tconstruct.util.network.DoubleJumpPacket;
|
||||
import tconstruct.util.network.GogglePacket;
|
||||
|
||||
public class ArmorControls extends TKeyHandler
|
||||
{
|
||||
public class ArmorControls {
|
||||
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);
|
||||
@@ -34,16 +44,32 @@ public class ArmorControls extends TKeyHandler
|
||||
|
||||
// boolean onStilts = false;
|
||||
|
||||
private final KeyBinding[] keys;
|
||||
|
||||
public ArmorControls()
|
||||
{
|
||||
super(new KeyBinding[] { armorKey, toggleGoggles, beltSwap, zoomKey }, new boolean[] { false, false, false, false }, getVanillaKeyBindings(), new boolean[] { false, false });
|
||||
/*ClientRegistry.registerKeyBinding(armorKey);
|
||||
ClientRegistry.registerKeyBinding(refreshCapes);
|
||||
ClientRegistry.registerKeyBinding(toggleGoggles);
|
||||
ClientRegistry.registerKeyBinding(beltSwap);
|
||||
ClientRegistry.registerKeyBinding(zoomKey);*/
|
||||
getVanillaKeyBindings();
|
||||
this.keys = new KeyBinding[] {
|
||||
ArmorControls.armorKey,
|
||||
ArmorControls.toggleGoggles,
|
||||
ArmorControls.beltSwap,
|
||||
ArmorControls.zoomKey,
|
||||
null, null
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private static KeyBinding[] getVanillaKeyBindings ()
|
||||
{
|
||||
mc = Minecraft.getMinecraft();
|
||||
@@ -52,90 +78,103 @@ public class ArmorControls extends TKeyHandler
|
||||
return new KeyBinding[] { jumpKey, invKey };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyDown (Type types, KeyBinding kb, boolean tickEnd, boolean isRepeat)
|
||||
{
|
||||
if (tickEnd && mc.theWorld != null)
|
||||
{
|
||||
if (kb == armorKey && mc.currentScreen == null) // Extended Armor
|
||||
{
|
||||
openArmorGui();// mc.thePlayer.username);
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void mouseEvent(InputEvent.MouseInputEvent event) {
|
||||
if (!Api.isLoaded())
|
||||
this.checkKeys();
|
||||
}
|
||||
|
||||
if (kb == jumpKey) // Double jump
|
||||
{
|
||||
if (mc.thePlayer.capabilities.isCreativeMode)
|
||||
return;
|
||||
@SubscribeEvent
|
||||
public void keyEvent(InputEvent.KeyInputEvent event) {
|
||||
if (!Api.isLoaded())
|
||||
this.checkKeys();
|
||||
}
|
||||
|
||||
if (jumping && midairJumps > 0)
|
||||
{
|
||||
mc.thePlayer.motionY = 0.42D;
|
||||
mc.thePlayer.fallDistance = 0;
|
||||
@SubscribeEvent
|
||||
public void keyEventSpecial(KeyBindingPressedEvent event) {
|
||||
this.keyPressed(event.keyBinding);
|
||||
}
|
||||
|
||||
if (mc.thePlayer.isPotionActive(Potion.jump))
|
||||
{
|
||||
mc.thePlayer.motionY += (double) ((float) (mc.thePlayer.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.1F);
|
||||
}
|
||||
private void checkKeys() {
|
||||
for (KeyBinding key : this.keys) {
|
||||
if (this.isKeyActive(key.getKeyCode())) {
|
||||
this.keyPressed(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
midairJumps--;
|
||||
resetFallDamage();
|
||||
}
|
||||
private boolean isKeyActive(int keyCode) {
|
||||
if (keyCode < 0)
|
||||
return Mouse.isButtonDown(keyCode + 100);
|
||||
else
|
||||
return Keyboard.isKeyDown(keyCode);
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
private void keyPressed(KeyBinding key) {
|
||||
if (key == ArmorControls.armorKey) {
|
||||
openArmorGui();
|
||||
}
|
||||
if (key == ArmorControls.jumpKey) {
|
||||
if (mc.thePlayer.capabilities.isCreativeMode)
|
||||
return;
|
||||
|
||||
if (mc.currentScreen == null)
|
||||
{
|
||||
if (kb == 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 (kb == beltSwap)
|
||||
{
|
||||
if (ArmorProxyClient.armorExtended.inventory[3] != null)
|
||||
{
|
||||
PlayerAbilityHelper.swapBelt(mc.thePlayer, ArmorProxyClient.armorExtended);
|
||||
toggleBelt();
|
||||
}
|
||||
}
|
||||
if (kb == zoomKey)
|
||||
zoom = !zoom;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (jumping && midairJumps > 0) {
|
||||
mc.thePlayer.motionY = 0.42D;
|
||||
mc.thePlayer.fallDistance = 0;
|
||||
|
||||
@Override
|
||||
public void keyUp (Type types, KeyBinding kb, boolean tickEnd)
|
||||
{
|
||||
// landOnGround();
|
||||
}
|
||||
if (mc.thePlayer.isPotionActive(Potion.jump)) {
|
||||
mc.thePlayer.motionY += (double) (
|
||||
(float) (mc.thePlayer.getActivePotionEffect(Potion.jump).getAmplifier()
|
||||
+ 1) * 0.1F);
|
||||
}
|
||||
|
||||
public void landOnGround ()
|
||||
{
|
||||
midairJumps = 0;
|
||||
jumping = false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void landOnGround() {
|
||||
midairJumps = 0;
|
||||
jumping = false;
|
||||
}
|
||||
|
||||
public void resetControls ()
|
||||
{
|
||||
|
||||
@@ -1,142 +0,0 @@
|
||||
package tconstruct.client;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Type;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import java.util.EnumSet;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import org.lwjgl.input.*;
|
||||
|
||||
public abstract class TKeyHandler
|
||||
{
|
||||
public KeyBinding[] keyBindings;
|
||||
public KeyBinding[] vKeyBindings;
|
||||
public boolean[] keyDown;
|
||||
public boolean[] repeatings;
|
||||
public boolean[] vRepeatings;
|
||||
public boolean isDummy;
|
||||
|
||||
/**
|
||||
* Pass an array of keybindings and a repeat flag for each one
|
||||
*
|
||||
* @param keyBindings
|
||||
* @param repeatings
|
||||
*/
|
||||
public TKeyHandler(KeyBinding[] keyBindings, boolean[] repeatings, KeyBinding[] vanillaKeys, boolean[] vanillaRepeatings)
|
||||
{
|
||||
assert keyBindings.length == repeatings.length : "You need to pass two arrays of identical length";
|
||||
assert vanillaKeys.length == vanillaRepeatings.length : "You need to pass two arrays of identical length";
|
||||
this.keyBindings = keyBindings;
|
||||
this.repeatings = repeatings;
|
||||
this.vKeyBindings = vanillaKeys;
|
||||
this.vRepeatings = vanillaRepeatings;
|
||||
this.keyDown = new boolean[keyBindings.length + vanillaKeys.length];
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the keys into the system. You will do your own keyboard
|
||||
* management elsewhere. No events will fire if you use this method
|
||||
*
|
||||
* @param keyBindings
|
||||
*/
|
||||
public TKeyHandler(KeyBinding[] keyBindings)
|
||||
{
|
||||
this.keyBindings = keyBindings;
|
||||
this.isDummy = true;
|
||||
}
|
||||
|
||||
public KeyBinding[] getKeyBindings ()
|
||||
{
|
||||
return this.keyBindings;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTick (ClientTickEvent event)
|
||||
{
|
||||
if (event.side == Side.CLIENT)
|
||||
{
|
||||
if (event.phase == Phase.START)
|
||||
keyTick(event.type, false);
|
||||
else if (event.phase == Phase.END)
|
||||
keyTick(event.type, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void keyTick (Type type, boolean tickEnd)
|
||||
{
|
||||
for (int i = 0; i < keyBindings.length; i++)
|
||||
{
|
||||
KeyBinding keyBinding = keyBindings[i];
|
||||
int keyCode = keyBinding.getKeyCode();
|
||||
boolean state = (keyCode < 0 ? Mouse.isButtonDown(keyCode + 100) : Keyboard.isKeyDown(keyCode));
|
||||
if (state != keyDown[i] || (state && repeatings[i]))
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
keyDown(type, keyBinding, tickEnd, state != keyDown[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
keyUp(type, keyBinding, tickEnd);
|
||||
}
|
||||
if (tickEnd)
|
||||
{
|
||||
keyDown[i] = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < vKeyBindings.length; i++)
|
||||
{
|
||||
KeyBinding keyBinding = vKeyBindings[i];
|
||||
int keyCode = keyBinding.getKeyCode();
|
||||
boolean state = (keyCode < 0 ? Mouse.isButtonDown(keyCode + 100) : Keyboard.isKeyDown(keyCode));
|
||||
if (state != keyDown[i + keyBindings.length] || (state && vRepeatings[i]))
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
keyDown(type, keyBinding, tickEnd, state != keyDown[i + keyBindings.length]);
|
||||
}
|
||||
else
|
||||
{
|
||||
keyUp(type, keyBinding, tickEnd);
|
||||
}
|
||||
if (tickEnd)
|
||||
{
|
||||
keyDown[i + keyBindings.length] = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the key is first in the down position on any tick from the
|
||||
* {@link #ticks()} set. Will be called subsequently with isRepeat set to
|
||||
* true
|
||||
*
|
||||
* @see #keyUp(EnumSet, KeyBinding, boolean)
|
||||
*
|
||||
* @param types
|
||||
* the type(s) of tick that fired when this key was first down
|
||||
* @param tickEnd
|
||||
* was it an end or start tick which fired the key
|
||||
* @param isRepeat
|
||||
* is it a repeat key event
|
||||
*/
|
||||
public abstract void keyDown (Type types, KeyBinding kb, boolean tickEnd, boolean isRepeat);
|
||||
|
||||
/**
|
||||
* Fired once when the key changes state from down to up
|
||||
*
|
||||
* @see #keyDown(EnumSet, KeyBinding, boolean, boolean)
|
||||
*
|
||||
* @param types
|
||||
* the type(s) of tick that fired when this key was first down
|
||||
* @param tickEnd
|
||||
* was it an end or start tick which fired the key
|
||||
*/
|
||||
public abstract void keyUp (Type types, KeyBinding kb, boolean tickEnd);
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user