[nofall][jetpack] rename flight to jetpack, create nofall

This commit is contained in:
c0repwn3r 2022-12-03 19:12:39 -05:00
parent 52e9cd679b
commit 6849292fa3
Signed by: core
GPG Key ID: FDBF740DADDCEECF
4 changed files with 63 additions and 16 deletions

View File

@ -1,7 +1,8 @@
package dev.coredoes.clientmod; 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.ModuleManager;
import dev.coredoes.clientmod.modules.NoFall;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -17,7 +18,11 @@ public class ClientMod implements ModInitializer {
@Override @Override
public void onInitialize() { public void onInitialize() {
LOGGER.info("Loaded ClientMod; initializing modules"); 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(); moduleManager.registerEvents();
} }
} }

View File

@ -26,6 +26,8 @@ public class ModMenu extends Screen {
} }
protected void init() { protected void init() {
this.lastHeight = 0;
this.addDrawableChild(new ButtonWidget(5, this.height - 25, 40, 20, ScreenTexts.BACK, (button) -> { this.addDrawableChild(new ButtonWidget(5, this.height - 25, 40, 20, ScreenTexts.BACK, (button) -> {
this.client.setScreen(this.parent); 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.addDrawableChild(new ButtonWidget(5, lastHeight + 5, 40, 20, Text.of(module.getId()), (button) -> {
this.client.setScreen(moduleUI); this.client.setScreen(moduleUI);
})); }));
this.lastHeight += 5; this.lastHeight += 25;
} }
} }
} }

View File

@ -1,17 +1,14 @@
package dev.coredoes.clientmod.modules; package dev.coredoes.clientmod.modules;
import dev.coredoes.clientmod.ClientMod;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.option.GameOptions; import net.minecraft.client.option.GameOptions;
import net.minecraft.entity.Entity;
import net.minecraft.screen.ScreenTexts; import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
public class Flight implements Module { public class Jetpack implements Module {
protected boolean isEnabled = false; protected boolean isEnabled = false;
protected boolean isVanillaBypassEnabled = true; protected boolean isVanillaBypassEnabled = true;
@ -24,8 +21,6 @@ public class Flight implements Module {
public void startTick(MinecraftClient client) { public void startTick(MinecraftClient client) {
Module.super.startTick(client); Module.super.startTick(client);
ClientMod.LOGGER.info(String.valueOf(vanillaBypassTickCounter));
if (!isEnabled) return; if (!isEnabled) return;
if (client.player != null) { if (client.player != null) {
@ -59,7 +54,7 @@ public class Flight implements Module {
@Override @Override
public String getId() { public String getId() {
return "Flight"; return "Jetpack";
} }
@Override @Override
@ -69,15 +64,15 @@ public class Flight implements Module {
@Override @Override
public Screen getUI(Screen parent, GameOptions options) { 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 Screen parent;
private final GameOptions settings; private final GameOptions settings;
private Flight parentModule; private Jetpack parentModule;
public FlightUI(Screen parent, GameOptions gameOptions, Flight parentModule) { public ModuleUI(Screen parent, GameOptions gameOptions, Jetpack parentModule) {
super(Text.of("FlightModule")); super(Text.of("JetpackModule"));
this.parent = parent; this.parent = parent;
this.settings = gameOptions; this.settings = gameOptions;
this.parentModule = parentModule; this.parentModule = parentModule;

View File

@ -1,13 +1,34 @@
package dev.coredoes.clientmod.modules; package dev.coredoes.clientmod.modules;
import dev.coredoes.clientmod.ClientMod;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen; 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.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 { public class NoFall implements Module {
protected boolean isEnabled;
@Override @Override
public void startTick(MinecraftClient client) { public void startTick(MinecraftClient client) {
Module.super.startTick(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 @Override
@ -22,6 +43,30 @@ public class NoFall implements Module {
@Override @Override
public Screen getUI(Screen parent, GameOptions options) { 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);
}));
}
} }
} }