From 202b14034f7a236c1e57985dde7ff08f0bff7b9b Mon Sep 17 00:00:00 2001 From: RacoonDog <32882447+RacoonDog@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:52:11 -0400 Subject: [PATCH] Add swap, drop and hotbar keys to .input command --- .../commands/commands/InputCommand.java | 59 ++++++++++++++----- .../mixin/KeyBindingAccessor.java | 6 ++ 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/InputCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/InputCommand.java index 6d1041047b..8852feccce 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/InputCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/InputCommand.java @@ -7,29 +7,37 @@ import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.datafixers.util.Pair; import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.commands.Command; import meteordevelopment.meteorclient.events.world.TickEvent; +import meteordevelopment.meteorclient.mixin.KeyBindingAccessor; import meteordevelopment.orbit.EventHandler; import net.minecraft.client.option.KeyBinding; +import net.minecraft.client.resource.language.I18n; import net.minecraft.command.CommandSource; import java.util.ArrayList; import java.util.List; -import java.util.Map; public class InputCommand extends Command { private static final List activeHandlers = new ArrayList<>(); - private static final Map keys = Map.of( - mc.options.forwardKey, "forwards", - mc.options.backKey, "backwards", - mc.options.leftKey, "left", - mc.options.rightKey, "right", - mc.options.jumpKey, "jump", - mc.options.sneakKey, "sneak", - mc.options.useKey, "use", - mc.options.attackKey, "attack" + private static final List> holdKeys = List.of( + new Pair<>(mc.options.forwardKey, "forwards"), + new Pair<>(mc.options.backKey, "backwards"), + new Pair<>(mc.options.leftKey, "left"), + new Pair<>(mc.options.rightKey, "right"), + new Pair<>(mc.options.jumpKey, "jump"), + new Pair<>(mc.options.sneakKey, "sneak"), + new Pair<>(mc.options.sprintKey, "sprint"), + new Pair<>(mc.options.useKey, "use"), + new Pair<>(mc.options.attackKey, "attack") + ); + + private static final List> pressKeys = List.of( + new Pair<>(mc.options.swapHandsKey, "swap"), + new Pair<>(mc.options.dropKey, "drop") ); public InputCommand() { @@ -38,17 +46,35 @@ public InputCommand() { @Override public void build(LiteralArgumentBuilder builder) { - for (Map.Entry keyBinding : keys.entrySet()) { - builder.then(literal(keyBinding.getValue()) + for (Pair keyBinding : holdKeys) { + builder.then(literal(keyBinding.getSecond()) .then(argument("ticks", IntegerArgumentType.integer(1)) .executes(context -> { - activeHandlers.add(new KeypressHandler(keyBinding.getKey(), context.getArgument("ticks", Integer.class))); + activeHandlers.add(new KeypressHandler(keyBinding.getFirst(), context.getArgument("ticks", Integer.class))); return SINGLE_SUCCESS; }) ) ); } + for (Pair keyBinding : pressKeys) { + builder.then(literal(keyBinding.getSecond()) + .executes(context -> { + press(keyBinding.getFirst()); + return SINGLE_SUCCESS; + }) + ); + } + + for (KeyBinding keyBinding : mc.options.hotbarKeys) { + builder.then(literal(keyBinding.getTranslationKey().substring(4)) + .executes(context -> { + press(keyBinding); + return SINGLE_SUCCESS; + }) + ); + } + builder.then(literal("clear").executes(ctx -> { if (activeHandlers.isEmpty()) warning("No active keypress handlers."); else { @@ -65,7 +91,7 @@ public void build(LiteralArgumentBuilder builder) { info("Active keypress handlers: "); for (int i = 0; i < activeHandlers.size(); i++) { KeypressHandler handler = activeHandlers.get(i); - info("(highlight)%d(default) - (highlight)%s %d(default) ticks left out of (highlight)%d(default).", i, keys.get(handler.key), handler.ticks, handler.totalTicks); + info("(highlight)%d(default) - (highlight)%s %d(default) ticks left out of (highlight)%d(default).", i, I18n.translate(handler.key.getTranslationKey()), handler.ticks, handler.totalTicks); } } return SINGLE_SUCCESS; @@ -83,6 +109,11 @@ public void build(LiteralArgumentBuilder builder) { }))); } + private static void press(KeyBinding keyBinding) { + KeyBindingAccessor accessor = (KeyBindingAccessor) keyBinding; + accessor.meteor$setTimesPressed(accessor.meteor$getTimesPressed() + 1); + } + private static class KeypressHandler { private final KeyBinding key; private final int totalTicks; diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/KeyBindingAccessor.java b/src/main/java/meteordevelopment/meteorclient/mixin/KeyBindingAccessor.java index 44f169c68e..f30ef37910 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/KeyBindingAccessor.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/KeyBindingAccessor.java @@ -19,4 +19,10 @@ public interface KeyBindingAccessor { @Accessor("boundKey") InputUtil.Key getKey(); + + @Accessor("timesPressed") + int meteor$getTimesPressed(); + + @Accessor("timesPressed") + void meteor$setTimesPressed(int timesPressed); }