-
Notifications
You must be signed in to change notification settings - Fork 755
/
TControls.java
184 lines (159 loc) · 5.82 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
package tconstruct.client;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
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.potion.Potion;
import tconstruct.TConstruct;
import tconstruct.client.event.EventCloakRender;
import tconstruct.client.tabs.TabRegistry;
import tconstruct.util.network.packet.PacketDoubleJump;
import cpw.mods.fml.common.gameevent.TickEvent.Type;
public class TControls extends TKeyHandler
{
public static final String keybindCategory = "key.tconstruct.category";
// 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, keybindCategory);
public static KeyBinding refreshCapes = new KeyBinding("key.tcapes.reload", 88, keybindCategory);
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 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(mc.thePlayer.getDisplayName());
}
if (!jumping)
jumping = mc.thePlayer.isAirBorne;
}
}
/*
* 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 (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 openArmorGui ()
{
// Position is unused. Set to 0.
mc.thePlayer.openGui(TConstruct.instance, TProxyClient.armorGuiID, mc.theWorld, 0, 0, 0);
}
public static void openKnapsackGui ()
{
// Position is unused. Set to 0.
mc.thePlayer.openGui(TConstruct.instance, TProxyClient.knapsackGuiID, mc.theWorld, 0, 0, 0);
}
static void updateServer (ByteArrayOutputStream bos)
{
/*
* Packet250CustomPayload packet = new Packet250CustomPayload();
* packet.channel = "TConstruct"; packet.data = bos.toByteArray();
* packet.length = bos.size();
*
* PacketDispatcher.sendPacketToServer(packet);
*/
// TODO Find out what packet should be used here
TConstruct.packetPipeline.sendToServer(new PacketDoubleJump());
}
}