-
Notifications
You must be signed in to change notification settings - Fork 753
/
TControls.java
232 lines (202 loc) · 6.53 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package tconstruct.client;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.EnumSet;
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.network.packet.Packet250CustomPayload;
import net.minecraft.potion.Potion;
import tconstruct.client.event.EventCloakRender;
import tconstruct.client.tabs.TabRegistry;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.common.network.PacketDispatcher;
public class TControls extends TKeyHandler
{
//static KeyBinding grabKey = new KeyBinding("key.grab", 29);
//static KeyBinding stiltsKey = new KeyBinding("key.stilts", 46);
public static KeyBinding armorKey = new KeyBinding("key.tarmor", 24);
public static KeyBinding refreshCapes = new KeyBinding("key.tcapes.reload", 88);
static KeyBinding jumpKey;
static KeyBinding invKey;
static Minecraft mc;
boolean jumping;
int midairJumps = 0;
boolean climbing = false;
boolean onGround = false;
boolean onStilts = false;
int currentTab = 1;
//boolean onStilts = false;
public TControls()
{
super(new KeyBinding[] { armorKey, refreshCapes }, new boolean[] { false, false }, getVanillaKeyBindings(), new boolean[] { false, false });
//TConstruct.logger.info("Controls registered");
}
private static KeyBinding[] getVanillaKeyBindings ()
{
mc = Minecraft.getMinecraft();
jumpKey = mc.gameSettings.keyBindJump;
invKey = mc.gameSettings.keyBindInventory;
return new KeyBinding[] { jumpKey, invKey };
}
@Override
public String getLabel ()
{
return null;
}
@Override
public void keyDown (EnumSet<TickType> 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(mc.thePlayer.username);
}
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");
}
}
}
}
}
@Override
public void keyUp (EnumSet<TickType> types, KeyBinding kb, boolean tickEnd)
{
//landOnGround();
}
@Override
public EnumSet<TickType> ticks ()
{
return EnumSet.of(TickType.CLIENT);
}
public void landOnGround ()
{
midairJumps = 0;
jumping = false;
}
public void resetControls ()
{
midairJumps = 0;
jumping = false;
climbing = false;
onGround = false;
onStilts = false;
}
void resetFallDamage (String name)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try
{
outputStream.writeByte(10);
outputStream.writeUTF(name);
}
catch (Exception ex)
{
ex.printStackTrace();
}
updateServer(bos);
}
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);
}
public static void openInventoryGui ()
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try
{
outputStream.writeByte(3);
outputStream.writeByte(0);
}
catch (Exception ex)
{
ex.printStackTrace();
}
updateServer(bos);
}
public static void openArmorGui ()
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try
{
outputStream.writeByte(3);
outputStream.writeByte(1);
}
catch (Exception ex)
{
ex.printStackTrace();
}
updateServer(bos);
}
public static void openKnapsackGui ()
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try
{
outputStream.writeByte(3);
outputStream.writeByte(2);
}
catch (Exception ex)
{
ex.printStackTrace();
}
updateServer(bos);
}
static void updateServer (ByteArrayOutputStream bos)
{
Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "TConstruct";
packet.data = bos.toByteArray();
packet.length = bos.size();
PacketDispatcher.sendPacketToServer(packet);
}
}