From fcded0f6be8569396510a94c05541ab43135e5d6 Mon Sep 17 00:00:00 2001 From: user32dll <96720131+user32dll@users.noreply.github.com> Date: Mon, 2 Oct 2023 09:10:32 +0200 Subject: [PATCH] Add keybind Adds a keybind to toggle the light level indicators --- build.gradle | 2 +- .../LightLevelIndicatorModClient.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 59bfcbd..c46f7c5 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { apply plugin: 'foxloader.dev' -version '0.1.0' +version '0.2.0' foxloader { // forceReload = true diff --git a/src/client/java/com/jellied/lightlevelindicator/LightLevelIndicatorModClient.java b/src/client/java/com/jellied/lightlevelindicator/LightLevelIndicatorModClient.java index e039ef1..3a0c30a 100644 --- a/src/client/java/com/jellied/lightlevelindicator/LightLevelIndicatorModClient.java +++ b/src/client/java/com/jellied/lightlevelindicator/LightLevelIndicatorModClient.java @@ -2,13 +2,32 @@ import com.fox2code.foxloader.loader.ClientMod; import com.fox2code.foxloader.registry.CommandCompat; +import net.minecraft.src.client.KeyBinding; +import com.fox2code.foxloader.client.KeyBindingAPI; +import net.minecraft.client.Minecraft; +import org.lwjgl.input.Keyboard; public class LightLevelIndicatorModClient extends LightLevelIndicatorMod implements ClientMod { + private static final KeyBinding toggleLightLevelIndicatorKeyBinding = new KeyBinding("Toggle Light Indicators", Keyboard.KEY_L); + private static boolean firstPress = true; + public void onTick() { + handleKeybind(); LightLevelIndicatorHandler.update(); } public void onInit() { + KeyBindingAPI.registerKeyBinding(toggleLightLevelIndicatorKeyBinding); CommandCompat.registerClientCommand(new ToggleCommand("toggleLightIndicators")); } + + private void handleKeybind() { + if (Keyboard.isKeyDown(toggleLightLevelIndicatorKeyBinding.keyCode) && firstPress) { + LightLevelIndicatorHandler.toggleIsEnabled(); + Minecraft.getInstance().thePlayer.displayChatMessage("Light Level Indicators: " + (LightLevelIndicatorHandler.getIsEnabled() ? "Enabled" : "Disabled")); + firstPress = false; + } else if (!Keyboard.isKeyDown(toggleLightLevelIndicatorKeyBinding.keyCode)) { + firstPress = true; + } + } }