-
Notifications
You must be signed in to change notification settings - Fork 753
/
TControls.java
194 lines (171 loc) · 6.81 KB
/
TControls.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package tconstruct.client;
import mantle.common.network.AbstractPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.potion.Potion;
import tconstruct.TConstruct;
import tconstruct.armor.ArmorProxyClient;
import tconstruct.armor.ArmorProxyCommon;
import tconstruct.armor.PlayerAbilityHelper;
import tconstruct.armor.items.TravelGear;
import tconstruct.client.tabs.TabRegistry;
import tconstruct.util.network.AccessoryInventoryPacket;
import tconstruct.util.network.BeltPacket;
import tconstruct.util.network.DoubleJumpPacket;
import tconstruct.util.network.GogglePacket;
import cpw.mods.fml.common.gameevent.TickEvent.Type;
public class TControls extends TKeyHandler
{
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;
public TControls()
{
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);*/
}
private static KeyBinding[] getVanillaKeyBindings ()
{
mc = Minecraft.getMinecraft();
jumpKey = mc.gameSettings.keyBindJump;
invKey = mc.gameSettings.keyBindInventory;
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);
}
if (kb == invKey && mc.currentScreen != null && mc.currentScreen.getClass() == GuiInventory.class)// &&
// !mc.playerController.isInCreativeMode())
{
TabRegistry.addTabsToInventory((GuiContainer) mc.currentScreen);
}
if (kb == jumpKey) // Double jump
{
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 (kb == toggleGoggles)
{
ItemStack goggles = mc.thePlayer.getCurrentArmor(3);
if (goggles != null && goggles.getItem() instanceof TravelGear) //TODO: Genericize this
{
activeGoggles = !activeGoggles;
toggleGoggles();
}
}
if (kb == beltSwap)
{
if (ArmorProxyClient.armorExtended.inventory[3] != null)
{
PlayerAbilityHelper.swapBelt(mc.thePlayer, ArmorProxyClient.armorExtended);
toggleBelt();
}
}
if (kb == zoomKey)
zoom = !zoom;
}
}
}
@Override
public void keyUp (Type types, KeyBinding kb, boolean tickEnd)
{
// landOnGround();
}
public void landOnGround ()
{
midairJumps = 0;
jumping = false;
}
public void resetControls ()
{
midairJumps = 0;
jumping = false;
climbing = false;
onGround = false;
}
void resetFallDamage ()
{
AbstractPacket packet = new DoubleJumpPacket();
updateServer(packet);
}
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);
}
}