get ready for jetpack rewrite
This commit is contained in:
parent
6849292fa3
commit
2e20a54dfb
|
@ -1,13 +1,20 @@
|
||||||
package dev.coredoes.clientmod;
|
package dev.coredoes.clientmod;
|
||||||
|
|
||||||
|
import dev.coredoes.clientmod.modmenu.ModMenu;
|
||||||
import dev.coredoes.clientmod.modules.Jetpack;
|
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 dev.coredoes.clientmod.modules.NoFall;
|
||||||
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.api.ModInitializer;
|
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.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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.
|
// 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.
|
// 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.
|
// 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();
|
public static ModuleManager moduleManager = new ModuleManager();
|
||||||
|
|
||||||
|
private static KeyBinding modMenuKeyBinding;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitializeClient() {
|
||||||
LOGGER.info("Loaded ClientMod; initializing modules");
|
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 Jetpack());
|
||||||
moduleManager.registerModule(new NoFall());
|
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();
|
moduleManager.registerEvents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import net.minecraft.client.gui.Element;
|
||||||
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.client.option.KeyBinding;
|
||||||
import net.minecraft.screen.ScreenTexts;
|
import net.minecraft.screen.ScreenTexts;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ public class ModMenu extends Screen {
|
||||||
for (Module module : ClientMod.moduleManager.getModules().values()) {
|
for (Module module : ClientMod.moduleManager.getModules().values()) {
|
||||||
Screen moduleUI = module.getUI(this, this.settings);
|
Screen moduleUI = module.getUI(this, this.settings);
|
||||||
if (moduleUI != null) {
|
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.client.setScreen(moduleUI);
|
||||||
}));
|
}));
|
||||||
this.lastHeight += 25;
|
this.lastHeight += 25;
|
||||||
|
|
|
@ -1,12 +1,23 @@
|
||||||
package dev.coredoes.clientmod.modules;
|
package dev.coredoes.clientmod.modules;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||||
import net.minecraft.client.MinecraftClient;
|
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.Screen;
|
||||||
|
import net.minecraft.client.gui.screen.option.SimpleOptionsScreen;
|
||||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
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.GameOptions;
|
||||||
|
import net.minecraft.client.option.KeyBinding;
|
||||||
|
import net.minecraft.client.util.InputUtil;
|
||||||
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.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
|
||||||
public class Jetpack implements Module {
|
public class Jetpack implements Module {
|
||||||
|
|
||||||
|
@ -17,6 +28,34 @@ public class Jetpack implements Module {
|
||||||
protected int vanillaBypassTickResetCounter = 0;
|
protected int vanillaBypassTickResetCounter = 0;
|
||||||
protected final int vanillaBypassResetTimeout = 7;
|
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
|
@Override
|
||||||
public void startTick(MinecraftClient client) {
|
public void startTick(MinecraftClient client) {
|
||||||
Module.super.startTick(client);
|
Module.super.startTick(client);
|
||||||
|
@ -24,11 +63,17 @@ public class Jetpack implements Module {
|
||||||
if (!isEnabled) return;
|
if (!isEnabled) return;
|
||||||
|
|
||||||
if (client.player != null) {
|
if (client.player != null) {
|
||||||
if (vanillaBypassTickCounter > 60) {
|
if (vanillaBypassTickCounter > 75 && isVanillaBypassEnabled) {
|
||||||
Vec3d velocity = client.player.getVelocity();
|
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;
|
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) {
|
if (vanillaBypassTickCounter < 0 && isVanillaBypassEnabled) {
|
||||||
vanillaBypassTickCounter++;
|
vanillaBypassTickCounter++;
|
||||||
return;
|
return;
|
||||||
|
@ -39,7 +84,7 @@ public class Jetpack implements Module {
|
||||||
vanillaBypassTickCounter++;
|
vanillaBypassTickCounter++;
|
||||||
Vec3d velocity = client.player.getVelocity();
|
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 {
|
} else {
|
||||||
vanillaBypassTickResetCounter++;
|
vanillaBypassTickResetCounter++;
|
||||||
if (vanillaBypassTickResetCounter > vanillaBypassResetTimeout) {
|
if (vanillaBypassTickResetCounter > vanillaBypassResetTimeout) {
|
||||||
|
@ -71,6 +116,8 @@ public class Jetpack implements Module {
|
||||||
private final GameOptions settings;
|
private final GameOptions settings;
|
||||||
private Jetpack parentModule;
|
private Jetpack parentModule;
|
||||||
|
|
||||||
|
private ButtonWidget upwardsVelBtn;
|
||||||
|
|
||||||
public ModuleUI(Screen parent, GameOptions gameOptions, Jetpack parentModule) {
|
public ModuleUI(Screen parent, GameOptions gameOptions, Jetpack parentModule) {
|
||||||
super(Text.of("JetpackModule"));
|
super(Text.of("JetpackModule"));
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
@ -89,6 +136,29 @@ public class Jetpack implements Module {
|
||||||
button.setMessage(Text.of("Vanilla Bypass Enabled: " + (this.parentModule.isVanillaBypassEnabled ? "yes" : "no")));
|
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.addDrawableChild(new ButtonWidget(5, this.height - 25, 40, 20, ScreenTexts.BACK, (button) -> {
|
||||||
this.client.setScreen(this.parent);
|
this.client.setScreen(this.parent);
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -1,18 +1,47 @@
|
||||||
package dev.coredoes.clientmod.modules;
|
package dev.coredoes.clientmod.modules;
|
||||||
|
|
||||||
import dev.coredoes.clientmod.ClientMod;
|
import dev.coredoes.clientmod.ClientMod;
|
||||||
|
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||||
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.client.option.KeyBinding;
|
||||||
|
import net.minecraft.client.util.InputUtil;
|
||||||
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket;
|
||||||
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.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
public class NoFall implements Module {
|
public class NoFall implements Module {
|
||||||
protected boolean isEnabled;
|
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
|
@Override
|
||||||
public void startTick(MinecraftClient client) {
|
public void startTick(MinecraftClient client) {
|
||||||
Module.super.startTick(client);
|
Module.super.startTick(client);
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
"environment": "*",
|
"environment": "*",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"main": [
|
"client": [
|
||||||
"dev.coredoes.clientmod.ClientMod"
|
"dev.coredoes.clientmod.ClientMod"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -29,6 +29,7 @@
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.14.10",
|
"fabricloader": ">=0.14.10",
|
||||||
"fabric-api": "*",
|
"fabric-api": "*",
|
||||||
|
"fabric-key-binding-api-v1": "*",
|
||||||
"minecraft": "~1.19",
|
"minecraft": "~1.19",
|
||||||
"java": ">=17"
|
"java": ">=17"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue