Files
TinkersConstruct/src/main/java/tconstruct/client/TControls.java
T

233 lines
6.5 KiB
Java
Raw Normal View History

package tconstruct.client;
2014-02-05 10:28:54 -05:00
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
2014-02-02 12:06:48 -05:00
import net.minecraft.client.Minecraft;
2014-02-05 10:28:54 -05:00
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.client.settings.KeyBinding;
2014-02-01 17:28:41 +11:00
import tconstruct.TConstruct;
2013-08-23 22:20:53 -07:00
import tconstruct.client.event.EventCloakRender;
2013-08-15 01:31:12 -04:00
import tconstruct.client.tabs.TabRegistry;
2014-02-01 17:28:41 +11:00
import tconstruct.util.network.packet.PacketDoubleJump;
2014-02-05 10:28:54 -05:00
import cpw.mods.fml.common.gameevent.TickEvent.Type;
public class TControls extends TKeyHandler
{
//static KeyBinding grabKey = new KeyBinding("key.grab", 29);
//static KeyBinding stiltsKey = new KeyBinding("key.stilts", 46);
2014-02-02 12:06:48 -05:00
public static KeyBinding armorKey = new KeyBinding("key.tarmor", 24, null);
public static KeyBinding refreshCapes = new KeyBinding("key.tcapes.reload", 88, null);
static KeyBinding jumpKey;
static KeyBinding invKey;
static Minecraft mc;
boolean jumping;
boolean doubleJump = true;
boolean climbing = false;
boolean onGround = false;
boolean onStilts = false;
int currentTab = 1;
//boolean onStilts = false;
public TControls()
{
2013-08-31 05:13:31 -07:00
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;
2014-02-05 08:28:53 -05:00
invKey = mc.gameSettings.keyBindInventory;
return new KeyBinding[] { jumpKey, invKey };
}
@Override
2014-02-02 12:06:48 -05:00
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())
{
2013-08-15 01:31:12 -04:00
TabRegistry.addTabsToInventory((GuiContainer) mc.currentScreen);
}
2013-08-31 05:13:31 -07:00
if (kb == refreshCapes && mc.currentScreen == null)
{
EventCloakRender.instance.refreshCapes();
2013-08-23 22:20:53 -07:00
}
/*if (kb == jumpKey) //Double jump
{
2013-11-14 14:26:37 -08:00
if (mc.thePlayer.capabilities.isCreativeMode)
return;
if (jumping && !doubleJump)
{
2013-11-14 14:26:37 -08:00
System.out.println("Jump!");
//if (player == null)
//player = mc.thePlayer;
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);
}
doubleJump = true;
resetFallDamage(mc.thePlayer.username);
}
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
2014-02-02 12:06:48 -05:00
public void keyUp (Type types, KeyBinding kb, boolean tickEnd)
{
//landOnGround();
}
public void landOnGround ()
{
doubleJump = false;
jumping = false;
}
public void resetControls ()
{
doubleJump = false;
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)
{
2014-02-01 17:28:41 +11:00
/*Packet250CustomPayload packet = new Packet250CustomPayload();
packet.channel = "TConstruct";
packet.data = bos.toByteArray();
packet.length = bos.size();
2014-02-01 17:28:41 +11:00
PacketDispatcher.sendPacketToServer(packet);*/
2014-02-02 12:06:48 -05:00
2014-02-01 17:28:41 +11:00
//TODO Find out what packet should be used here
TConstruct.packetPipeline.sendToServer(new PacketDoubleJump());
}
2014-02-02 12:06:48 -05:00
}