-
Notifications
You must be signed in to change notification settings - Fork 753
/
TControls.java
215 lines (191 loc) · 7.72 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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.ArmorProxyCommon;
import tconstruct.client.event.EventCloakRender;
import tconstruct.client.tabs.TabRegistry;
import tconstruct.util.network.packet.PacketDoubleJump;
import tconstruct.util.network.packet.PacketExtendedInventory;
import cpw.mods.fml.client.registry.ClientRegistry;
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 refreshCapes = new KeyBinding("key.tcapes.reload", 88, 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", 29, 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;
boolean onStilts = false;
public static boolean zoom = false;
int currentTab = 1;
// boolean onStilts = false;
public TControls()
{
super(new KeyBinding[] { armorKey, refreshCapes, toggleGoggles, beltSwap, zoomKey }, new boolean[] { false, 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 == refreshCapes && mc.currentScreen == null)
{
EventCloakRender.instance.refreshCapes();
}
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
{
PlayerAbilityHelper.toggleGoggles(mc.thePlayer);
updateServer((byte) 9);
}
}
if (kb == beltSwap)
{
TPlayerStats stats = TConstruct.playerTracker.getPlayerStats(mc.thePlayer.username);
if (stats.armor.inventory[3] != null)
{
//PlayerAbilityHelper.swapBelt(mc.thePlayer, stats);
updateServer((byte) 8);
}
}
if (kb == zoomKey)
zoom = !zoom;
}*/
}
/*
* else if (kb == stiltsKey) //Stilts { float size = 1.8F; if
* (!onStilts) size = 0.8F;
* TConstruct.playerTracker.updateSize(mc.thePlayer.username, size);
* onStilts = !onStilts; //updateServer(mc.thePlayer.username, (byte)
* 11); if (onStilts) { onStilts = false; } else { onStilts = true; } }
*/
}
@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;
onStilts = false;
}
void resetFallDamage ()
{
AbstractPacket packet = new PacketDoubleJump();
updateServer(packet);
}
void updateSize (String name, float size)
{
/*ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try
{
outputStream.writeByte(11);
outputStream.writeUTF(name);
outputStream.writeFloat(size);
}
catch (Exception ex)
{
ex.printStackTrace();
}
updateServer(bos);*/
//TODO: Enable code with right packet
//AbstractPacket packet = new ();
//updateServer(packet);
}
public static void openArmorGui ()
{
AbstractPacket packet = new PacketExtendedInventory(ArmorProxyCommon.armorGuiID);
updateServer(packet);
}
public static void openKnapsackGui ()
{
AbstractPacket packet = new PacketExtendedInventory(ArmorProxyCommon.knapsackGuiID);
updateServer(packet);
}
static void updateServer (AbstractPacket abstractPacket)
{
TConstruct.packetPipeline.sendToServer(abstractPacket);
}
}