diff --git a/src/main/java/dev/coredoes/clientmod/ClientMod.java b/src/main/java/dev/coredoes/clientmod/ClientMod.java index af04bd3..2a1aee7 100644 --- a/src/main/java/dev/coredoes/clientmod/ClientMod.java +++ b/src/main/java/dev/coredoes/clientmod/ClientMod.java @@ -2,11 +2,11 @@ package dev.coredoes.clientmod; import dev.coredoes.clientmod.hud.HudManager; import dev.coredoes.clientmod.modmenu.ModMenu; +import dev.coredoes.clientmod.modules.CreativeFlight; 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; @@ -48,6 +48,7 @@ public class ClientMod implements ClientModInitializer { moduleManager.registerModule(new Jetpack()); moduleManager.registerModule(new NoFall()); + moduleManager.registerModule(new CreativeFlight()); LOGGER.info("[Stage 3/3: EventInit] Registered modules; registering module event system"); moduleManager.registerEvents(); diff --git a/src/main/java/dev/coredoes/clientmod/modules/CreativeFlight.java b/src/main/java/dev/coredoes/clientmod/modules/CreativeFlight.java new file mode 100644 index 0000000..82c3a46 --- /dev/null +++ b/src/main/java/dev/coredoes/clientmod/modules/CreativeFlight.java @@ -0,0 +1,172 @@ +package dev.coredoes.clientmod.modules; + +import dev.coredoes.clientmod.ClientMod; +import dev.coredoes.clientmod.hud.HudColor; +import dev.coredoes.clientmod.hud.HudMessage; +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.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.entity.player.PlayerAbilities; +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 CreativeFlight implements Module { + + protected boolean isEnabled = false; + protected boolean isVanillaBypassEnabled = true; + + protected boolean doOnDisable = false; + + protected int tickCounter = 0; + + private static KeyBinding toggleBinding; + + @Override + public void postRegister() { + Module.super.postRegister(); + + toggleBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( + "key.clientmod.creativeflight", + InputUtil.Type.KEYSYM, + GLFW.GLFW_KEY_UNKNOWN, + "category.clientmod.modules" + )); + } + + @Override + public void endTick(MinecraftClient client) { + Module.super.endTick(client); + + while (toggleBinding.wasPressed()) { + this.isEnabled = !this.isEnabled; + } + } + + @Override + public void disable() { + this.isEnabled = false; + doOnDisable = true; + } + + @Override + public void enable() { + this.isEnabled = true; + tickCounter = 0; + ClientMod.moduleManager.getModuleById("jetpack").disable(); + ClientMod.moduleManager.getModuleById("nofall").disable(); + } + + @Override + public void startTick(MinecraftClient client) { + Module.super.startTick(client); + + tickCounter += 1; + + if (client.player != null) { + if (this.isEnabled) { + ClientMod.hudManager.setMesssage("CreativeFlight", new HudMessage(String.format("CreativeFlight: Enabled (VanillaBypass %s)", (this.isVanillaBypassEnabled) ? "on" : "off"), HudColor.Green)); + + client.player.getAbilities().allowFlying = true; + + if (isVanillaBypassEnabled && client.player.getAbilities().flying) { + vanillaBypass(client); + } + } else { + ClientMod.hudManager.clearMessage("CreativeFlight"); + + if (doOnDisable) { + doOnDisable = false; + PlayerAbilities abilities = client.player.getAbilities(); + boolean is_creative = client.player.isCreative(); + + abilities.flying = is_creative && !client.player.isOnGround(); + abilities.allowFlying = is_creative; + + client.options.jumpKey.setPressed(false); + client.options.sneakKey.setPressed(false); + } + } + } + } + + private void vanillaBypass(MinecraftClient client) { + if (tickCounter > 60 + 2) { + tickCounter = 0; + } + + if (tickCounter == 0) { + if (client.options.sneakKey.isPressed() && !client.options.jumpKey.isPressed()) { + tickCounter = 3; + } else { + setYVel(client, -0.032); + } + } else if (tickCounter == 1) { + setYVel(client, 0.032); + } else if (tickCounter == 2) { + setYVel(client, 0); + } else if (tickCounter == 3) { + client.options.jumpKey.setPressed(false); + client.options.sneakKey.setPressed(false); + } + } + + private void setYVel(MinecraftClient client, double yvel) { + client.options.sneakKey.setPressed(false); + client.options.jumpKey.setPressed(false); + Vec3d old_vel = client.player.getVelocity(); + client.player.setVelocity(old_vel.x, yvel, old_vel.z); + } + + @Override + public String getId() { + return "CreativeFlight"; + } + + @Override + public String getVersion() { + return "1.0.0"; + } + + @Override + public Screen getUI(Screen parent, GameOptions options) { + return new ModuleUI(parent, options, this); + } + class ModuleUI extends Screen { + private final Screen parent; + private final GameOptions settings; + private CreativeFlight parentModule; + + public ModuleUI(Screen parent, GameOptions gameOptions, CreativeFlight parentModule) { + super(Text.of("CreativeFlightModule")); + this.parent = parent; + this.settings = gameOptions; + this.parentModule = parentModule; + } + + protected void init() { + this.addDrawableChild(new ButtonWidget(5, 5, 70, 20, Text.of("Enabled: " + (this.parentModule.isEnabled ? "yes" : "no")), (button) -> { + this.parentModule.isEnabled = !this.parentModule.isEnabled; + button.setMessage(Text.of("Enabled: " + (this.parentModule.isEnabled ? "yes" : "no"))); + })); + + this.addDrawableChild(new ButtonWidget(5, 30, 170, 20, Text.of("Vanilla Bypass Enabled: " + (this.parentModule.isVanillaBypassEnabled ? "yes" : "no")), (button) -> { + this.parentModule.isVanillaBypassEnabled = !this.parentModule.isVanillaBypassEnabled; + button.setMessage(Text.of("Vanilla Bypass Enabled: " + (this.parentModule.isVanillaBypassEnabled ? "yes" : "no"))); + })); + + 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/Jetpack.java b/src/main/java/dev/coredoes/clientmod/modules/Jetpack.java index c4883db..789cc24 100644 --- a/src/main/java/dev/coredoes/clientmod/modules/Jetpack.java +++ b/src/main/java/dev/coredoes/clientmod/modules/Jetpack.java @@ -219,4 +219,16 @@ public class Jetpack implements Module { })); } } + + @Override + public void disable() { + this.isEnabled = false; + } + + @Override + public void enable() { + this.isEnabled = true; + ClientMod.moduleManager.getModuleById("creativeflight").disable(); + ClientMod.moduleManager.getModuleById("nofall").disable(); + } } diff --git a/src/main/java/dev/coredoes/clientmod/modules/Module.java b/src/main/java/dev/coredoes/clientmod/modules/Module.java index 94e44bd..6661b62 100644 --- a/src/main/java/dev/coredoes/clientmod/modules/Module.java +++ b/src/main/java/dev/coredoes/clientmod/modules/Module.java @@ -19,6 +19,9 @@ public interface Module { default void startTick(MinecraftClient client) {} default void endTick(MinecraftClient client) {} + default void disable() {} + default void enable() {} + // Manager stuff String getId(); String getVersion(); diff --git a/src/main/java/dev/coredoes/clientmod/modules/NoFall.java b/src/main/java/dev/coredoes/clientmod/modules/NoFall.java index 7a02354..53e6dac 100644 --- a/src/main/java/dev/coredoes/clientmod/modules/NoFall.java +++ b/src/main/java/dev/coredoes/clientmod/modules/NoFall.java @@ -61,7 +61,7 @@ public class NoFall implements Module { if (client.player.fallDistance <= (client.player.isFallFlying() ? 1 : 2)) return; // Can we even take fall damage right now? - if (client.player.isFallFlying() && client.player.isSneaking() && client.player.getVelocity().getY() >= -0.5) return; + if (client.player.isFallFlying() && client.player.isSneaking() && client.player.getVelocity().getY() >= -0.4) return; // Need to cancel fall damage client.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(true)); @@ -77,6 +77,18 @@ public class NoFall implements Module { return "1.0.0"; } + @Override + public void disable() { + this.isEnabled = false; + } + + @Override + public void enable() { + this.isEnabled = true; + ClientMod.moduleManager.getModuleById("jetpack").disable(); + ClientMod.moduleManager.getModuleById("creativeflight").disable(); + } + @Override public Screen getUI(Screen parent, GameOptions options) { return new ModuleUI(parent, options, this); diff --git a/src/main/resources/assets/coreclientmod/lang/en_us.json b/src/main/resources/assets/coreclientmod/lang/en_us.json index dfb3b51..709fe6c 100644 --- a/src/main/resources/assets/coreclientmod/lang/en_us.json +++ b/src/main/resources/assets/coreclientmod/lang/en_us.json @@ -1,8 +1,9 @@ { "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" + + "key.clientmod.modmenu": "Toggle ModMenu", + "key.clientmod.jetpack": "Toggle Jetpack", + "key.clientmod.nofall": "Toggle NoFall", + "key.clientmod.creativeflight": "Toggle CreativeFlight" } \ No newline at end of file