2013-03-31 00:13:59 +01:00
|
|
|
package mekanism.client;
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
import mekanism.api.EnumColor;
|
|
|
|
import mekanism.common.ItemConfigurator;
|
|
|
|
import mekanism.common.ItemElectricBow;
|
|
|
|
import mekanism.common.PacketHandler;
|
2013-06-07 17:16:47 +02:00
|
|
|
import mekanism.common.PacketHandler.Transmission;
|
2013-06-13 23:37:30 +02:00
|
|
|
import mekanism.common.network.PacketConfiguratorState;
|
|
|
|
import mekanism.common.network.PacketElectricBowState;
|
2013-03-31 00:13:59 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2013-07-20 18:10:14 +02:00
|
|
|
import net.minecraft.util.ChatMessageComponent;
|
2013-03-31 00:13:59 +01:00
|
|
|
|
2013-06-07 17:16:47 +02:00
|
|
|
import org.lwjgl.input.Keyboard;
|
|
|
|
|
2013-03-31 00:13:59 +01:00
|
|
|
import cpw.mods.fml.common.ITickHandler;
|
|
|
|
import cpw.mods.fml.common.TickType;
|
2013-04-13 16:33:37 +02:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2013-03-31 00:13:59 +01:00
|
|
|
|
2013-04-13 16:33:37 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-03-31 00:13:59 +01:00
|
|
|
public class ClientPlayerTickHandler implements ITickHandler
|
|
|
|
{
|
|
|
|
public boolean lastTickConfiguratorChange = false;
|
|
|
|
public boolean lastTickElectricBowChange = false;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void tickStart(EnumSet<TickType> type, Object... tickData) {}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void tickEnd(EnumSet<TickType> type, Object... tickData)
|
|
|
|
{
|
|
|
|
if(tickData[0] instanceof EntityPlayer)
|
|
|
|
{
|
|
|
|
EntityPlayer entityPlayer = (EntityPlayer)tickData[0];
|
|
|
|
|
|
|
|
if(entityPlayer.getCurrentEquippedItem() != null)
|
|
|
|
{
|
|
|
|
ItemStack stack = entityPlayer.getCurrentEquippedItem();
|
|
|
|
|
|
|
|
if(entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemConfigurator)
|
|
|
|
{
|
|
|
|
ItemConfigurator item = (ItemConfigurator)entityPlayer.getCurrentEquippedItem().getItem();
|
|
|
|
|
|
|
|
if(entityPlayer.isSneaking() && Keyboard.isKeyDown(Keyboard.KEY_M))
|
|
|
|
{
|
|
|
|
if(!lastTickConfiguratorChange)
|
|
|
|
{
|
2013-07-07 03:33:08 +02:00
|
|
|
item.setState(stack, (byte)(item.getState(stack) < 2 ? item.getState(stack)+1 : 0));
|
2013-06-15 00:25:09 +02:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketConfiguratorState().setParams(item.getState(stack)));
|
2013-07-20 18:10:14 +02:00
|
|
|
entityPlayer.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + "Configure State: " + item.getColor(item.getState(stack)) + item.getState(item.getState(stack))));
|
2013-03-31 00:13:59 +01:00
|
|
|
lastTickConfiguratorChange = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastTickConfiguratorChange = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemElectricBow)
|
|
|
|
{
|
|
|
|
ItemElectricBow item = (ItemElectricBow)entityPlayer.getCurrentEquippedItem().getItem();
|
|
|
|
|
|
|
|
if(entityPlayer.isSneaking() && Keyboard.isKeyDown(Keyboard.KEY_M))
|
|
|
|
{
|
|
|
|
if(!lastTickElectricBowChange)
|
|
|
|
{
|
|
|
|
item.setFireState(stack, !item.getFireState(stack));
|
2013-06-15 00:25:09 +02:00
|
|
|
PacketHandler.sendPacket(Transmission.SERVER, new PacketElectricBowState().setParams(item.getFireState(stack)));
|
2013-07-20 18:10:14 +02:00
|
|
|
entityPlayer.sendChatToPlayer(ChatMessageComponent.func_111066_d(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + "Fire Mode: " + (item.getFireState(stack) ? (EnumColor.DARK_GREEN + "ON") : (EnumColor.DARK_RED + "OFF"))));
|
2013-03-31 00:13:59 +01:00
|
|
|
lastTickElectricBowChange = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastTickElectricBowChange = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumSet<TickType> ticks()
|
|
|
|
{
|
|
|
|
return EnumSet.of(TickType.PLAYER);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getLabel()
|
|
|
|
{
|
|
|
|
return "MekanismClientPlayer";
|
|
|
|
}
|
|
|
|
}
|