diff --git a/src/main/java/dev/coredoes/clientmod/ClientMod.java b/src/main/java/dev/coredoes/clientmod/ClientMod.java index bcd4753..6a8b9f5 100644 --- a/src/main/java/dev/coredoes/clientmod/ClientMod.java +++ b/src/main/java/dev/coredoes/clientmod/ClientMod.java @@ -1,13 +1,20 @@ package dev.coredoes.clientmod; +import dev.coredoes.clientmod.modmenu.ModMenu; import dev.coredoes.clientmod.modules.Jetpack; import dev.coredoes.clientmod.modules.ModuleManager; import dev.coredoes.clientmod.modules.NoFall; +import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.minecraft.client.option.KeyBinding; +import net.minecraft.client.util.InputUtil; +import org.lwjgl.glfw.GLFW; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ClientMod implements ModInitializer { +public class ClientMod implements ClientModInitializer { // This logger is used to write text to the console and the log file. // It is considered best practice to use your mod id as the logger's name. // That way, it's clear which mod wrote info, warnings, and errors. @@ -15,14 +22,32 @@ public class ClientMod implements ModInitializer { public static ModuleManager moduleManager = new ModuleManager(); + private static KeyBinding modMenuKeyBinding; + @Override - public void onInitialize() { - LOGGER.info("Loaded ClientMod; initializing modules"); + public void onInitializeClient() { + LOGGER.info("Hello, world! ClientMod is loading up"); + + LOGGER.info("[Stage 1/3: ModMenuInit] Creating ModMenu keybinding"); + modMenuKeyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( + "key.clientmod.modmenu", + InputUtil.Type.KEYSYM, + GLFW.GLFW_KEY_GRAVE_ACCENT, + "category.clientmod.menues" + )); + + ClientTickEvents.END_CLIENT_TICK.register(client -> { + while (modMenuKeyBinding.wasPressed()) { + client.setScreen(new ModMenu(null, client.options)); + } + }); + + LOGGER.info("[Stage 2/3: ModuleInit] Registering modules"); moduleManager.registerModule(new Jetpack()); moduleManager.registerModule(new NoFall()); - LOGGER.info("Registered modules; registing module event system"); + LOGGER.info("[Stage 3/3: EventInit] Registered modules; registering module event system"); moduleManager.registerEvents(); } } diff --git a/src/main/java/dev/coredoes/clientmod/modmenu/ModMenu.java b/src/main/java/dev/coredoes/clientmod/modmenu/ModMenu.java index db4bf2b..dfeb4bd 100644 --- a/src/main/java/dev/coredoes/clientmod/modmenu/ModMenu.java +++ b/src/main/java/dev/coredoes/clientmod/modmenu/ModMenu.java @@ -7,6 +7,7 @@ import net.minecraft.client.gui.Element; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.option.GameOptions; +import net.minecraft.client.option.KeyBinding; import net.minecraft.screen.ScreenTexts; import net.minecraft.text.Text; @@ -35,7 +36,7 @@ public class ModMenu extends Screen { for (Module module : ClientMod.moduleManager.getModules().values()) { Screen moduleUI = module.getUI(this, this.settings); if (moduleUI != null) { - this.addDrawableChild(new ButtonWidget(5, lastHeight + 5, 40, 20, Text.of(module.getId()), (button) -> { + this.addDrawableChild(new ButtonWidget(5, lastHeight + 5, 70, 20, Text.of(module.getId()), (button) -> { this.client.setScreen(moduleUI); })); this.lastHeight += 25; diff --git a/src/main/java/dev/coredoes/clientmod/modules/Jetpack.java b/src/main/java/dev/coredoes/clientmod/modules/Jetpack.java index 00774cf..0a534a6 100644 --- a/src/main/java/dev/coredoes/clientmod/modules/Jetpack.java +++ b/src/main/java/dev/coredoes/clientmod/modules/Jetpack.java @@ -1,12 +1,23 @@ package dev.coredoes.clientmod.modules; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.Selectable; import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.option.SimpleOptionsScreen; import net.minecraft.client.gui.widget.ButtonWidget; +import net.minecraft.client.gui.widget.SliderWidget; +import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.option.GameOptions; +import net.minecraft.client.option.KeyBinding; +import net.minecraft.client.util.InputUtil; import net.minecraft.screen.ScreenTexts; import net.minecraft.text.Text; import net.minecraft.util.math.Vec3d; +import org.lwjgl.glfw.GLFW; + +import java.text.DecimalFormat; public class Jetpack implements Module { @@ -17,6 +28,34 @@ public class Jetpack implements Module { protected int vanillaBypassTickResetCounter = 0; protected final int vanillaBypassResetTimeout = 7; + private static KeyBinding toggleBinding; + + protected double upwardsVel = 0.1; + + protected double prevVelocity = 0; + + @Override + public void postRegister() { + Module.super.postRegister(); + + toggleBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( + "key.clientmod.jetpack", + InputUtil.Type.KEYSYM, + GLFW.GLFW_KEY_UNKNOWN, + "category.clientmod.modules" + )); + } + + @Override + public void endTick(MinecraftClient client) { + Module.super.endTick(client); + + while (toggleBinding.wasPressed()) { + client.player.sendMessage(Text.of(String.format("[%s] Toggled!", this.getId()))); + this.isEnabled = !this.isEnabled; + } + } + @Override public void startTick(MinecraftClient client) { Module.super.startTick(client); @@ -24,11 +63,17 @@ public class Jetpack implements Module { if (!isEnabled) return; if (client.player != null) { - if (vanillaBypassTickCounter > 60) { + if (vanillaBypassTickCounter > 75 && isVanillaBypassEnabled) { Vec3d velocity = client.player.getVelocity(); - client.player.setVelocity(new Vec3d(velocity.getX(), velocity.getY() - 0.4, velocity.getZ())); + this.prevVelocity = velocity.getY(); + client.player.setVelocity(new Vec3d(velocity.getX(), -1, velocity.getZ())); vanillaBypassTickCounter = -vanillaBypassResetTimeout; } + if (vanillaBypassTickCounter == 0) { + vanillaBypassTickCounter++; + Vec3d velocity = client.player.getVelocity(); + client.player.setVelocity(new Vec3d(velocity.getX(), this.prevVelocity, velocity.getZ())); + } if (vanillaBypassTickCounter < 0 && isVanillaBypassEnabled) { vanillaBypassTickCounter++; return; @@ -39,7 +84,7 @@ public class Jetpack implements Module { vanillaBypassTickCounter++; Vec3d velocity = client.player.getVelocity(); - client.player.setVelocity(new Vec3d(velocity.getX(), velocity.getY() + 0.1, velocity.getZ())); + client.player.setVelocity(new Vec3d(velocity.getX(), velocity.getY() + upwardsVel, velocity.getZ())); } else { vanillaBypassTickResetCounter++; if (vanillaBypassTickResetCounter > vanillaBypassResetTimeout) { @@ -71,6 +116,8 @@ public class Jetpack implements Module { private final GameOptions settings; private Jetpack parentModule; + private ButtonWidget upwardsVelBtn; + public ModuleUI(Screen parent, GameOptions gameOptions, Jetpack parentModule) { super(Text.of("JetpackModule")); this.parent = parent; @@ -89,6 +136,29 @@ public class Jetpack implements Module { button.setMessage(Text.of("Vanilla Bypass Enabled: " + (this.parentModule.isVanillaBypassEnabled ? "yes" : "no"))); })); + DecimalFormat df = new DecimalFormat("#.00"); + + this.addDrawableChild(new ButtonWidget(5, 55, 20, 20, Text.of("++"), (button) -> { + this.parentModule.upwardsVel += 0.1; + this.upwardsVelBtn.setMessage(Text.of("UpVel: " + df.format((this.parentModule.upwardsVel)))); + })); + this.addDrawableChild(new ButtonWidget(30, 55, 20, 20, Text.of("+"), (button) -> { + this.parentModule.upwardsVel += 0.01; + this.upwardsVelBtn.setMessage(Text.of("UpVel: " + df.format((this.parentModule.upwardsVel)))); + })); + + this.upwardsVelBtn = new ButtonWidget(55, 55, 70, 20, Text.of("UpVel: " + df.format((this.parentModule.upwardsVel))), (button) -> {}); + this.addDrawableChild(this.upwardsVelBtn); + + this.addDrawableChild(new ButtonWidget(130, 55, 20, 20, Text.of("-"), (button) -> { + this.parentModule.upwardsVel -= 0.01; + this.upwardsVelBtn.setMessage(Text.of("UpVel: " + df.format((this.parentModule.upwardsVel)))); + })); + this.addDrawableChild(new ButtonWidget(155, 55, 20, 20, Text.of("--"), (button) -> { + this.parentModule.upwardsVel -= 0.1; + this.upwardsVelBtn.setMessage(Text.of("UpVel: " + df.format((this.parentModule.upwardsVel)))); + })); + this.addDrawableChild(new ButtonWidget(5, this.height - 25, 40, 20, ScreenTexts.BACK, (button) -> { this.client.setScreen(this.parent); })); diff --git a/src/main/java/dev/coredoes/clientmod/modules/NoFall.java b/src/main/java/dev/coredoes/clientmod/modules/NoFall.java index c141e80..3607311 100644 --- a/src/main/java/dev/coredoes/clientmod/modules/NoFall.java +++ b/src/main/java/dev/coredoes/clientmod/modules/NoFall.java @@ -1,18 +1,47 @@ package dev.coredoes.clientmod.modules; import dev.coredoes.clientmod.ClientMod; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.option.GameOptions; +import net.minecraft.client.option.KeyBinding; +import net.minecraft.client.util.InputUtil; import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket; import net.minecraft.screen.ScreenTexts; import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; +import org.lwjgl.glfw.GLFW; public class NoFall implements Module { protected boolean isEnabled; + + private static KeyBinding toggleBinding; + + @Override + public void postRegister() { + Module.super.postRegister(); + + toggleBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( + "key.clientmod.nofall", + InputUtil.Type.KEYSYM, + GLFW.GLFW_KEY_UNKNOWN, + "category.clientmod.modules" + )); + } + + @Override + public void endTick(MinecraftClient client) { + Module.super.endTick(client); + + while (toggleBinding.wasPressed()) { + client.player.sendMessage(Text.of(String.format("[%s] Toggled!", this.getId()))); + this.isEnabled = !this.isEnabled; + } + } + @Override public void startTick(MinecraftClient client) { Module.super.startTick(client); diff --git a/src/main/resources/assets/coreclientmod/lang/en_us.json b/src/main/resources/assets/coreclientmod/lang/en_us.json new file mode 100644 index 0000000..dfb3b51 --- /dev/null +++ b/src/main/resources/assets/coreclientmod/lang/en_us.json @@ -0,0 +1,8 @@ +{ + "category.clientmod.menues": "ClientMod: Menues", + "key.clientmod.modmenu": "Toggle ModMenu", + + "category.clientmod.modules": "ClientMod: Modules", + "key.clientmod.jetpack": "Toggle Jetpack", + "key.clientmod.nofall": "Toggle NoFall" +} \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 3565f09..aeb5f45 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -18,7 +18,7 @@ "environment": "*", "entrypoints": { - "main": [ + "client": [ "dev.coredoes.clientmod.ClientMod" ] }, @@ -29,6 +29,7 @@ "depends": { "fabricloader": ">=0.14.10", "fabric-api": "*", + "fabric-key-binding-api-v1": "*", "minecraft": "~1.19", "java": ">=17" }