diff options
| author | Arslaan Pathan <[email protected]> | 2025-10-04 15:58:03 +1300 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2025-10-04 15:58:03 +1300 |
| commit | b28f0b7bb0cd10fc3318cd24709c22430aa16270 (patch) | |
| tree | 07c33ae8c984d2285e6dc15568ef76668347a52f /src/main/java/net/justlearning/arslaan3102/arslaansmagichax/commands | |
| parent | b03b9a7014f49b763abd02e91d99be68b48b6c07 (diff) | |
| download | arslaansmagichax-b28f0b7bb0cd10fc3318cd24709c22430aa16270.tar.xz arslaansmagichax-b28f0b7bb0cd10fc3318cd24709c22430aa16270.zip | |
lot of shit
Diffstat (limited to 'src/main/java/net/justlearning/arslaan3102/arslaansmagichax/commands')
3 files changed, 125 insertions, 20 deletions
diff --git a/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/commands/HackTP.java b/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/commands/HackTP.java index f794e4c..5185f20 100644 --- a/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/commands/HackTP.java +++ b/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/commands/HackTP.java @@ -2,6 +2,7 @@ package net.justlearning.arslaan3102.arslaansmagichax.commands; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; @@ -21,6 +22,7 @@ import java.util.Queue; public class HackTP { private static final Queue<double[]> stepQueue = new LinkedList<>(); + private static int packetsPerTick = 5; public static BlockPos findClosestAirNearPosition(int x, int y, int z) { World world = MinecraftClient.getInstance().world; @@ -42,12 +44,33 @@ public class HackTP { return null; } + private static int computeSafePacketsPerTick(int requestedSpeed) { + final int STEP_HORIZ = 2; + final double SAFE_HORIZ = 8.5; // server maximum horizontal move + + int allowed = (int) Math.floor(SAFE_HORIZ / STEP_HORIZ); + if (allowed < 1) allowed = 1; + + return Math.max(1, Math.min(requestedSpeed, allowed)); + } + + private static double parseCoordinate(String arg, double current) { + if (arg.startsWith("c")) { + if (arg.length() == 1) return current; + return current + Double.parseDouble(arg.substring(1)); + } else { + return Double.parseDouble(arg); + } + } + public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess access) { dispatcher.register(ClientCommandManager.literal("hacktp") - .then(ClientCommandManager.argument("x", IntegerArgumentType.integer()) - .then(ClientCommandManager.argument("y", IntegerArgumentType.integer()) - .then(ClientCommandManager.argument("z", IntegerArgumentType.integer()) - .executes(HackTP::run) + .then(ClientCommandManager.argument("x", StringArgumentType.word()) + .then(ClientCommandManager.argument("y", StringArgumentType.word()) + .then(ClientCommandManager.argument("z", StringArgumentType.word()) + .then(ClientCommandManager.argument("speed", IntegerArgumentType.integer(0, 25)) + .executes(HackTP::run) + ) ) ) ) @@ -68,28 +91,25 @@ public class HackTP { // }); ClientTickEvents.END_CLIENT_TICK.register(client -> { if (!stepQueue.isEmpty() && client.player != null) { - int packetsPerTick = 5; // how many packets you want per tick for (int i = 0; i < packetsPerTick && !stepQueue.isEmpty(); i++) { double[] pos = stepQueue.poll(); - client.getNetworkHandler().sendPacket( - new PlayerMoveC2SPacket.PositionAndOnGround( - pos[0], pos[1], pos[2], true, client.player.horizontalCollision - ) - ); +// client.getNetworkHandler().sendPacket( +// new PlayerMoveC2SPacket.PositionAndOnGround( +// pos[0], pos[1], pos[2], true, client.player.horizontalCollision +// ) +// ); client.player.setPos(pos[0], pos[1], pos[2]); - client.player.sendMessage(Text.literal("Teleported to " + pos[0] + " " + pos[1] + " " + pos[2]), false); + client.player.sendMessage(Text.literal("Teleported to " + pos[0] + " " + pos[1] + " " + pos[2] + " with packetsPerTick/speed " + packetsPerTick), false); } } }); } private static int run(CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException { - int targetX = IntegerArgumentType.getInteger(context, "x"); - int targetY = IntegerArgumentType.getInteger(context, "y"); - int targetZ = IntegerArgumentType.getInteger(context, "z"); + int speed = IntegerArgumentType.getInteger(context, "speed"); ClientPlayerEntity player = context.getSource().getPlayer(); if (player == null) { @@ -101,10 +121,29 @@ public class HackTP { double currentY = player.getY(); double currentZ = player.getZ(); - int stepX = (targetX > currentX) ? 5 : -5; + String xArg = context.getArgument("x", String.class); + String yArg = context.getArgument("y", String.class); + String zArg = context.getArgument("z", String.class); + + double targetX = parseCoordinate(xArg, currentX); + double targetY = parseCoordinate(yArg, currentY); + double targetZ = parseCoordinate(zArg, currentZ); + + if (speed < 1) { + packetsPerTick = computeSafePacketsPerTick(packetsPerTick); + } else { + packetsPerTick = computeSafePacketsPerTick(speed); + } + + context.getSource().sendFeedback(Text.literal("Using " + packetsPerTick + " packets/tick (requested " + speed + ")")); + + int stepX = (targetX > currentX) ? 2 : -2; int stepY = (targetY > currentY) ? 2 : -2; - int stepZ = (targetZ > currentZ) ? 5 : -5; + int stepZ = (targetZ > currentZ) ? 2 : -2; + for (int i = 1; i <= 8; i++) { + stepQueue.add(new double[]{currentX, currentY, currentZ}); // I don't know how this works but it makes Y more reliable (go through more blocks on the Y axis?) + } while ((stepY > 0 && currentY < targetY) || (stepY < 0 && currentY > targetY)) { currentY += stepY; if ((stepY > 0 && currentY > targetY) || (stepY < 0 && currentY < targetY)) currentY = targetY; @@ -140,10 +179,6 @@ public class HackTP { )); } - context.getSource().sendFeedback(Text.literal( - "Queued teleport to " + targetX + " " + targetY + " " + targetZ - )); - return 1; } } diff --git a/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/commands/ModuleSuggestionProvider.java b/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/commands/ModuleSuggestionProvider.java new file mode 100644 index 0000000..71a0d2b --- /dev/null +++ b/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/commands/ModuleSuggestionProvider.java @@ -0,0 +1,26 @@ +package net.justlearning.arslaan3102.arslaansmagichax.commands; + +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import com.mojang.brigadier.suggestion.SuggestionProvider; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.justlearning.arslaan3102.arslaansmagichax.modules.Module; +import net.justlearning.arslaan3102.arslaansmagichax.modules.ModuleManager; + +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class ModuleSuggestionProvider implements SuggestionProvider<FabricClientCommandSource> { + @Override + public CompletableFuture<Suggestions> getSuggestions(CommandContext<FabricClientCommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException { + List<Module> modules = ModuleManager.getAllModules(); + + for (Module module : modules) { + builder.suggest(module.getName()); + } + + return builder.buildFuture(); + } +}
\ No newline at end of file diff --git a/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/commands/ModuleToggleCommand.java b/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/commands/ModuleToggleCommand.java new file mode 100644 index 0000000..1448bd7 --- /dev/null +++ b/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/commands/ModuleToggleCommand.java @@ -0,0 +1,44 @@ +package net.justlearning.arslaan3102.arslaansmagichax.commands; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; +import net.justlearning.arslaan3102.arslaansmagichax.modules.ModuleManager; +import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.text.Text; + +public class ModuleToggleCommand { + public static void register(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess access) { + dispatcher.register( + ClientCommandManager.literal("module") + .then( + ClientCommandManager.literal("toggle") + .then( + ClientCommandManager.argument("moduleName", StringArgumentType.word()) + .suggests(new ModuleSuggestionProvider()) + .executes(ModuleToggleCommand::run) + ) + ) + ); + } + + private static int run(CommandContext<FabricClientCommandSource> context) throws CommandSyntaxException { + String moduleName = StringArgumentType.getString(context, "moduleName"); + + ModuleManager.getAllModules().stream() + .filter(m -> m.getName().equalsIgnoreCase(moduleName)) + .findFirst() + .ifPresentOrElse(module -> { + module.toggle(); + context.getSource().sendFeedback(Text.literal( + "Toggled module " + module.getName() + " to " + (module.isEnabled() ? "ON" : "OFF") + )); + }, () -> context.getSource().sendError(Text.literal("Module not found: " + moduleName))); + + return 1; + } +} |
