From 6849292fa373b481484fb81eb5e79124f839f10a Mon Sep 17 00:00:00 2001 From: c0repwn3r Date: Sat, 3 Dec 2022 19:12:39 -0500 Subject: [PATCH] [nofall][jetpack] rename flight to jetpack, create nofall --- .../dev/coredoes/clientmod/ClientMod.java | 9 +++- .../coredoes/clientmod/modmenu/ModMenu.java | 4 +- .../modules/{Flight.java => Jetpack.java} | 19 +++----- .../coredoes/clientmod/modules/NoFall.java | 47 ++++++++++++++++++- 4 files changed, 63 insertions(+), 16 deletions(-) rename src/main/java/dev/coredoes/clientmod/modules/{Flight.java => Jetpack.java} (86%) diff --git a/src/main/java/dev/coredoes/clientmod/ClientMod.java b/src/main/java/dev/coredoes/clientmod/ClientMod.java index 56b4e50..bcd4753 100644 --- a/src/main/java/dev/coredoes/clientmod/ClientMod.java +++ b/src/main/java/dev/coredoes/clientmod/ClientMod.java @@ -1,7 +1,8 @@ package dev.coredoes.clientmod; -import dev.coredoes.clientmod.modules.Flight; +import dev.coredoes.clientmod.modules.Jetpack; import dev.coredoes.clientmod.modules.ModuleManager; +import dev.coredoes.clientmod.modules.NoFall; import net.fabricmc.api.ModInitializer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,7 +18,11 @@ public class ClientMod implements ModInitializer { @Override public void onInitialize() { LOGGER.info("Loaded ClientMod; initializing modules"); - moduleManager.registerModule(new Flight()); + + moduleManager.registerModule(new Jetpack()); + moduleManager.registerModule(new NoFall()); + + LOGGER.info("Registered modules; registing 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 0241917..db4bf2b 100644 --- a/src/main/java/dev/coredoes/clientmod/modmenu/ModMenu.java +++ b/src/main/java/dev/coredoes/clientmod/modmenu/ModMenu.java @@ -26,6 +26,8 @@ public class ModMenu extends Screen { } protected void init() { + this.lastHeight = 0; + this.addDrawableChild(new ButtonWidget(5, this.height - 25, 40, 20, ScreenTexts.BACK, (button) -> { this.client.setScreen(this.parent); })); @@ -36,7 +38,7 @@ public class ModMenu extends Screen { this.addDrawableChild(new ButtonWidget(5, lastHeight + 5, 40, 20, Text.of(module.getId()), (button) -> { this.client.setScreen(moduleUI); })); - this.lastHeight += 5; + this.lastHeight += 25; } } } diff --git a/src/main/java/dev/coredoes/clientmod/modules/Flight.java b/src/main/java/dev/coredoes/clientmod/modules/Jetpack.java similarity index 86% rename from src/main/java/dev/coredoes/clientmod/modules/Flight.java rename to src/main/java/dev/coredoes/clientmod/modules/Jetpack.java index 14936df..00774cf 100644 --- a/src/main/java/dev/coredoes/clientmod/modules/Flight.java +++ b/src/main/java/dev/coredoes/clientmod/modules/Jetpack.java @@ -1,17 +1,14 @@ package dev.coredoes.clientmod.modules; -import dev.coredoes.clientmod.ClientMod; 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.entity.Entity; import net.minecraft.screen.ScreenTexts; import net.minecraft.text.Text; -import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; -public class Flight implements Module { +public class Jetpack implements Module { protected boolean isEnabled = false; protected boolean isVanillaBypassEnabled = true; @@ -24,8 +21,6 @@ public class Flight implements Module { public void startTick(MinecraftClient client) { Module.super.startTick(client); - ClientMod.LOGGER.info(String.valueOf(vanillaBypassTickCounter)); - if (!isEnabled) return; if (client.player != null) { @@ -59,7 +54,7 @@ public class Flight implements Module { @Override public String getId() { - return "Flight"; + return "Jetpack"; } @Override @@ -69,15 +64,15 @@ public class Flight implements Module { @Override public Screen getUI(Screen parent, GameOptions options) { - return new FlightUI(parent, options, this); + return new ModuleUI(parent, options, this); } - class FlightUI extends Screen { + class ModuleUI extends Screen { private final Screen parent; private final GameOptions settings; - private Flight parentModule; + private Jetpack parentModule; - public FlightUI(Screen parent, GameOptions gameOptions, Flight parentModule) { - super(Text.of("FlightModule")); + public ModuleUI(Screen parent, GameOptions gameOptions, Jetpack parentModule) { + super(Text.of("JetpackModule")); this.parent = parent; this.settings = gameOptions; this.parentModule = parentModule; diff --git a/src/main/java/dev/coredoes/clientmod/modules/NoFall.java b/src/main/java/dev/coredoes/clientmod/modules/NoFall.java index 2fa5fc1..c141e80 100644 --- a/src/main/java/dev/coredoes/clientmod/modules/NoFall.java +++ b/src/main/java/dev/coredoes/clientmod/modules/NoFall.java @@ -1,13 +1,34 @@ package dev.coredoes.clientmod.modules; +import dev.coredoes.clientmod.ClientMod; 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.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; public class NoFall implements Module { + protected boolean isEnabled; @Override public void startTick(MinecraftClient client) { Module.super.startTick(client); + + if (!isEnabled) return; + + if (client.player == null) return; + + // Have we fallen more than a couple blocks? + 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; + + // Need to cancel fall damage + client.player.networkHandler.sendPacket(new PlayerMoveC2SPacket.OnGroundOnly(true)); } @Override @@ -22,6 +43,30 @@ public class NoFall implements Module { @Override public Screen getUI(Screen parent, GameOptions options) { - return Module.super.getUI(parent, options); + return new ModuleUI(parent, options, this); + } + + class ModuleUI extends Screen { + private final Screen parent; + private final GameOptions settings; + private NoFall parentModule; + + public ModuleUI(Screen parent, GameOptions gameOptions, NoFall parentModule) { + super(Text.of("NoFallModule")); + 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, this.height - 25, 40, 20, ScreenTexts.BACK, (button) -> { + this.client.setScreen(this.parent); + })); + } } }