diff --git a/common/src/main/java/com/seibel/lod/common/wrappers/config/LodConfigWrapperSingleton.java b/common/src/main/java/com/seibel/lod/common/wrappers/config/LodConfigWrapperSingleton.java index ad2957411..90a412b27 100644 --- a/common/src/main/java/com/seibel/lod/common/wrappers/config/LodConfigWrapperSingleton.java +++ b/common/src/main/java/com/seibel/lod/common/wrappers/config/LodConfigWrapperSingleton.java @@ -475,7 +475,7 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton @Override public boolean getDrawLods() { - return Config.Client.Advanced.Debugging.drawLods; + return (boolean) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.drawLods").value; } @Override public void setDrawLods(boolean newDrawLods) @@ -488,7 +488,7 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton @Override public DebugMode getDebugMode() { - return Config.Client.Advanced.Debugging.debugMode; + return (DebugMode) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.debugMode").value; } @Override public void setDebugMode(DebugMode newDebugMode) @@ -501,7 +501,7 @@ public class LodConfigWrapperSingleton implements ILodConfigWrapperSingleton @Override public boolean getDebugKeybindingsEnabled() { - return Config.Client.Advanced.Debugging.enableDebugKeybindings; + return (boolean) ConfigGui.editSingleOption.getEntry("client.advanced.debugging.enableDebugKeybindings").value; } @Override public void setDebugKeybindingsEnabled(boolean newEnableDebugKeybindings) diff --git a/core b/core index 09b2d952b..31717ad20 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 09b2d952b62295b716514f212330ba625ac3929a +Subproject commit 31717ad2020d909a685c298b8456a72459161ba5 diff --git a/fabric/src/main/java/com/seibel/lod/fabric/ClientProxy.java b/fabric/src/main/java/com/seibel/lod/fabric/ClientProxy.java index cb5416461..e83e82791 100644 --- a/fabric/src/main/java/com/seibel/lod/fabric/ClientProxy.java +++ b/fabric/src/main/java/com/seibel/lod/fabric/ClientProxy.java @@ -21,6 +21,7 @@ package com.seibel.lod.fabric; import com.seibel.lod.core.api.ClientApi; import com.seibel.lod.core.api.EventApi; +import com.mojang.blaze3d.platform.InputConstants; import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; import com.seibel.lod.common.wrappers.world.DimensionTypeWrapper; import com.seibel.lod.common.wrappers.world.WorldWrapper; @@ -34,11 +35,16 @@ import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents; import net.minecraft.client.KeyMapping; +import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.chunk.LevelChunk; + +import java.util.HashSet; +import java.util.List; + import org.lwjgl.glfw.GLFW; /** @@ -146,31 +152,40 @@ public class ClientProxy // recreate the LOD where the blocks were changed eventApi.blockChangeEvent(chunk, dimType); } - - - - // The debug mode keybinding, which will be registered - public static final KeyMapping DebugToggle = KeyBindingHelper.registerKeyBinding( - new KeyMapping("key.lod.DebugToggle", GLFW.GLFW_KEY_F8, "key.lod.category")); - - // The draw toggle keybinding, which will be registered - public static final KeyMapping DrawToggle = KeyBindingHelper.registerKeyBinding( - new KeyMapping("key.lod.DrawToggle", GLFW.GLFW_KEY_F6, "key.lod.category")); - - boolean PreDebugToggle = false; - boolean PreDrawToggle = false; + + private static final List KEY_TO_CHECK_FOR = List.of(GLFW.GLFW_KEY_F6, GLFW.GLFW_KEY_F8); + + HashSet previousKeyDown = new HashSet(); + public void onKeyInput() { ILodConfigWrapperSingleton CONFIG = SingletonHandler.get(ILodConfigWrapperSingleton.class); if (CONFIG.client().advanced().debugging().getDebugKeybindingsEnabled()) { - // Only activates when you press the key - if (DebugToggle.isDown() && DebugToggle.isDown() != PreDebugToggle) - CONFIG.client().advanced().debugging().setDebugMode(CONFIG.client().advanced().debugging().getDebugMode().getNext()); - - if (DrawToggle.isDown() && DrawToggle.isDown() != PreDebugToggle) - CONFIG.client().advanced().debugging().setDrawLods(!CONFIG.client().advanced().debugging().getDrawLods()); + HashSet currectKeyDown = new HashSet(); + + // Note: Minecraft's InputConstants is same as GLFW Key values + //TODO: Use mixin to hook directly into the GLFW Keyboard event in minecraft KeyboardHandler + // Check all keys we need + for (int i = InputConstants.KEY_A; i <= InputConstants.KEY_Z; i++) { + if (InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), i)) { + currectKeyDown.add(i); + } + } + for (int i : KEY_TO_CHECK_FOR) { + if (InputConstants.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), i)) { + currectKeyDown.add(i); + } + } + + // Diff and trigger events + for (int c : currectKeyDown) { + if (!previousKeyDown.contains(c)) { + ClientApi.INSTANCE.keyPressedEvent(c); + } + } + + // Update the set + previousKeyDown = currectKeyDown; } - PreDebugToggle = DebugToggle.isDown(); - PreDrawToggle = DrawToggle.isDown(); } } diff --git a/forge/src/main/java/com/seibel/lod/forge/ForgeClientProxy.java b/forge/src/main/java/com/seibel/lod/forge/ForgeClientProxy.java index 4e2aa4dc3..a2f345853 100644 --- a/forge/src/main/java/com/seibel/lod/forge/ForgeClientProxy.java +++ b/forge/src/main/java/com/seibel/lod/forge/ForgeClientProxy.java @@ -22,10 +22,14 @@ package com.seibel.lod.forge; import com.seibel.lod.core.api.ClientApi; import com.seibel.lod.core.api.EventApi; import com.seibel.lod.core.wrapperInterfaces.chunk.IChunkWrapper; + +import org.lwjgl.glfw.GLFW; + import com.seibel.lod.common.wrappers.chunk.ChunkWrapper; import com.seibel.lod.common.wrappers.world.DimensionTypeWrapper; import com.seibel.lod.common.wrappers.world.WorldWrapper; +import net.minecraft.client.Minecraft; import net.minecraftforge.client.event.InputEvent; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.world.BlockEvent; @@ -102,7 +106,9 @@ public class ForgeClientProxy @SubscribeEvent public void onKeyInput(InputEvent.KeyInputEvent event) { - eventApi.onKeyInput(event.getKey(), event.getAction()); + if (Minecraft.getInstance().player == null) return; + if (event.getAction() != GLFW.GLFW_PRESS) return; + clientApi.keyPressedEvent(event.getKey()); }