Skip to content

Commit

Permalink
Make hud keybinding persist hud render state through game restarts #7765
Browse files Browse the repository at this point in the history
  • Loading branch information
pupnewfster committed Apr 7, 2023
1 parent 25f57f0 commit f92b48a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/main/java/mekanism/client/MekanismClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ private MekanismClient() {

public static final Map<UUID, SecurityData> clientSecurityMap = new Object2ObjectOpenHashMap<>();
public static final Map<UUID, String> clientUUIDMap = new Object2ObjectOpenHashMap<>();
public static boolean renderHUD = true;

public static long ticksPassed = 0;

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/mekanism/client/key/MekanismKeyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mekanism.common.Mekanism;
import mekanism.common.MekanismLang;
import mekanism.common.base.KeySync;
import mekanism.common.config.MekanismConfig;
import mekanism.common.integration.curios.CuriosIntegration;
import mekanism.common.inventory.container.ModuleTweakerContainer;
import mekanism.common.item.interfaces.IGasItem;
Expand Down Expand Up @@ -59,7 +60,11 @@ public class MekanismKeyHandler {
public static final KeyMapping boostKey = new MekKeyBindingBuilder().description(MekanismLang.KEY_BOOST).conflictInGame().keyCode(GLFW.GLFW_KEY_LEFT_CONTROL)
.onKeyDown((kb, isRepeat) -> MekanismClient.updateKey(kb, KeySync.BOOST)).onKeyUp(kb -> MekanismClient.updateKey(kb, KeySync.BOOST)).build();
public static final KeyMapping hudKey = new MekKeyBindingBuilder().description(MekanismLang.KEY_HUD).conflictInGame().keyCode(GLFW.GLFW_KEY_H)
.onKeyDown((kb, isRepeat) -> MekanismClient.renderHUD = !MekanismClient.renderHUD).build();
.onKeyDown((kb, isRepeat) -> {
MekanismConfig.client.enableHUD.set(!MekanismConfig.client.enableHUD.get());
// save the updated config info
MekanismConfig.client.save();
}).build();

public static void registerKeybindings(RegisterKeyMappingsEvent event) {
ClientRegistrationUtil.registerKeyBindings(event, handModeSwitchKey, headModeSwitchKey, chestModeSwitchKey, legsModeSwitchKey, feetModeSwitchKey,
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/mekanism/client/render/hud/MekanismHUD.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import mekanism.client.MekanismClient;
import mekanism.client.render.HUDRenderer;
import mekanism.common.Mekanism;
import mekanism.common.config.MekanismConfig;
Expand All @@ -31,7 +30,7 @@ public class MekanismHUD implements IGuiOverlay {
@Override
public void render(ForgeGui gui, PoseStack poseStack, float partialTicks, int screenWidth, int screenHeight) {
Minecraft minecraft = Minecraft.getInstance();
if (!minecraft.options.hideGui && !minecraft.player.isSpectator() && MekanismConfig.client.enableHUD.get() && MekanismClient.renderHUD) {
if (!minecraft.options.hideGui && !minecraft.player.isSpectator() && MekanismConfig.client.enableHUD.get()) {
int count = 0;
List<List<Component>> renderStrings = new ArrayList<>();
for (EquipmentSlot slotType : EQUIPMENT_ORDER) {
Expand Down

0 comments on commit f92b48a

Please sign in to comment.