mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 14:52:58 +00:00
Keybindings optimisations (#5389)
* Shift keybinds to a builder pattern to avoid the array length issue, use Bitsets for the boolean arrays, remove unused and redundant constructor * Use proper lang keys for KeyBinding creation instead of pre-localising * WIP tidy keyhandler tick method * more key handler tidying * tweak handler to use translation placeholders so languages can reconfigure the foo: bar display * add todo * move tank, bow & flamethrower keys to use string format placeholders * fix NPE on configurator changes * nullable annotations * prefix keybind lang keys with modid * make datafixers into their own thing * make a datafixer base class * remove keybind fixer, options datafixers dont work * Revert "remove keybind fixer, options datafixers dont work" This reverts commit c57f6c1b05ed6b26e7fb7774bada4ca53f6c655e. * datafix the keybinds to the new format * documentation * Remove unused import and extra dash from runClient args
This commit is contained in:
1 parent
b570ef7110
commit
31b06c0ab0
39 files changed
+572
-248
No files matched your search
@@ -1,7 +1,6 @@
|
||||
package mekanism.client;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import mekanism.api.EnumColor;
|
||||
import java.util.Collections;
|
||||
import mekanism.client.sound.SoundHandler;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.MekanismSounds;
|
||||
@@ -16,12 +15,15 @@ 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.PacketFlamethrowerData;
|
||||
import mekanism.common.network.PacketFlamethrowerData.FlamethrowerDataMessage;
|
||||
import mekanism.common.network.PacketFlamethrowerData.FlamethrowerPacket;
|
||||
import mekanism.common.network.PacketFreeRunnerData;
|
||||
import mekanism.common.network.PacketFreeRunnerData.FreeRunnerDataMessage;
|
||||
import mekanism.common.network.PacketItemStack.ItemStackMessage;
|
||||
import mekanism.common.network.PacketJetpackData.JetpackDataMessage;
|
||||
import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage;
|
||||
import mekanism.common.util.LangUtils;
|
||||
import mekanism.common.util.TextComponentGroup;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -29,7 +31,7 @@ import net.minecraft.inventory.EntityEquipmentSlot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||
@@ -43,20 +45,23 @@ import org.lwjgl.input.Keyboard;
|
||||
public class MekanismKeyHandler extends MekKeyHandler {
|
||||
|
||||
public static final String keybindCategory = Mekanism.MOD_NAME;
|
||||
public static KeyBinding modeSwitchKey = new KeyBinding("Mekanism " + LangUtils.localize("key.mode"),
|
||||
Keyboard.KEY_M, keybindCategory);
|
||||
public static KeyBinding armorModeSwitchKey = new KeyBinding("Mekanism " + LangUtils.localize("key.armorMode"),
|
||||
Keyboard.KEY_G, keybindCategory);
|
||||
public static KeyBinding voiceKey = new KeyBinding("Mekanism " + LangUtils.localize("key.voice"), Keyboard.KEY_U,
|
||||
keybindCategory);
|
||||
public static KeyBinding freeRunnerModeSwitchKey = new KeyBinding("Mekanism " + LangUtils.localize("key.feetMode"),
|
||||
Keyboard.KEY_H, keybindCategory);
|
||||
public static KeyBinding modeSwitchKey = new KeyBinding("mekanism.key.mode", Keyboard.KEY_M, keybindCategory);
|
||||
public static KeyBinding armorModeSwitchKey = new KeyBinding("mekanism.key.armorMode", Keyboard.KEY_G, keybindCategory);
|
||||
public static KeyBinding freeRunnerModeSwitchKey = new KeyBinding("mekanism.key.feetMode", Keyboard.KEY_H, keybindCategory);
|
||||
public static KeyBinding voiceKey = new KeyBinding("mekanism.key.voice", Keyboard.KEY_U, keybindCategory);
|
||||
|
||||
public static KeyBinding sneakKey = Minecraft.getMinecraft().gameSettings.keyBindSneak;
|
||||
public static KeyBinding jumpKey = Minecraft.getMinecraft().gameSettings.keyBindJump;
|
||||
|
||||
private static Builder BINDINGS = new Builder()
|
||||
.addBinding(modeSwitchKey, false)
|
||||
.addBinding(armorModeSwitchKey, false)
|
||||
.addBinding(freeRunnerModeSwitchKey, false)
|
||||
.addBinding(voiceKey, true)
|
||||
;
|
||||
|
||||
public MekanismKeyHandler() {
|
||||
super(new KeyBinding[]{modeSwitchKey, armorModeSwitchKey, freeRunnerModeSwitchKey, voiceKey},
|
||||
new boolean[]{false, false, false, true});
|
||||
super(BINDINGS);
|
||||
|
||||
ClientRegistry.registerKeyBinding(modeSwitchKey);
|
||||
ClientRegistry.registerKeyBinding(armorModeSwitchKey);
|
||||
@@ -82,60 +87,63 @@ public class MekanismKeyHandler extends MekKeyHandler {
|
||||
if (player.isSneaking() && item instanceof ItemConfigurator) {
|
||||
ItemConfigurator configurator = (ItemConfigurator) item;
|
||||
|
||||
int toSet = configurator.getState(toolStack).ordinal() < ConfiguratorMode.values().length - 1 ?
|
||||
configurator.getState(toolStack).ordinal() + 1 : 0;
|
||||
configurator.setState(toolStack, ConfiguratorMode.values()[toSet]);
|
||||
Mekanism.packetHandler
|
||||
.sendToServer(new ItemStackMessage(EnumHand.MAIN_HAND, Lists.newArrayList(toSet)));
|
||||
player.sendMessage(new TextComponentString(
|
||||
EnumColor.DARK_BLUE + Mekanism.LOG_TAG + " " + EnumColor.GREY + LangUtils
|
||||
.localize("tooltip.configureState") + ": " + configurator
|
||||
.getColor(configurator.getState(toolStack)) + configurator
|
||||
.getStateDisplay(configurator.getState(toolStack))));
|
||||
ConfiguratorMode configuratorMode = configurator.getState(toolStack);
|
||||
int toSet = (configuratorMode.ordinal() + 1) % ConfiguratorMode.values().length;
|
||||
configuratorMode = ConfiguratorMode.values()[toSet];
|
||||
configurator.setState(toolStack, configuratorMode);
|
||||
|
||||
Mekanism.packetHandler.sendToServer(new ItemStackMessage(EnumHand.MAIN_HAND, Collections.singletonList(toSet)));
|
||||
|
||||
player.sendMessage(
|
||||
new TextComponentGroup(TextFormatting.GRAY)
|
||||
.string(Mekanism.LOG_TAG, TextFormatting.DARK_BLUE).string(" ")
|
||||
.translation("mekanism.tooltip.configureState", LangUtils.withColor(configuratorMode.getNameComponent(), configuratorMode.getColor().textFormatting))
|
||||
);
|
||||
} else if (player.isSneaking() && item instanceof ItemElectricBow) {
|
||||
ItemElectricBow bow = (ItemElectricBow) item;
|
||||
|
||||
bow.setFireState(toolStack, !bow.getFireState(toolStack));
|
||||
Mekanism.packetHandler.sendToServer(
|
||||
new ItemStackMessage(EnumHand.MAIN_HAND, Lists.newArrayList(bow.getFireState(toolStack))));
|
||||
player.sendMessage(new TextComponentString(
|
||||
EnumColor.DARK_BLUE + Mekanism.LOG_TAG + " " + EnumColor.GREY + LangUtils
|
||||
.localize("tooltip.fireMode")
|
||||
+ ": " + (bow.getFireState(toolStack) ? EnumColor.DARK_GREEN : EnumColor.DARK_RED)
|
||||
+ LangUtils.transOnOff(bow.getFireState(toolStack))));
|
||||
boolean newBowState = !bow.getFireState(toolStack);
|
||||
bow.setFireState(toolStack, newBowState);
|
||||
Mekanism.packetHandler.sendToServer(new ItemStackMessage(EnumHand.MAIN_HAND, Collections.singletonList(newBowState)));
|
||||
player.sendMessage(
|
||||
new TextComponentGroup(TextFormatting.GRAY)
|
||||
.string(Mekanism.LOG_TAG, TextFormatting.DARK_BLUE).string(" ")
|
||||
.translation("mekanism.tooltip.fireMode", LangUtils.onOffColoured(newBowState))
|
||||
);
|
||||
} else if (player.isSneaking() && item instanceof ItemBlockMachine) {
|
||||
ItemBlockMachine machine = (ItemBlockMachine) item;
|
||||
|
||||
if (MachineType.get(toolStack) == MachineType.FLUID_TANK) {
|
||||
machine.setBucketMode(toolStack, !machine.getBucketMode(toolStack));
|
||||
Mekanism.packetHandler.sendToServer(new ItemStackMessage(EnumHand.MAIN_HAND,
|
||||
Lists.newArrayList(machine.getBucketMode(toolStack))));
|
||||
player.sendMessage(new TextComponentString(
|
||||
EnumColor.DARK_BLUE + Mekanism.LOG_TAG + " " + EnumColor.GREY + LangUtils
|
||||
.localize("tooltip.portableTank.bucketMode") + ": " + (machine.getBucketMode(toolStack)
|
||||
? EnumColor.DARK_GREEN : EnumColor.DARK_RED) + LangUtils
|
||||
.transOnOff(machine.getBucketMode(toolStack))));
|
||||
boolean newBucketMode = !machine.getBucketMode(toolStack);
|
||||
machine.setBucketMode(toolStack, newBucketMode);
|
||||
Mekanism.packetHandler.sendToServer(new ItemStackMessage(EnumHand.MAIN_HAND, Collections.singletonList(machine.getBucketMode(toolStack))));
|
||||
player.sendMessage(
|
||||
new TextComponentGroup(TextFormatting.GRAY)
|
||||
.string(Mekanism.LOG_TAG, TextFormatting.DARK_BLUE).string(" ")
|
||||
.translation("mekanism.tooltip.portableTank.bucketMode", LangUtils.onOffColoured(newBucketMode))
|
||||
);
|
||||
}
|
||||
} 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;
|
||||
int newChan = wt.getChannel(toolStack) + 1;
|
||||
if (newChan == 9) {
|
||||
newChan = 1;
|
||||
}
|
||||
wt.setChannel(toolStack, newChan);
|
||||
Mekanism.packetHandler
|
||||
.sendToServer(new ItemStackMessage(EnumHand.MAIN_HAND, Lists.newArrayList(newChan)));
|
||||
Mekanism.packetHandler.sendToServer(new ItemStackMessage(EnumHand.MAIN_HAND, Collections.singletonList(newChan)));
|
||||
}
|
||||
} else if (player.isSneaking() && item instanceof ItemFlamethrower) {
|
||||
ItemFlamethrower flamethrower = (ItemFlamethrower) item;
|
||||
|
||||
flamethrower.incrementMode(toolStack);
|
||||
Mekanism.packetHandler.sendToServer(
|
||||
new PacketFlamethrowerData.FlamethrowerDataMessage(PacketFlamethrowerData.FlamethrowerPacket.MODE,
|
||||
EnumHand.MAIN_HAND, null, false));
|
||||
player.sendMessage(new TextComponentString(
|
||||
EnumColor.DARK_BLUE + Mekanism.LOG_TAG + " " + EnumColor.GREY + LangUtils
|
||||
.localize("tooltip.flamethrower.modeBump") + ": " + flamethrower.getMode(toolStack)
|
||||
.getName()));
|
||||
Mekanism.packetHandler.sendToServer(new FlamethrowerDataMessage(FlamethrowerPacket.MODE, EnumHand.MAIN_HAND, null, false));
|
||||
player.sendMessage(
|
||||
new TextComponentGroup(TextFormatting.GRAY)
|
||||
.string(Mekanism.LOG_TAG, TextFormatting.DARK_BLUE).string(" ")
|
||||
.translation("mekanism.tooltip.flamethrower.modeBump", flamethrower.getMode(toolStack).getTextComponent())
|
||||
);
|
||||
}
|
||||
} else if (kb == armorModeSwitchKey) {
|
||||
EntityPlayer player = FMLClientHandler.instance().getClient().player;
|
||||
@@ -174,9 +182,7 @@ public class MekanismKeyHandler extends MekKeyHandler {
|
||||
freeRunners.incrementMode(feetStack);
|
||||
}
|
||||
|
||||
Mekanism.packetHandler.sendToServer(
|
||||
new PacketFreeRunnerData.FreeRunnerDataMessage(PacketFreeRunnerData.FreeRunnerPacket.MODE, null,
|
||||
player.isSneaking()));
|
||||
Mekanism.packetHandler.sendToServer(new FreeRunnerDataMessage(PacketFreeRunnerData.FreeRunnerPacket.MODE, null, player.isSneaking()));
|
||||
SoundHandler.playSound(MekanismSounds.HYDRAULIC);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user