Skip to content

Commit

Permalink
Add leg mode switch key and have it be able to change the speed of th…
Browse files Browse the repository at this point in the history
…e locomotive boosting unit
  • Loading branch information
pupnewfster committed Feb 14, 2021
1 parent 0fe7b00 commit ee70dbe
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/datagen/generated/mekanism/.cache/cache
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ d5bd6c407c9250a90e22e1f2c8805738b3830abf assets/mekanism/blockstates/lithium.jso
c1be0ed56a542f711719367cf1e508f10063c695 assets/mekanism/blockstates/sulfuric_acid.json
f5e3eb6799a15d0b72969547614dfc51dac53419 assets/mekanism/blockstates/tin_ore.json
246c1904e7699b01a3a20f2a2b79b35b5d99aec9 assets/mekanism/blockstates/uranium_ore.json
4d194c5c2052e42783ceb5f812ae1079182de671 assets/mekanism/lang/en_ud.json
7f080eb00cea13f433a20f5daf5256cedc111ef4 assets/mekanism/lang/en_us.json
009411ca4598901f6ccb75fe5d28974f5bf71f46 assets/mekanism/lang/en_ud.json
25b6427b030661da84867270326e3a9f11eb796e assets/mekanism/lang/en_us.json
beea3be5a8af802be66d456a7a648678bede0f02 assets/mekanism/models/block/brine.json
beea3be5a8af802be66d456a7a648678bede0f02 assets/mekanism/models/block/chlorine.json
beea3be5a8af802be66d456a7a648678bede0f02 assets/mekanism/models/block/ethene.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,7 @@
"key.mekanism.head_mode": "\u0265\u0254\u0287\u1D09\u028DS \u01DDpoW p\u0250\u01DDH",
"key.mekanism.key_boost": "\u0287soo\u15FA",
"key.mekanism.key_hud": "\u15E1\u2229H \u028Do\u0265S",
"key.mekanism.legs_mode": "\u0265\u0254\u0287\u1D09\u028DS \u01DDpoW s\u1D77\u01DD\uA780",
"key.mekanism.mode": "\u0265\u0254\u0287\u1D09\u028DS \u01DDpoW \u026F\u01DD\u0287I",
"key.mekanism.module_tweaker": "\u0279\u01DD\u029E\u0250\u01DD\u028D\u27D8 \u01DD\uA781npoW",
"laser_amplifier.mekanism.energy_contents": "s\u0287u\u01DD\u0287uo\u0186 \u028E\u1D77\u0279\u01DDu\u018E",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,7 @@
"key.mekanism.head_mode": "Head Mode Switch",
"key.mekanism.key_boost": "Boost",
"key.mekanism.key_hud": "Show HUD",
"key.mekanism.legs_mode": "Legs Mode Switch",
"key.mekanism.mode": "Item Mode Switch",
"key.mekanism.module_tweaker": "Module Tweaker",
"laser_amplifier.mekanism.energy_contents": "Energy Contents",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ private void addMisc() {
add(MekanismLang.KEY_HAND_MODE, "Item Mode Switch");
add(MekanismLang.KEY_HEAD_MODE, "Head Mode Switch");
add(MekanismLang.KEY_CHEST_MODE, "Chest Mode Switch");
add(MekanismLang.KEY_LEGS_MODE, "Legs Mode Switch");
add(MekanismLang.KEY_FEET_MODE, "Feet Mode Switch");
add(MekanismLang.KEY_DETAILS_MODE, "Show Details");
add(MekanismLang.KEY_DESCRIPTION_MODE, "Show Description");
Expand Down
30 changes: 17 additions & 13 deletions src/main/java/mekanism/client/MekanismKeyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class MekanismKeyHandler extends MekKeyHandler {
GLFW.GLFW_KEY_V, MekanismLang.MEKANISM.getTranslationKey());
public static final KeyBinding chestModeSwitchKey = new KeyBinding(MekanismLang.KEY_CHEST_MODE.getTranslationKey(), KeyConflictContext.IN_GAME, InputMappings.Type.KEYSYM,
GLFW.GLFW_KEY_G, MekanismLang.MEKANISM.getTranslationKey());
public static final KeyBinding legsModeSwitchKey = new KeyBinding(MekanismLang.KEY_LEGS_MODE.getTranslationKey(), KeyConflictContext.IN_GAME, InputMappings.Type.KEYSYM,
GLFW.GLFW_KEY_J, MekanismLang.MEKANISM.getTranslationKey());
public static final KeyBinding feetModeSwitchKey = new KeyBinding(MekanismLang.KEY_FEET_MODE.getTranslationKey(), KeyConflictContext.IN_GAME, InputMappings.Type.KEYSYM,
GLFW.GLFW_KEY_B, MekanismLang.MEKANISM.getTranslationKey());
public static final KeyBinding detailsKey = new KeyBinding(MekanismLang.KEY_DETAILS_MODE.getTranslationKey(), KeyConflictContext.GUI, InputMappings.Type.KEYSYM,
Expand All @@ -43,10 +45,11 @@ public class MekanismKeyHandler extends MekKeyHandler {
public static final KeyBinding hudKey = new KeyBinding(MekanismLang.KEY_HUD.getTranslationKey(), KeyConflictContext.IN_GAME, InputMappings.Type.KEYSYM,
GLFW.GLFW_KEY_H, MekanismLang.MEKANISM.getTranslationKey());

private static final Builder BINDINGS = new Builder(9)
private static final Builder BINDINGS = new Builder(10)
.addBinding(handModeSwitchKey, false)
.addBinding(headModeSwitchKey, false)
.addBinding(chestModeSwitchKey, false)
.addBinding(legsModeSwitchKey, false)
.addBinding(feetModeSwitchKey, false)
.addBinding(detailsKey, false)
.addBinding(descriptionKey, false)
Expand All @@ -59,6 +62,7 @@ public MekanismKeyHandler() {
ClientRegistry.registerKeyBinding(handModeSwitchKey);
ClientRegistry.registerKeyBinding(headModeSwitchKey);
ClientRegistry.registerKeyBinding(chestModeSwitchKey);
ClientRegistry.registerKeyBinding(legsModeSwitchKey);
ClientRegistry.registerKeyBinding(feetModeSwitchKey);
ClientRegistry.registerKeyBinding(detailsKey);
ClientRegistry.registerKeyBinding(descriptionKey);
Expand Down Expand Up @@ -86,20 +90,13 @@ public void keyDown(KeyBinding kb, boolean isRepeat) {
Mekanism.packetHandler.sendToServer(new PacketModeChange(EquipmentSlotType.OFFHAND, player.isSneaking()));
}
} else if (kb == headModeSwitchKey) {
if (IModeItem.isModeItem(player, EquipmentSlotType.HEAD)) {
Mekanism.packetHandler.sendToServer(new PacketModeChange(EquipmentSlotType.HEAD, player.isSneaking()));
SoundHandler.playSound(MekanismSounds.HYDRAULIC);
}
handlePotentialModeItem(player, EquipmentSlotType.HEAD);
} else if (kb == chestModeSwitchKey) {
if (IModeItem.isModeItem(player, EquipmentSlotType.CHEST)) {
Mekanism.packetHandler.sendToServer(new PacketModeChange(EquipmentSlotType.CHEST, player.isSneaking()));
SoundHandler.playSound(MekanismSounds.HYDRAULIC);
}
handlePotentialModeItem(player, EquipmentSlotType.CHEST);
} else if (kb == legsModeSwitchKey) {
handlePotentialModeItem(player, EquipmentSlotType.LEGS);
} else if (kb == feetModeSwitchKey) {
if (IModeItem.isModeItem(player, EquipmentSlotType.FEET)) {
Mekanism.packetHandler.sendToServer(new PacketModeChange(EquipmentSlotType.FEET, player.isSneaking()));
SoundHandler.playSound(MekanismSounds.HYDRAULIC);
}
handlePotentialModeItem(player, EquipmentSlotType.FEET);
} else if (kb == moduleTweakerKey) {
if (ModuleTweakerContainer.hasTweakableItem(player)) {
Mekanism.packetHandler.sendToServer(new PacketOpenGui(GuiType.MODULE_TWEAKER));
Expand All @@ -111,6 +108,13 @@ public void keyDown(KeyBinding kb, boolean isRepeat) {
}
}

private void handlePotentialModeItem(PlayerEntity player, EquipmentSlotType slot) {
if (IModeItem.isModeItem(player, slot)) {
Mekanism.packetHandler.sendToServer(new PacketModeChange(slot, player.isSneaking()));
SoundHandler.playSound(MekanismSounds.HYDRAULIC);
}
}

@Override
public void keyUp(KeyBinding kb) {
if (kb == boostKey) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/mekanism/common/MekanismLang.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public enum MekanismLang implements ILangEntry {
KEY_HAND_MODE("key", "mode"),
KEY_HEAD_MODE("key", "head_mode"),
KEY_CHEST_MODE("key", "chest_mode"),
KEY_LEGS_MODE("key", "legs_mode"),
KEY_FEET_MODE("key", "feet_mode"),
KEY_DETAILS_MODE("key", "details"),
KEY_DESCRIPTION_MODE("key", "description"),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mekanism/common/content/gear/Modules.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private Modules() {
// Pants
public static final ModuleData<ModuleLocomotiveBoostingUnit> LOCOMOTIVE_BOOSTING_UNIT = register("locomotive_boosting_unit",
MekanismLang.MODULE_LOCOMOTIVE_BOOSTING_UNIT, MekanismLang.DESCRIPTION_LOCOMOTIVE_BOOSTING_UNIT, ModuleLocomotiveBoostingUnit::new, 4)
.rarity(Rarity.RARE);
.rarity(Rarity.RARE).setHandlesModeChange();

// Boots
public static final ModuleData<ModuleHydraulicPropulsionUnit> HYDRAULIC_PROPULSION_UNIT = register("hydraulic_propulsion_unit",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package mekanism.common.content.gear.mekasuit;

import javax.annotation.Nonnull;
import mekanism.api.IIncrementalEnum;
import mekanism.api.math.FloatingLong;
import mekanism.api.math.MathUtils;
import mekanism.api.text.IHasTextComponent;
import mekanism.common.MekanismLang;
import mekanism.common.config.MekanismConfig;
import mekanism.common.content.gear.ModuleConfigItem;
import mekanism.common.content.gear.ModuleConfigItem.EnumData;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
Expand All @@ -21,6 +25,20 @@ public void init() {
addConfigItem(sprintBoost = new ModuleConfigItem<>(this, "sprint_boost", MekanismLang.MODULE_SPRINT_BOOST, new EnumData<>(SprintBoost.class, getInstalledCount() + 1), SprintBoost.LOW));
}

@Override
public void changeMode(@Nonnull PlayerEntity player, @Nonnull ItemStack stack, int shift, boolean displayChangeMessage) {
if (!isEnabled()) {
return;
}
SprintBoost newMode = sprintBoost.get().adjust(shift);
if (sprintBoost.get() != newMode) {
sprintBoost.set(newMode, null);
if (displayChangeMessage) {
displayModeChange(player, MekanismLang.MODULE_SPRINT_BOOST.translate(), newMode);
}
}
}

@Override
public void tickServer(PlayerEntity player) {
super.tickServer(player);
Expand Down Expand Up @@ -64,13 +82,15 @@ public float getBoost() {
return sprintBoost.get().getBoost();
}

public enum SprintBoost implements IHasTextComponent {
public enum SprintBoost implements IHasTextComponent, IIncrementalEnum<SprintBoost> {
OFF(0),
LOW(0.05F),
MED(0.1F),
HIGH(0.25F),
ULTRA(0.5F);

private static final SprintBoost[] MODES = values();

private final float boost;
private final ITextComponent label;

Expand All @@ -79,6 +99,12 @@ public enum SprintBoost implements IHasTextComponent {
this.label = new StringTextComponent(Float.toString(boost));
}

@Nonnull
@Override
public SprintBoost byIndex(int index) {
return MathUtils.getByIndexMod(MODES, index);
}

@Override
public ITextComponent getTextComponent() {
return label;
Expand Down

0 comments on commit ee70dbe

Please sign in to comment.