Sanify keybinds somewhat.
ClientTickHandler was getting way out of hand.
This commit is contained in:
parent
ec1c02d2e5
commit
54328ceb35
3 changed files with 120 additions and 152 deletions
|
@ -228,134 +228,6 @@ public class ClientTickHandler
|
|||
}
|
||||
}
|
||||
|
||||
ItemStack stack = mc.thePlayer.getCurrentEquippedItem();
|
||||
|
||||
if(mc.currentScreen == null)
|
||||
{
|
||||
if(mc.thePlayer.isSneaking() && StackUtils.getItem(mc.thePlayer.getCurrentEquippedItem()) instanceof ItemConfigurator)
|
||||
{
|
||||
ItemConfigurator item = (ItemConfigurator)mc.thePlayer.getCurrentEquippedItem().getItem();
|
||||
|
||||
if(MekanismKeyHandler.modeSwitchKey.getIsKeyPressed())
|
||||
{
|
||||
if(!lastTickUpdate)
|
||||
{
|
||||
item.setState(stack, (byte)(item.getState(stack) < 3 ? item.getState(stack)+1 : 0));
|
||||
Mekanism.packetHandler.sendToServer(new ConfiguratorStateMessage(item.getState(stack)));
|
||||
mc.thePlayer.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + MekanismUtils.localize("tooltip.configureState") + ": " + item.getColor(item.getState(stack)) + item.getStateDisplay(item.getState(stack))));
|
||||
lastTickUpdate = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastTickUpdate = false;
|
||||
}
|
||||
}
|
||||
else if(mc.thePlayer.isSneaking() && StackUtils.getItem(mc.thePlayer.getCurrentEquippedItem()) instanceof ItemElectricBow)
|
||||
{
|
||||
ItemElectricBow item = (ItemElectricBow)mc.thePlayer.getCurrentEquippedItem().getItem();
|
||||
|
||||
if(MekanismKeyHandler.modeSwitchKey.getIsKeyPressed())
|
||||
{
|
||||
if(!lastTickUpdate)
|
||||
{
|
||||
item.setFireState(stack, !item.getFireState(stack));
|
||||
Mekanism.packetHandler.sendToServer(new ElectricBowStateMessage(item.getFireState(stack)));
|
||||
mc.thePlayer.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + MekanismUtils.localize("tooltip.fireMode") + ": " + (item.getFireState(stack) ? EnumColor.DARK_GREEN : EnumColor.DARK_RED) + LangUtils.transYesNo(item.getFireState(stack))));
|
||||
lastTickUpdate = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastTickUpdate = false;
|
||||
}
|
||||
}
|
||||
else if(mc.thePlayer.isSneaking() && StackUtils.getItem(mc.thePlayer.getCurrentEquippedItem()) instanceof ItemBlockMachine)
|
||||
{
|
||||
ItemBlockMachine item = (ItemBlockMachine)mc.thePlayer.getCurrentEquippedItem().getItem();
|
||||
|
||||
if(MachineType.get(mc.thePlayer.getCurrentEquippedItem()) == MachineType.PORTABLE_TANK)
|
||||
{
|
||||
if(MekanismKeyHandler.modeSwitchKey.getIsKeyPressed())
|
||||
{
|
||||
if(!lastTickUpdate)
|
||||
{
|
||||
item.setBucketMode(stack, !item.getBucketMode(stack));
|
||||
Mekanism.packetHandler.sendToServer(new PortableTankStateMessage(item.getBucketMode(stack)));
|
||||
mc.thePlayer.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + MekanismUtils.localize("tooltip.portableTank.bucketMode") + ": " + (item.getBucketMode(stack) ? (EnumColor.DARK_GREEN + "ON") : (EnumColor.DARK_RED + "OFF"))));
|
||||
lastTickUpdate = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastTickUpdate = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(mc.thePlayer.isSneaking() && StackUtils.getItem(mc.thePlayer.getCurrentEquippedItem()) instanceof ItemWalkieTalkie)
|
||||
{
|
||||
ItemWalkieTalkie item = (ItemWalkieTalkie)mc.thePlayer.getCurrentEquippedItem().getItem();
|
||||
|
||||
if(MekanismKeyHandler.modeSwitchKey.getIsKeyPressed() && item.getOn(stack))
|
||||
{
|
||||
if(!lastTickUpdate)
|
||||
{
|
||||
int newChan = item.getChannel(stack) < 9 ? item.getChannel(stack)+1 : 1;
|
||||
item.setChannel(stack, newChan);
|
||||
Mekanism.packetHandler.sendToServer(new WalkieTalkieStateMessage(newChan));
|
||||
SoundHandler.playSound("mekanism:etc.Ding");
|
||||
lastTickUpdate = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastTickUpdate = false;
|
||||
}
|
||||
}
|
||||
else if(mc.thePlayer.getEquipmentInSlot(3) != null && mc.thePlayer.getEquipmentInSlot(3).getItem() instanceof ItemJetpack)
|
||||
{
|
||||
ItemStack jetpack = mc.thePlayer.getEquipmentInSlot(3);
|
||||
|
||||
if(MekanismKeyHandler.modeSwitchKey.getIsKeyPressed())
|
||||
{
|
||||
if(!lastTickUpdate)
|
||||
{
|
||||
if(mc.thePlayer.isSneaking())
|
||||
{
|
||||
((ItemJetpack)jetpack.getItem()).setMode(jetpack, JetpackMode.DISABLED);
|
||||
}
|
||||
else {
|
||||
((ItemJetpack)jetpack.getItem()).incrementMode(jetpack);
|
||||
}
|
||||
|
||||
Mekanism.packetHandler.sendToServer(new JetpackDataMessage(JetpackPacket.MODE, null, mc.thePlayer.isSneaking()));
|
||||
SoundHandler.playSound("mekanism:etc.Hydraulic");
|
||||
lastTickUpdate = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastTickUpdate = false;
|
||||
}
|
||||
}
|
||||
else if(mc.thePlayer.getEquipmentInSlot(3) != null && mc.thePlayer.getEquipmentInSlot(3).getItem() instanceof ItemScubaTank)
|
||||
{
|
||||
ItemStack scubaTank = mc.thePlayer.getEquipmentInSlot(3);
|
||||
|
||||
if(MekanismKeyHandler.modeSwitchKey.getIsKeyPressed())
|
||||
{
|
||||
if(!lastTickUpdate)
|
||||
{
|
||||
((ItemScubaTank)scubaTank.getItem()).toggleFlowing(scubaTank);
|
||||
Mekanism.packetHandler.sendToServer(new ScubaTankDataMessage(ScubaTankPacket.MODE, null, false));
|
||||
SoundHandler.playSound("mekanism:etc.Hydraulic");
|
||||
lastTickUpdate = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastTickUpdate = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lastTickUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(mc.thePlayer.getEquipmentInSlot(1) != null && mc.thePlayer.getEquipmentInSlot(1).getItem() instanceof ItemFreeRunners)
|
||||
{
|
||||
mc.thePlayer.stepHeight = 1.002F;
|
||||
|
|
|
@ -2,6 +2,8 @@ package mekanism.client;
|
|||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import mekanism.common.Mekanism;
|
||||
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
@ -23,8 +25,8 @@ public abstract class MekKeyHandler
|
|||
/**
|
||||
* Pass an array of keybindings and a repeat flag for each one
|
||||
*
|
||||
* @param keyBindings
|
||||
* @param repeatings
|
||||
* @param bindings
|
||||
* @param rep
|
||||
*/
|
||||
public MekKeyHandler(KeyBinding[] bindings, boolean[] rep)
|
||||
{
|
||||
|
@ -38,7 +40,7 @@ public abstract class MekKeyHandler
|
|||
* Register the keys into the system. You will do your own keyboard
|
||||
* management elsewhere. No events will fire if you use this method
|
||||
*
|
||||
* @param keyBindings
|
||||
* @param bindings
|
||||
*/
|
||||
public MekKeyHandler(KeyBinding[] bindings)
|
||||
{
|
||||
|
@ -56,14 +58,13 @@ public abstract class MekKeyHandler
|
|||
for(int i = 0; i < keyBindings.length; i++)
|
||||
{
|
||||
KeyBinding keyBinding = keyBindings[i];
|
||||
int keyCode = keyBinding.getKeyCode();
|
||||
boolean state = (keyCode < 0 ? Mouse.isButtonDown(keyCode + 100) : Keyboard.isKeyDown(keyCode));
|
||||
|
||||
boolean state = keyBinding.getIsKeyPressed();
|
||||
|
||||
if(state != keyDown[i] || (state && repeatings[i]))
|
||||
{
|
||||
if(state)
|
||||
{
|
||||
keyDown(type, keyBinding, tickEnd, state != keyDown[i]);
|
||||
keyDown(type, keyBinding, tickEnd, state == keyDown[i]);
|
||||
}
|
||||
else {
|
||||
keyUp(type, keyBinding, tickEnd);
|
||||
|
@ -78,11 +79,10 @@ public abstract class MekKeyHandler
|
|||
}
|
||||
|
||||
/**
|
||||
* Called when the key is first in the down position on any tick from the
|
||||
* {@link #ticks()} set. Will be called subsequently with isRepeat set to
|
||||
* true
|
||||
* Called when the key is first in the down position. Will be called
|
||||
* subsequently with isRepeat set to true
|
||||
*
|
||||
* @see #keyUp(EnumSet, KeyBinding, boolean)
|
||||
* @see #keyUp(Type, KeyBinding, boolean)
|
||||
*
|
||||
* @param types
|
||||
* the type(s) of tick that fired when this key was first down
|
||||
|
@ -96,7 +96,7 @@ public abstract class MekKeyHandler
|
|||
/**
|
||||
* Fired once when the key changes state from down to up
|
||||
*
|
||||
* @see #keyDown(EnumSet, KeyBinding, boolean, boolean)
|
||||
* @see #keyDown(Type, KeyBinding, boolean, boolean)
|
||||
*
|
||||
* @param types
|
||||
* the type(s) of tick that fired when this key was first down
|
||||
|
|
|
@ -1,15 +1,40 @@
|
|||
package mekanism.client;
|
||||
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.util.StackUtils;
|
||||
import mekanism.client.sound.SoundHandler;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.block.BlockMachine.MachineType;
|
||||
import mekanism.common.item.ItemBlockMachine;
|
||||
import mekanism.common.item.ItemConfigurator;
|
||||
import mekanism.common.item.ItemElectricBow;
|
||||
import mekanism.common.item.ItemJetpack;
|
||||
import mekanism.common.item.ItemJetpack.JetpackMode;
|
||||
import mekanism.common.item.ItemScubaTank;
|
||||
import mekanism.common.item.ItemWalkieTalkie;
|
||||
import mekanism.common.network.PacketConfiguratorState.ConfiguratorStateMessage;
|
||||
import mekanism.common.network.PacketElectricBowState.ElectricBowStateMessage;
|
||||
import mekanism.common.network.PacketJetpackData.JetpackDataMessage;
|
||||
import mekanism.common.network.PacketJetpackData.JetpackPacket;
|
||||
import mekanism.common.network.PacketPortableTankState.PortableTankStateMessage;
|
||||
import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage;
|
||||
import mekanism.common.network.PacketScubaTankData.ScubaTankPacket;
|
||||
import mekanism.common.network.PacketWalkieTalkieState.WalkieTalkieStateMessage;
|
||||
import mekanism.common.util.LangUtils;
|
||||
import mekanism.common.util.MekanismUtils;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import cpw.mods.fml.common.gameevent.InputEvent.KeyInputEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Type;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
@ -19,37 +44,108 @@ public class MekanismKeyHandler extends MekKeyHandler
|
|||
{
|
||||
public static final String keybindCategory = "Mekanism";
|
||||
public static KeyBinding modeSwitchKey = new KeyBinding("Mekanism " + MekanismUtils.localize("key.mode"), Keyboard.KEY_M, keybindCategory);
|
||||
public static KeyBinding armorModeSwitchKey = new KeyBinding("Mekanism " + MekanismUtils.localize("key.armorMode"), Keyboard.KEY_F, keybindCategory);
|
||||
public static KeyBinding voiceKey = new KeyBinding("Mekanism " + MekanismUtils.localize("key.voice"), Keyboard.KEY_U, keybindCategory);
|
||||
|
||||
public MekanismKeyHandler()
|
||||
{
|
||||
super(new KeyBinding[] {modeSwitchKey, voiceKey}, new boolean[] {false, false});
|
||||
super(new KeyBinding[] {modeSwitchKey, armorModeSwitchKey, voiceKey}, new boolean[] {false, false, true});
|
||||
|
||||
ClientRegistry.registerKeyBinding(modeSwitchKey);
|
||||
ClientRegistry.registerKeyBinding(armorModeSwitchKey);
|
||||
ClientRegistry.registerKeyBinding(voiceKey);
|
||||
|
||||
FMLCommonHandler.instance().bus().register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onTick(ClientTickEvent event)
|
||||
public void onTick(KeyInputEvent event)
|
||||
{
|
||||
if(event.side == Side.CLIENT)
|
||||
keyTick(Type.CLIENT, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyDown(Type types, KeyBinding kb, boolean tickEnd, boolean isRepeat)
|
||||
{
|
||||
Mekanism.logger.info(isRepeat ? "Repeating" : "Not Repeating");
|
||||
if(kb == modeSwitchKey)
|
||||
{
|
||||
if(event.phase == Phase.START)
|
||||
EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer;
|
||||
ItemStack toolStack = player.getCurrentEquippedItem();
|
||||
|
||||
Item item = StackUtils.getItem(toolStack);
|
||||
if(player.isSneaking() && item instanceof ItemConfigurator)
|
||||
{
|
||||
keyTick(event.type, false);
|
||||
ItemConfigurator configurator = (ItemConfigurator) item;
|
||||
|
||||
configurator.setState(toolStack, (byte) (configurator.getState(toolStack) < 3 ? configurator.getState(toolStack) + 1 : 0));
|
||||
Mekanism.packetHandler.sendToServer(new ConfiguratorStateMessage(configurator.getState(toolStack)));
|
||||
player.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + MekanismUtils.localize("tooltip.configureState") + ": " + configurator.getColor(configurator.getState(toolStack)) + configurator.getStateDisplay(configurator.getState(toolStack))));
|
||||
}
|
||||
else if(event.phase == Phase.END)
|
||||
else if(player.isSneaking() && item instanceof ItemElectricBow)
|
||||
{
|
||||
keyTick(event.type, true);
|
||||
ItemElectricBow bow = (ItemElectricBow) item;
|
||||
|
||||
bow.setFireState(toolStack, !bow.getFireState(toolStack));
|
||||
Mekanism.packetHandler.sendToServer(new ElectricBowStateMessage(bow.getFireState(toolStack)));
|
||||
player.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + MekanismUtils.localize("tooltip.fireMode") + ": " + (bow.getFireState(toolStack) ? EnumColor.DARK_GREEN : EnumColor.DARK_RED) + LangUtils.transYesNo(bow.getFireState(toolStack))));
|
||||
}
|
||||
else if(player.isSneaking() && item instanceof ItemBlockMachine)
|
||||
{
|
||||
ItemBlockMachine machine = (ItemBlockMachine) item;
|
||||
|
||||
if(MachineType.get(toolStack) == MachineType.PORTABLE_TANK)
|
||||
{
|
||||
machine.setBucketMode(toolStack, !machine.getBucketMode(toolStack));
|
||||
Mekanism.packetHandler.sendToServer(new PortableTankStateMessage(machine.getBucketMode(toolStack)));
|
||||
player.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + MekanismUtils.localize("tooltip.portableTank.bucketMode") + ": " + (machine.getBucketMode(toolStack) ? (EnumColor.DARK_GREEN + "ON") : (EnumColor.DARK_RED + "OFF"))));
|
||||
}
|
||||
}
|
||||
else if(player.isSneaking() && item instanceof ItemWalkieTalkie)
|
||||
{
|
||||
ItemWalkieTalkie wt = (ItemWalkieTalkie) item;
|
||||
|
||||
if(wt.getOn(toolStack))
|
||||
{
|
||||
int newChan = wt.getChannel(toolStack) < 9 ? wt.getChannel(toolStack) + 1 : 1;
|
||||
wt.setChannel(toolStack, newChan);
|
||||
Mekanism.packetHandler.sendToServer(new WalkieTalkieStateMessage(newChan));
|
||||
SoundHandler.playSound("mekanism:etc.Ding");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(kb == armorModeSwitchKey)
|
||||
{
|
||||
EntityPlayer player = FMLClientHandler.instance().getClient().thePlayer;
|
||||
ItemStack chestStack = player.getCurrentArmor(2);
|
||||
Item chestItem = StackUtils.getItem(chestStack);
|
||||
|
||||
if(chestItem instanceof ItemJetpack)
|
||||
{
|
||||
ItemJetpack jetpack = (ItemJetpack)chestItem;
|
||||
|
||||
if(player.isSneaking())
|
||||
{
|
||||
jetpack.setMode(chestStack, JetpackMode.DISABLED);
|
||||
}
|
||||
else {
|
||||
jetpack.incrementMode(chestStack);
|
||||
}
|
||||
|
||||
Mekanism.packetHandler.sendToServer(new JetpackDataMessage(JetpackPacket.MODE, null, player.isSneaking()));
|
||||
SoundHandler.playSound("mekanism:etc.Hydraulic");
|
||||
}
|
||||
else if(chestItem instanceof ItemScubaTank)
|
||||
{
|
||||
ItemScubaTank scubaTank = (ItemScubaTank)chestItem;
|
||||
|
||||
scubaTank.toggleFlowing(chestStack);
|
||||
Mekanism.packetHandler.sendToServer(new ScubaTankDataMessage(ScubaTankPacket.MODE, null, false));
|
||||
SoundHandler.playSound("mekanism:etc.Hydraulic");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyDown(Type types, KeyBinding kb, boolean tickEnd, boolean isRepeat) {}
|
||||
|
||||
@Override
|
||||
public void keyUp(Type types, KeyBinding kb, boolean tickEnd) {}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue