diff --git a/src/main/java/io/github/simplycmd/quake/AntiGhost.java b/src/main/java/io/github/simplycmd/quake/AntiGhost.java index 1c8b614..018b72b 100644 --- a/src/main/java/io/github/simplycmd/quake/AntiGhost.java +++ b/src/main/java/io/github/simplycmd/quake/AntiGhost.java @@ -1,34 +1,41 @@ package io.github.simplycmd.quake; +import org.lwjgl.glfw.GLFW; + import net.fabricmc.api.ClientModInitializer; -import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; -import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.fabricmc.fabric.api.event.client.ClientTickCallback; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.options.GameOptions; +import net.minecraft.client.options.KeyBinding; import net.minecraft.client.util.InputUtil; import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket; import net.minecraft.text.TranslatableText; -import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; -import static org.lwjgl.glfw.GLFW.GLFW_KEY_G; public class AntiGhost implements ClientModInitializer { - static FabricKeyBinding requestBlocks; - //static KeyBinding requestBlock; + private KeyBinding requestBlocks; @Override public void onInitializeClient() { - final String category="key.categories.quake"; - KeyBindingRegistry.INSTANCE.addCategory(category); - KeyBindingRegistry.INSTANCE.register(requestBlocks = FabricKeyBinding.Builder - .create(new Identifier("quake:reveal"), InputUtil.Type.KEYSYM, - GLFW_KEY_G, category) - .build()); + SetupKeybinds(); + } + + private void SetupKeybinds() { + requestBlocks = new KeyBinding( + "key.quake.reveal", + InputUtil.Type.KEYSYM, + GLFW.GLFW_KEY_G, + "key.categories.quake" + ); + + KeyBindingHelper.registerKeyBinding(requestBlocks); + ClientTickCallback.EVENT.register(e->keyPressed()); } diff --git a/src/main/java/io/github/simplycmd/quake/Fullbright.java b/src/main/java/io/github/simplycmd/quake/Fullbright.java index b8075c3..4ec3c0c 100644 --- a/src/main/java/io/github/simplycmd/quake/Fullbright.java +++ b/src/main/java/io/github/simplycmd/quake/Fullbright.java @@ -20,7 +20,7 @@ public class Fullbright implements ClientModInitializer { private boolean maxBrightToggled = false; private double prevBrightness; private boolean prevPressed; - private KeyBinding brightnessBind; + private KeyBinding fullbrightKey; @Override @@ -32,14 +32,14 @@ public void onInitializeClient() { private void SetupKeybinds() { // Create the max brightness toggle - brightnessBind = new KeyBinding( + fullbrightKey = new KeyBinding( "key.quake.fullbright", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_B, "key.categories.quake" ); - KeyBindingHelper.registerKeyBinding(brightnessBind); + KeyBindingHelper.registerKeyBinding(fullbrightKey); // Callback that toggles brightness between set value and maximum ClientTickCallback.EVENT.register(e -> { @@ -49,7 +49,7 @@ private void SetupKeybinds() { gameOptions = client.options; } - if (brightnessBind.isPressed()) { + if (fullbrightKey.isPressed()) { if (!prevPressed) { if (!maxBrightToggled) { prevBrightness = gameOptions.gamma; diff --git a/src/main/java/io/github/simplycmd/quake/Toggle.java b/src/main/java/io/github/simplycmd/quake/Toggle.java new file mode 100644 index 0000000..5879f70 --- /dev/null +++ b/src/main/java/io/github/simplycmd/quake/Toggle.java @@ -0,0 +1,69 @@ +package io.github.simplycmd.quake; + +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; +import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.fabricmc.fabric.api.event.client.ClientTickCallback; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.client.options.KeyBinding; +import net.minecraft.client.util.InputUtil; +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; +import net.minecraft.util.Identifier; +import org.lwjgl.glfw.GLFW; +import net.minecraft.text.LiteralText; + +public class Toggle implements ClientModInitializer { + private KeyBinding toggleSprint; + private KeyBinding toggleSneak; + + @Override + public void onInitializeClient() { + SetupKeybinds(); + } + + private void SetupKeybinds() { + toggleSprint = new KeyBinding( + "key.quake.sprint", + InputUtil.Type.KEYSYM, + GLFW.GLFW_KEY_RIGHT_CONTROL, + "key.categories.quake" + ); + toggleSneak = new KeyBinding( + "key.quake.sneak", + InputUtil.Type.KEYSYM, + GLFW.GLFW_KEY_RIGHT_SHIFT, + "key.categories.quake" + ); + + KeyBindingHelper.registerKeyBinding(toggleSprint); + KeyBindingHelper.registerKeyBinding(toggleSneak); + + ClientTickCallback.EVENT.register(e->keyPressed()); + } + + public void keyPressed() { + MinecraftClient client = MinecraftClient.getInstance(); + if (toggleSprint.wasPressed()) { + if(client.options.sprintToggled == true) { + client.player.sendMessage(new TranslatableText("msg.sprinthold"), false); + client.options.sprintToggled = false; + } else { + client.player.sendMessage(new TranslatableText("msg.sprinttoggle"), false); + client.options.sprintToggled = true; + } + } + if (toggleSneak.wasPressed()) { + if(client.options.sneakToggled == true) { + client.player.sendMessage(new TranslatableText("msg.sneakhold"), false); + client.options.sneakToggled = false; + } else { + client.player.sendMessage(new TranslatableText("msg.sneaktoggle"), false); + client.options.sneakToggled = true; + } + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quake/lang/en_us.json b/src/main/resources/assets/quake/lang/en_us.json index 96eab7a..79609e6 100644 --- a/src/main/resources/assets/quake/lang/en_us.json +++ b/src/main/resources/assets/quake/lang/en_us.json @@ -4,5 +4,12 @@ "key.quake.reveal": "Reveal Ghost Blocks", "msg.request": "Revealing glitched blocks (Don't spam this or else you will get kicked!)", - "key.quake.fullbright": "Toggle Fullbright" + "key.quake.fullbright": "Toggle Fullbright", + + "key.quake.sprint": "Toggle Sprint", + "key.quake.sneak": "Toggle Sneak", + "msg.sprinthold": "Changed sprint mode to HOLD. (This will take effect in a few seconds)", + "msg.sprinttoggle": "Changed sprint mode to TOGGLE. (This will take effect in a few seconds)", + "msg.sneakhold": "Changed sneak mode to HOLD. (This will take effect in a few seconds)", + "msg.sneaktoggle": "Changed sneak mode to TOGGLE. (This will take effect in a few seconds)" } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 087b700..c9482fd 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -19,7 +19,7 @@ "main": [ "io.github.simplycmd.quake.Quake" ], - "client": ["io.github.simplycmd.quake.AntiGhost","io.github.simplycmd.quake.Fullbright"], + "client": ["io.github.simplycmd.quake.AntiGhost","io.github.simplycmd.quake.Fullbright","io.github.simplycmd.quake.Toggle"], "server": [] }, "mixins": [