Skip to content

Commit

Permalink
Initialize toggle keybind when registering (#366)
Browse files Browse the repository at this point in the history
* Initialize toggle keybind when registering

* Add comment
  • Loading branch information
Caedis authored Mar 8, 2024
1 parent 22bf48c commit 14b7178
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ private HUDCaching() {}

private final List<Long> updateTimeList = new ArrayList<>(21);
private static boolean isEnabled = true;
private static final KeyBinding toggle = new KeyBinding("Toggle HUDCaching", 0, "Debug");

// moved initialization to when its registered to avoid an empty Debug category, which can cause crashes when
// opening the controls menu and hudcaching is disabled in the config
private static KeyBinding toggle;

public static void registerKeyBindings() {
toggle = new KeyBinding("Toggle HUDCaching", 0, "Debug");
ClientRegistry.registerKeyBinding(toggle);
}

Expand All @@ -86,7 +90,7 @@ public static void registerKeyBindings() {

@SubscribeEvent
public void onKeypress(InputEvent.KeyInputEvent event) {
if (toggle.isPressed()) {
if (toggle != null && toggle.isPressed()) {
isEnabled = !isEnabled;
final String msg = isEnabled ? "Enabled HUDCaching" : "Disabled HUDCaching";
if (mc.thePlayer != null) mc.thePlayer.addChatMessage(new ChatComponentText(msg));
Expand Down

0 comments on commit 14b7178

Please sign in to comment.