mirror of
https://github.com/AutismDevelopment/Autism-Client.git
synced 2026-10-28 22:59:46 +00:00
Release the tag update
This commit is contained in:
commit
cb6910b424
1300 changed files with 317229 additions and 0 deletions
18
src/main/java/autismclient/commands/AutismCommandSource.java
Normal file
18
src/main/java/autismclient/commands/AutismCommandSource.java
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package autismclient.commands;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
|
||||
public final class AutismCommandSource {
|
||||
public static final AutismCommandSource INSTANCE = new AutismCommandSource();
|
||||
|
||||
private AutismCommandSource() {}
|
||||
|
||||
public Minecraft mc() { return Minecraft.getInstance(); }
|
||||
public LocalPlayer player() { return Minecraft.getInstance().player; }
|
||||
public ClientPacketListener connection() { return Minecraft.getInstance().getConnection(); }
|
||||
|
||||
public boolean hasPlayer() { return Minecraft.getInstance().player != null; }
|
||||
public boolean hasConnection() { return Minecraft.getInstance().getConnection() != null; }
|
||||
}
|
||||
284
src/main/java/autismclient/commands/AutismCommands.java
Normal file
284
src/main/java/autismclient/commands/AutismCommands.java
Normal file
|
|
@ -0,0 +1,284 @@
|
|||
package autismclient.commands;
|
||||
|
||||
import autismclient.AutismClientAddon;
|
||||
import autismclient.api.AddonRegistrationResult;
|
||||
import autismclient.modules.PackHideState;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismCompatManager;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
public final class AutismCommands {
|
||||
private static final CommandDispatcher<AutismCommandSource> DISPATCHER = new CommandDispatcher<>();
|
||||
private static final List<Command> ALL = new ArrayList<>();
|
||||
private static final Map<String, Command> BY_NAME = new LinkedHashMap<>();
|
||||
private static final Map<String, String> ADDON_COMMAND_OWNERS = new LinkedHashMap<>();
|
||||
private static final Map<Command, String> ADDON_COMMAND_OBJECT_OWNERS = new IdentityHashMap<>();
|
||||
private static final Set<String> DISABLED_ADDON_COMMAND_NAMES = new HashSet<>();
|
||||
private static final List<String> PANIC_PREFIX_FALLBACKS = List.of(".", ",", ";", ":", "'", "\"", "\\", "|", "-", "_", "+", "=", "*", "#", "@", "!", "$", "%", "&", "~");
|
||||
private static boolean initialized = false;
|
||||
private static int revision;
|
||||
|
||||
private AutismCommands() {}
|
||||
|
||||
public static synchronized void init() {
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
register(new autismclient.commands.impl.MacroCommand());
|
||||
register(new autismclient.commands.impl.SyncCommand());
|
||||
register(new autismclient.commands.impl.DelayCommand());
|
||||
register(new autismclient.commands.impl.SendCommand());
|
||||
register(new autismclient.commands.impl.VClipCommand());
|
||||
register(new autismclient.commands.impl.HClipCommand());
|
||||
register(new autismclient.commands.impl.TpCommand());
|
||||
register(new autismclient.commands.impl.CopyPosCommand());
|
||||
register(new autismclient.commands.impl.NbtCommand());
|
||||
register(new autismclient.commands.impl.ServerCommand());
|
||||
register(new autismclient.commands.impl.PluginsCommand());
|
||||
register(new autismclient.commands.impl.PrefixCommand());
|
||||
register(new autismclient.commands.impl.CommandsCommand());
|
||||
register(new autismclient.commands.impl.HelpCommand());
|
||||
register(new autismclient.commands.impl.BindsCommand());
|
||||
register(new autismclient.commands.impl.BindCommand());
|
||||
register(new autismclient.commands.impl.ClearCommand());
|
||||
register(new autismclient.commands.impl.DismountCommand());
|
||||
register(new autismclient.commands.impl.DisconnectCommand());
|
||||
register(new autismclient.commands.impl.SayCommand());
|
||||
register(new autismclient.commands.impl.DropCommand());
|
||||
register(new autismclient.commands.impl.ChangeSlotCommand());
|
||||
register(new autismclient.commands.impl.ClickSlotCommand());
|
||||
register(new autismclient.commands.impl.ClickItemCommand());
|
||||
register(new autismclient.commands.impl.GiveCommand());
|
||||
register(new autismclient.commands.impl.DamageCommand());
|
||||
|
||||
if (!autismclient.util.AutismLiteVariant.enabled()) {
|
||||
register(new autismclient.commands.impl.IrcCommand());
|
||||
register(new autismclient.commands.impl.MatchmakingCommand());
|
||||
register(new autismclient.commands.impl.MultiCommand());
|
||||
register(new autismclient.commands.impl.ToggleCommand());
|
||||
register(new autismclient.commands.impl.ModulesCommand());
|
||||
register(new autismclient.commands.impl.OreSimCommand());
|
||||
register(new autismclient.commands.impl.GhostBlockCommand());
|
||||
register(new autismclient.commands.impl.FriendCommand());
|
||||
register(new autismclient.commands.impl.WaypointsCommand());
|
||||
register(new autismclient.commands.impl.GamemodeCommand());
|
||||
register(new autismclient.commands.impl.FakeGmCommand());
|
||||
register(new autismclient.commands.impl.XCarryCommand());
|
||||
register(new autismclient.commands.impl.RemoteViewCommand());
|
||||
register(new autismclient.commands.impl.NameScrapeCommand());
|
||||
}
|
||||
}
|
||||
|
||||
private static void register(Command command) {
|
||||
registerWithName(command, command.name(), true);
|
||||
}
|
||||
|
||||
private static List<String> registerWithName(Command command, String primaryName, boolean registerAliases) {
|
||||
List<String> registeredNames = new ArrayList<>();
|
||||
revision++;
|
||||
ALL.add(command);
|
||||
LiteralArgumentBuilder<AutismCommandSource> primary = LiteralArgumentBuilder.literal(primaryName);
|
||||
command.build(primary);
|
||||
DISPATCHER.register(primary);
|
||||
BY_NAME.put(primaryName.toLowerCase(Locale.ROOT), command);
|
||||
DISABLED_ADDON_COMMAND_NAMES.remove(primaryName.toLowerCase(Locale.ROOT));
|
||||
registeredNames.add(primaryName.toLowerCase(Locale.ROOT));
|
||||
|
||||
if (!registerAliases) return registeredNames;
|
||||
for (String alias : command.aliases()) {
|
||||
if (alias == null || alias.isBlank()) continue;
|
||||
if (BY_NAME.containsKey(alias.toLowerCase(Locale.ROOT))) continue;
|
||||
LiteralArgumentBuilder<AutismCommandSource> aliasBuilder = LiteralArgumentBuilder.literal(alias);
|
||||
command.build(aliasBuilder);
|
||||
DISPATCHER.register(aliasBuilder);
|
||||
BY_NAME.put(alias.toLowerCase(Locale.ROOT), command);
|
||||
DISABLED_ADDON_COMMAND_NAMES.remove(alias.toLowerCase(Locale.ROOT));
|
||||
registeredNames.add(alias.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
return registeredNames;
|
||||
}
|
||||
|
||||
public static synchronized void registerAddonCommand(Command command, String addonId) {
|
||||
registerAddonCommandDetailed(command, addonId);
|
||||
}
|
||||
|
||||
public static synchronized AddonRegistrationResult registerAddonCommandDetailed(Command command, String addonId) {
|
||||
if (command == null) return AddonRegistrationResult.rejected("command", "", "command was null");
|
||||
if (addonId == null || addonId.isBlank()) {
|
||||
return rejectAddonCommand(addonId, "", "registration outside an addon lifecycle - register from onInitialize() or onRegisterCategories()");
|
||||
}
|
||||
String name = command.name();
|
||||
if (name == null || name.isBlank()) {
|
||||
return rejectAddonCommand(addonId, "", "blank command name");
|
||||
}
|
||||
List<String> registered;
|
||||
boolean collision = BY_NAME.containsKey(name.toLowerCase(Locale.ROOT));
|
||||
if (collision) {
|
||||
String namespaced = (addonId == null || addonId.isBlank() ? "addon" : addonId) + ":" + name;
|
||||
AutismClientAddon.LOG.warn("[Commands] Command name '{}' from addon '{}' collides with an existing "
|
||||
+ "command; registering it as '{}' instead", name, addonId, namespaced);
|
||||
registered = registerWithName(command, namespaced, false);
|
||||
} else {
|
||||
registered = registerWithName(command, name, true);
|
||||
}
|
||||
ADDON_COMMAND_OBJECT_OWNERS.put(command, addonId);
|
||||
for (String registeredName : registered) {
|
||||
ADDON_COMMAND_OWNERS.put(registeredName, addonId);
|
||||
}
|
||||
String id = registered.isEmpty() ? name : registered.get(0);
|
||||
autismclient.addons.AddonManager.recordAcceptedRegistration("command", id);
|
||||
return AddonRegistrationResult.accepted("command", id);
|
||||
}
|
||||
|
||||
private static AddonRegistrationResult rejectAddonCommand(String addonId, String id, String reason) {
|
||||
AutismClientAddon.LOG.warn("[Commands] Rejecting addon command '{}': {}", id, reason);
|
||||
autismclient.addons.AddonManager.recordRejectedRegistration(addonId, "command", id, reason);
|
||||
return AddonRegistrationResult.rejected("command", id, reason);
|
||||
}
|
||||
|
||||
public static synchronized void unregisterAddonCommands(String addonId) {
|
||||
if (addonId == null || addonId.isBlank()) return;
|
||||
List<String> removeNames = new ArrayList<>();
|
||||
for (Map.Entry<String, String> owner : ADDON_COMMAND_OWNERS.entrySet()) {
|
||||
if (addonId.equals(owner.getValue())) removeNames.add(owner.getKey());
|
||||
}
|
||||
for (String name : removeNames) {
|
||||
BY_NAME.remove(name);
|
||||
ADDON_COMMAND_OWNERS.remove(name);
|
||||
DISABLED_ADDON_COMMAND_NAMES.add(name);
|
||||
}
|
||||
ALL.removeIf(command -> addonId.equals(ADDON_COMMAND_OBJECT_OWNERS.get(command)));
|
||||
ADDON_COMMAND_OBJECT_OWNERS.entrySet().removeIf(entry -> addonId.equals(entry.getValue()));
|
||||
if (!removeNames.isEmpty()) revision++;
|
||||
}
|
||||
|
||||
public static CommandDispatcher<AutismCommandSource> dispatcher() { return DISPATCHER; }
|
||||
|
||||
public static int revision() { return revision; }
|
||||
|
||||
public static List<Command> all() { return Collections.unmodifiableList(ALL); }
|
||||
|
||||
public static Command find(String nameOrAlias) {
|
||||
if (nameOrAlias == null) return null;
|
||||
return BY_NAME.get(nameOrAlias.trim().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public static String effectivePrefix() { return AutismCompatManager.effectiveCommandPrefix(); }
|
||||
|
||||
public static boolean isAutismCommandMessage(String message) {
|
||||
if (message == null || message.isBlank()) return false;
|
||||
String trimmed = message.trim();
|
||||
String prefix = effectivePrefix();
|
||||
return !prefix.isEmpty() && trimmed.startsWith(prefix);
|
||||
}
|
||||
|
||||
public static boolean commandsBlockedByPanic() {
|
||||
return PackHideState.isHardLocked();
|
||||
}
|
||||
|
||||
public static boolean isBlockedPanicCommandMessage(String message) {
|
||||
return commandsBlockedByPanic() && isPanicBlockedCommandMessage(message);
|
||||
}
|
||||
|
||||
private static boolean isPanicBlockedCommandMessage(String message) {
|
||||
if (message == null || message.isBlank()) return false;
|
||||
String trimmed = message.trim();
|
||||
if ("^toggleautism".equalsIgnoreCase(trimmed)) return true;
|
||||
|
||||
String prefix = effectivePrefix();
|
||||
if (!prefix.isEmpty() && trimmed.startsWith(prefix)) return true;
|
||||
|
||||
for (String fallback : PANIC_PREFIX_FALLBACKS) {
|
||||
if (fallback == null || fallback.isEmpty() || fallback.equals(prefix)) continue;
|
||||
if (!trimmed.startsWith(fallback)) continue;
|
||||
String body = trimmed.substring(fallback.length()).trim();
|
||||
if (body.isEmpty()) continue;
|
||||
String first = firstToken(body).toLowerCase(Locale.ROOT);
|
||||
if (BY_NAME.containsKey(first) || DISABLED_ADDON_COMMAND_NAMES.contains(first)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String commandBody(String message) {
|
||||
if (!isAutismCommandMessage(message)) return "";
|
||||
String trimmed = message.trim();
|
||||
int prefixLength = effectivePrefix().length();
|
||||
return trimmed.length() <= prefixLength ? "" : trimmed.substring(prefixLength).trim();
|
||||
}
|
||||
|
||||
private static final ThreadLocal<Boolean> PLAIN_CHAT_BYPASS = ThreadLocal.withInitial(() -> false);
|
||||
|
||||
public static boolean plainChatBypass() {
|
||||
return PLAIN_CHAT_BYPASS.get();
|
||||
}
|
||||
|
||||
public static void sendPlainChat(net.minecraft.client.multiplayer.ClientPacketListener conn, String message) {
|
||||
PLAIN_CHAT_BYPASS.set(true);
|
||||
try {
|
||||
conn.sendChat(message);
|
||||
} finally {
|
||||
PLAIN_CHAT_BYPASS.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean dispatch(String body) {
|
||||
if (commandsBlockedByPanic()) return true;
|
||||
if (body == null) return false;
|
||||
String trimmed = body.trim();
|
||||
if (trimmed.isEmpty()) return false;
|
||||
if (DISABLED_ADDON_COMMAND_NAMES.contains(firstToken(trimmed).toLowerCase(Locale.ROOT))) {
|
||||
sendSyntaxError(trimmed, CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand().create());
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
|
||||
if (!autismclient.util.AutismLiteVariant.enabled()
|
||||
&& autismclient.util.multi.MultiPovCommandRouter.route(trimmed)) return true;
|
||||
DISPATCHER.execute(trimmed, AutismCommandSource.INSTANCE);
|
||||
return true;
|
||||
} catch (CommandSyntaxException e) {
|
||||
sendSyntaxError(trimmed, e);
|
||||
return true;
|
||||
} catch (Throwable t) {
|
||||
AutismClientAddon.LOG.warn("[Commands] dispatch failed for '{}'", trimmed, t);
|
||||
AutismClientMessaging.sendPrefixed("§cCommand error: "
|
||||
+ (t.getMessage() == null ? t.getClass().getSimpleName() : t.getMessage()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendSyntaxError(String body, CommandSyntaxException e) {
|
||||
String first = firstToken(body);
|
||||
Command command = find(first);
|
||||
String prefix = effectivePrefix();
|
||||
if (command == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cUnknown AUTISM command: §f" + first);
|
||||
AutismClientMessaging.sendPrefixed("§7Use §f" + prefix + "commands §7or §f" + prefix + "help§7.");
|
||||
return;
|
||||
}
|
||||
|
||||
String message = e.getMessage();
|
||||
if (message == null || message.isBlank()) message = "Incomplete or invalid command.";
|
||||
AutismClientMessaging.sendPrefixed("§c" + message);
|
||||
AutismClientMessaging.sendPrefixed("§7Use §f" + prefix + "help " + command.name() + "§7.");
|
||||
}
|
||||
|
||||
private static String firstToken(String body) {
|
||||
if (body == null) return "";
|
||||
String trimmed = body.trim();
|
||||
if (trimmed.isEmpty()) return "";
|
||||
int space = trimmed.indexOf(' ');
|
||||
return space < 0 ? trimmed : trimmed.substring(0, space);
|
||||
}
|
||||
}
|
||||
33
src/main/java/autismclient/commands/Command.java
Normal file
33
src/main/java/autismclient/commands/Command.java
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package autismclient.commands;
|
||||
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
|
||||
public abstract class Command {
|
||||
public static final int SUCCESS = 1;
|
||||
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final String[] aliases;
|
||||
|
||||
protected Command(String name, String description, String... aliases) {
|
||||
this.name = name;
|
||||
this.description = description == null ? "" : description;
|
||||
this.aliases = aliases == null ? new String[0] : aliases.clone();
|
||||
}
|
||||
|
||||
public final String name() { return name; }
|
||||
public final String description() { return description; }
|
||||
public final String[] aliases() { return aliases.clone(); }
|
||||
|
||||
public abstract void build(LiteralArgumentBuilder<AutismCommandSource> builder);
|
||||
|
||||
public int run(CommandContext<AutismCommandSource> ctx) {
|
||||
autismclient.util.AutismClientMessaging.sendPrefixed(
|
||||
"§eUsage: " + AutismCommands.effectivePrefix() + name + (aliases.length > 0 ? " (alias: " + aliases[0] + ")" : ""));
|
||||
if (!description.isEmpty()) {
|
||||
autismclient.util.AutismClientMessaging.sendPrefixed("§7" + description);
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
92
src/main/java/autismclient/commands/CommandSuggest.java
Normal file
92
src/main/java/autismclient/commands/CommandSuggest.java
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
package autismclient.commands;
|
||||
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public final class CommandSuggest {
|
||||
private CommandSuggest() {}
|
||||
|
||||
public static <S> CompletableFuture<Suggestions> literals(SuggestionsBuilder builder, String... values) {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
for (String value : values) {
|
||||
if (value != null && value.toLowerCase(Locale.ROOT).startsWith(remaining)) builder.suggest(value);
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
public static <S> CompletableFuture<Suggestions> state(CommandContext<S> ignored, SuggestionsBuilder builder) {
|
||||
return literals(builder, "on", "off", "toggle", "enable", "disable");
|
||||
}
|
||||
|
||||
public static <S> CompletableFuture<Suggestions> offsets(CommandContext<S> ignored, SuggestionsBuilder builder) {
|
||||
return literals(builder, "1", "5", "10", "50", "100", "-1", "-5", "-10", "-50", "-100");
|
||||
}
|
||||
|
||||
public static <S> CompletableFuture<Suggestions> vclipSegments(CommandContext<S> ignored, SuggestionsBuilder builder) {
|
||||
return literals(builder, "1", "5", "10", "20", "50");
|
||||
}
|
||||
|
||||
public static <S> CompletableFuture<Suggestions> vclipPacketLimits(CommandContext<S> ignored, SuggestionsBuilder builder) {
|
||||
return literals(builder, "1", "5", "10", "20", "40", "100");
|
||||
}
|
||||
|
||||
public static <S> CompletableFuture<Suggestions> damage(CommandContext<S> ignored, SuggestionsBuilder builder) {
|
||||
return literals(builder, "1", "2", "4", "8", "20");
|
||||
}
|
||||
|
||||
public static <S> CompletableFuture<Suggestions> counts(CommandContext<S> ignored, SuggestionsBuilder builder) {
|
||||
return literals(builder, "1", "16", "32", "64", "1000", "10000", "100000");
|
||||
}
|
||||
|
||||
public static <S> CompletableFuture<Suggestions> gamemodes(CommandContext<S> ignored, SuggestionsBuilder builder) {
|
||||
return literals(builder, "survival", "creative", "adventure", "spectator", "reset", "0", "1", "2", "3");
|
||||
}
|
||||
|
||||
public static <S> CompletableFuture<Suggestions> realGamemodes(CommandContext<S> ignored, SuggestionsBuilder builder) {
|
||||
return literals(builder, "survival", "creative", "adventure", "spectator", "0", "1", "2", "3");
|
||||
}
|
||||
|
||||
public static <S> CompletableFuture<Suggestions> prefixes(CommandContext<S> ignored, SuggestionsBuilder builder) {
|
||||
return literals(builder, ".", "%", "-", "_", "*", "#", "@", "&", "=");
|
||||
}
|
||||
|
||||
private static volatile String[][] itemIdCache;
|
||||
private static volatile String[][] blockIdCache;
|
||||
|
||||
public static <S> CompletableFuture<Suggestions> itemIds(CommandContext<S> ignored, SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
String[][] cache = itemIdCache;
|
||||
if (cache == null) cache = itemIdCache = buildIdCache(BuiltInRegistries.ITEM.keySet());
|
||||
for (String[] entry : cache) {
|
||||
if (entry[1].startsWith(remaining)) builder.suggest(entry[0]);
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
public static <S> CompletableFuture<Suggestions> blockIds(CommandContext<S> ignored, SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
String[][] cache = blockIdCache;
|
||||
if (cache == null) cache = blockIdCache = buildIdCache(BuiltInRegistries.BLOCK.keySet());
|
||||
for (String[] entry : cache) {
|
||||
if (entry[1].startsWith(remaining)) builder.suggest(entry[0]);
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
private static String[][] buildIdCache(java.util.Set<Identifier> ids) {
|
||||
java.util.List<String[]> entries = new java.util.ArrayList<>(ids.size() * 2);
|
||||
for (Identifier id : ids) {
|
||||
String full = id.toString();
|
||||
String shortId = id.getNamespace().equals("minecraft") ? id.getPath() : full;
|
||||
entries.add(new String[]{full, full.toLowerCase(Locale.ROOT)});
|
||||
if (!shortId.equals(full)) entries.add(new String[]{shortId, shortId.toLowerCase(Locale.ROOT)});
|
||||
}
|
||||
return entries.toArray(new String[0][]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package autismclient.commands.args;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class KeyArgumentType implements ArgumentType<Integer> {
|
||||
private static final Map<String, Integer> NAMES = new LinkedHashMap<>();
|
||||
private static final SimpleCommandExceptionType UNKNOWN = new SimpleCommandExceptionType(Component.literal("Unknown key"));
|
||||
|
||||
static {
|
||||
for (Field f : GLFW.class.getDeclaredFields()) {
|
||||
String n = f.getName();
|
||||
if (!n.startsWith("GLFW_KEY_")) continue;
|
||||
try {
|
||||
int code = f.getInt(null);
|
||||
NAMES.put(n.substring("GLFW_KEY_".length()).toUpperCase(Locale.ROOT), code);
|
||||
} catch (Throwable ignored) { }
|
||||
}
|
||||
}
|
||||
|
||||
public static KeyArgumentType key() { return new KeyArgumentType(); }
|
||||
|
||||
public static int get(CommandContext<AutismCommandSource> ctx, String name) {
|
||||
return ctx.getArgument(name, Integer.class);
|
||||
}
|
||||
|
||||
public static String keyName(int code) {
|
||||
if (code < 0) return "NONE";
|
||||
for (Map.Entry<String, Integer> e : NAMES.entrySet()) {
|
||||
if (e.getValue() == code) return e.getKey();
|
||||
}
|
||||
return "KEY_" + code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer parse(StringReader reader) throws CommandSyntaxException {
|
||||
String raw = reader.readUnquotedString();
|
||||
String upper = raw.toUpperCase(Locale.ROOT);
|
||||
Integer code = NAMES.get(upper);
|
||||
if (code != null) return code;
|
||||
|
||||
if (upper.length() == 1) {
|
||||
char c = upper.charAt(0);
|
||||
if (c >= 'A' && c <= 'Z') return GLFW.GLFW_KEY_A + (c - 'A');
|
||||
if (c >= '0' && c <= '9') return GLFW.GLFW_KEY_0 + (c - '0');
|
||||
}
|
||||
throw UNKNOWN.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemaining().toUpperCase(Locale.ROOT);
|
||||
for (String n : NAMES.keySet()) {
|
||||
if (n.startsWith(remaining)) builder.suggest(n);
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package autismclient.commands.args;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.util.AutismMacroManager;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class MacroArgumentType implements ArgumentType<String> {
|
||||
private static volatile long cachedRevision = Long.MIN_VALUE;
|
||||
private static volatile List<Candidate> cachedCandidates = List.of();
|
||||
|
||||
private record Candidate(String value, String lower) {}
|
||||
|
||||
public static MacroArgumentType macroName() { return new MacroArgumentType(); }
|
||||
|
||||
public static String get(CommandContext<AutismCommandSource> ctx, String name) {
|
||||
return ctx.getArgument(name, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(StringReader reader) throws CommandSyntaxException {
|
||||
|
||||
if (reader.canRead() && reader.peek() == '"') return reader.readQuotedString();
|
||||
return reader.readUnquotedString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
for (Candidate candidate : candidates()) {
|
||||
if (candidate.lower().startsWith(remaining)) builder.suggest(candidate.value());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
private static List<Candidate> candidates() {
|
||||
AutismMacroManager manager = AutismMacroManager.get();
|
||||
long revision = manager.getRevision();
|
||||
List<Candidate> hit = cachedCandidates;
|
||||
if (cachedRevision == revision) return hit;
|
||||
List<Candidate> rebuilt = new ArrayList<>();
|
||||
for (autismclient.util.AutismMacro macro : manager.getAll()) {
|
||||
if (macro == null || macro.name == null) continue;
|
||||
String name = macro.name;
|
||||
String value = name.contains(" ") ? "\"" + name + "\"" : name;
|
||||
rebuilt.add(new Candidate(value, name.toLowerCase(Locale.ROOT)));
|
||||
}
|
||||
hit = List.copyOf(rebuilt);
|
||||
cachedCandidates = hit;
|
||||
cachedRevision = revision;
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
package autismclient.commands.args;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.util.AutismInventoryHelper;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public final class MenuSlotArgumentType implements ArgumentType<Integer> {
|
||||
private static final SimpleCommandExceptionType INVALID_SLOT = new SimpleCommandExceptionType(
|
||||
Component.literal("Unknown slot. Use gui1, hotbar1, inventory1, helmet, chestplate, leggings, boots, offhand, or a visible numeric slot id."));
|
||||
private static AbstractContainerMenu cachedMenu;
|
||||
private static int cachedSlotCount = -1;
|
||||
private static List<String> cachedValues = List.of();
|
||||
|
||||
private MenuSlotArgumentType() {
|
||||
}
|
||||
|
||||
public static MenuSlotArgumentType slot() {
|
||||
return new MenuSlotArgumentType();
|
||||
}
|
||||
|
||||
public static int get(CommandContext<AutismCommandSource> context, String name) {
|
||||
return context.getArgument(name, Integer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer parse(StringReader reader) throws CommandSyntaxException {
|
||||
String token = reader.readUnquotedString().trim().toLowerCase(Locale.ROOT);
|
||||
if (token.isEmpty()) throw INVALID_SLOT.create();
|
||||
|
||||
Integer named = parseNamed(token);
|
||||
if (named != null) return named;
|
||||
try {
|
||||
int numeric = Integer.parseInt(token);
|
||||
if (numeric >= 0) return numeric;
|
||||
} catch (NumberFormatException ignored) { }
|
||||
throw INVALID_SLOT.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
for (String value : values(mc)) {
|
||||
if (value.toLowerCase(Locale.ROOT).startsWith(remaining)) builder.suggest(value);
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
private static List<String> values(Minecraft mc) {
|
||||
AbstractContainerMenu menu = mc.player == null ? null : mc.player.containerMenu;
|
||||
int slotCount = menu == null ? 0 : menu.slots.size();
|
||||
if (menu == cachedMenu && slotCount == cachedSlotCount) return cachedValues;
|
||||
Set<String> values = new LinkedHashSet<>();
|
||||
if (menu != null) {
|
||||
for (int handlerSlot = 0; handlerSlot < menu.slots.size(); handlerSlot++) {
|
||||
int visible = AutismInventoryHelper.toUserVisibleSlot(mc, handlerSlot);
|
||||
values.add(displayToken(visible));
|
||||
values.add(String.valueOf(visible));
|
||||
}
|
||||
} else {
|
||||
for (int slot = 1; slot <= 9; slot++) values.add("hotbar" + slot);
|
||||
}
|
||||
cachedMenu = menu;
|
||||
cachedSlotCount = slotCount;
|
||||
cachedValues = List.copyOf(values);
|
||||
return cachedValues;
|
||||
}
|
||||
|
||||
public static String displayToken(int visibleSlot) {
|
||||
if (visibleSlot >= AutismInventoryHelper.FIRST_GUI_SLOT) {
|
||||
return "gui" + (visibleSlot - AutismInventoryHelper.FIRST_GUI_SLOT + 1);
|
||||
}
|
||||
if (visibleSlot >= 0 && visibleSlot <= 8) return "hotbar" + (visibleSlot + 1);
|
||||
if (visibleSlot >= 9 && visibleSlot <= 35) return "inventory" + (visibleSlot - 8);
|
||||
return switch (visibleSlot) {
|
||||
case 36 -> "boots";
|
||||
case 37 -> "leggings";
|
||||
case 38 -> "chestplate";
|
||||
case 39 -> "helmet";
|
||||
case 40 -> "offhand";
|
||||
default -> String.valueOf(visibleSlot);
|
||||
};
|
||||
}
|
||||
|
||||
private static Integer parseNamed(String token) {
|
||||
return switch (token) {
|
||||
case "boots" -> 36;
|
||||
case "leggings" -> 37;
|
||||
case "chestplate" -> 38;
|
||||
case "helmet" -> 39;
|
||||
case "offhand" -> 40;
|
||||
default -> {
|
||||
Integer gui = parseIndexed(token, "gui", AutismInventoryHelper.FIRST_GUI_SLOT, Integer.MAX_VALUE);
|
||||
if (gui != null) yield gui;
|
||||
Integer hotbar = parseIndexed(token, "hotbar", 0, 9);
|
||||
if (hotbar != null) yield hotbar;
|
||||
yield parseIndexed(token, "inventory", 9, 27);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Integer parseIndexed(String token, String prefix, int offset, int maxIndex) {
|
||||
if (!token.startsWith(prefix)) return null;
|
||||
String suffix = token.substring(prefix.length());
|
||||
if (suffix.startsWith(":")) suffix = suffix.substring(1);
|
||||
try {
|
||||
int oneBased = Integer.parseInt(suffix);
|
||||
if (oneBased < 1 || oneBased > maxIndex) return null;
|
||||
return offset + oneBased - 1;
|
||||
} catch (NumberFormatException ignored) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
package autismclient.commands.args;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.modules.ModuleRegistry;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class ModuleArgumentType implements ArgumentType<String> {
|
||||
private static volatile int cachedRevision = Integer.MIN_VALUE;
|
||||
private static volatile List<Candidate> cachedCandidates = List.of();
|
||||
|
||||
private record Candidate(String value, String lower) {}
|
||||
|
||||
public static ModuleArgumentType moduleName() { return new ModuleArgumentType(); }
|
||||
|
||||
public static String get(CommandContext<AutismCommandSource> ctx, String name) {
|
||||
return ctx.getArgument(name, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(StringReader reader) throws CommandSyntaxException {
|
||||
return reader.readUnquotedString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
for (Candidate candidate : candidates()) {
|
||||
if (candidate.lower().startsWith(remaining)) builder.suggest(candidate.value());
|
||||
}
|
||||
|
||||
if ("all".startsWith(remaining)) builder.suggest("all");
|
||||
if ("hud".startsWith(remaining)) builder.suggest("hud");
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
private static List<Candidate> candidates() {
|
||||
int revision = ModuleRegistry.revision();
|
||||
List<Candidate> hit = cachedCandidates;
|
||||
if (cachedRevision == revision) return hit;
|
||||
List<Candidate> rebuilt = new ArrayList<>();
|
||||
for (String name : ModuleRegistry.names()) {
|
||||
if (name == null) continue;
|
||||
|
||||
String commandName = name.replace(' ', '-');
|
||||
rebuilt.add(new Candidate(commandName, commandName.toLowerCase(Locale.ROOT)));
|
||||
}
|
||||
hit = List.copyOf(rebuilt);
|
||||
cachedCandidates = hit;
|
||||
cachedRevision = revision;
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package autismclient.commands.args;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.util.multi.MultiManager;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class MultiBotArgumentType implements ArgumentType<String> {
|
||||
public static MultiBotArgumentType botName() {
|
||||
return new MultiBotArgumentType();
|
||||
}
|
||||
|
||||
public static String get(CommandContext<AutismCommandSource> ctx, String name) {
|
||||
return ctx.getArgument(name, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(StringReader reader) throws CommandSyntaxException {
|
||||
if (reader.canRead() && reader.peek() == '"') return reader.readQuotedString();
|
||||
return reader.readUnquotedString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
for (MultiManager.BotHandle bot : MultiManager.get().liveBots()) {
|
||||
String name = bot.username();
|
||||
if (name == null || name.isBlank()) continue;
|
||||
if (name.toLowerCase(Locale.ROOT).startsWith(remaining)) {
|
||||
builder.suggest(name.contains(" ") ? "\"" + name + "\"" : name);
|
||||
}
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package autismclient.commands.args;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.util.multi.MultiProfile;
|
||||
import autismclient.util.multi.MultiProfileManager;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class MultiProfileArgumentType implements ArgumentType<String> {
|
||||
private static volatile long cachedRevision = Long.MIN_VALUE;
|
||||
private static volatile List<Candidate> cachedCandidates = List.of();
|
||||
|
||||
private record Candidate(String value, String lower) {}
|
||||
|
||||
public static MultiProfileArgumentType profileName() {
|
||||
return new MultiProfileArgumentType();
|
||||
}
|
||||
|
||||
public static String get(CommandContext<AutismCommandSource> ctx, String name) {
|
||||
return ctx.getArgument(name, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(StringReader reader) throws CommandSyntaxException {
|
||||
if (reader.canRead() && reader.peek() == '"') return reader.readQuotedString();
|
||||
return reader.readUnquotedString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
for (Candidate candidate : candidates()) {
|
||||
if (candidate.lower().startsWith(remaining)) builder.suggest(candidate.value());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
private static List<Candidate> candidates() {
|
||||
MultiProfileManager manager = MultiProfileManager.get();
|
||||
long revision = manager.revision();
|
||||
List<Candidate> hit = cachedCandidates;
|
||||
if (cachedRevision == revision) return hit;
|
||||
List<Candidate> rebuilt = new ArrayList<>();
|
||||
for (MultiProfile profile : manager) {
|
||||
if (profile == null || profile.name == null) continue;
|
||||
String name = profile.name;
|
||||
String value = name.contains(" ") ? "\"" + name + "\"" : name;
|
||||
rebuilt.add(new Candidate(value, name.toLowerCase(Locale.ROOT)));
|
||||
}
|
||||
hit = List.copyOf(rebuilt);
|
||||
cachedCandidates = hit;
|
||||
cachedRevision = revision;
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package autismclient.commands.args;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.util.AutismPacketRegistry;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class PacketClassArgumentType implements ArgumentType<String> {
|
||||
private static volatile List<Candidate> cachedCandidates;
|
||||
|
||||
private record Candidate(String value, String lower) {}
|
||||
|
||||
public static PacketClassArgumentType packetClass() { return new PacketClassArgumentType(); }
|
||||
|
||||
public static String get(CommandContext<AutismCommandSource> ctx, String name) {
|
||||
return ctx.getArgument(name, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(StringReader reader) throws CommandSyntaxException {
|
||||
return reader.readUnquotedString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
|
||||
for (Candidate candidate : candidates()) {
|
||||
if (candidate.lower().contains(remaining)) builder.suggest(candidate.value());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
private static List<Candidate> candidates() {
|
||||
List<Candidate> hit = cachedCandidates;
|
||||
if (hit != null) return hit;
|
||||
List<Candidate> rebuilt = new ArrayList<>();
|
||||
for (Class<? extends Packet<?>> cls : AutismPacketRegistry.getC2SPackets()) {
|
||||
String name = AutismPacketRegistry.getName(cls);
|
||||
if (name != null) rebuilt.add(new Candidate(name, name.toLowerCase(Locale.ROOT)));
|
||||
}
|
||||
hit = List.copyOf(rebuilt);
|
||||
cachedCandidates = hit;
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
package autismclient.commands.args;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public final class VisibleItemNameArgumentType implements ArgumentType<String> {
|
||||
private static AbstractContainerMenu cachedMenu;
|
||||
private static int cachedMenuRevision = Integer.MIN_VALUE;
|
||||
private static List<Candidate> cachedNames = List.of();
|
||||
|
||||
private record Candidate(String value, String lower) {}
|
||||
|
||||
private VisibleItemNameArgumentType() {
|
||||
}
|
||||
|
||||
public static VisibleItemNameArgumentType itemName() {
|
||||
return new VisibleItemNameArgumentType();
|
||||
}
|
||||
|
||||
public static String get(CommandContext<AutismCommandSource> context, String name) {
|
||||
return context.getArgument(name, String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parse(StringReader reader) throws com.mojang.brigadier.exceptions.CommandSyntaxException {
|
||||
return reader.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
if (remaining.startsWith("\"")) remaining = remaining.substring(1);
|
||||
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
for (Candidate candidate : names(mc)) {
|
||||
if (candidate.lower().startsWith(remaining)) {
|
||||
builder.suggest(StringArgumentType.escapeIfRequired(candidate.value()));
|
||||
}
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
private static List<Candidate> names(Minecraft mc) {
|
||||
AbstractContainerMenu menu = mc.player == null ? null : mc.player.containerMenu;
|
||||
int revision = menu == null ? -1 : menu.getStateId();
|
||||
if (menu == cachedMenu && revision == cachedMenuRevision) return cachedNames;
|
||||
|
||||
Set<String> names = new LinkedHashSet<>();
|
||||
if (menu != null) {
|
||||
for (int slot = 0; slot < menu.slots.size(); slot++) {
|
||||
ItemStack stack = menu.slots.get(slot).getItem();
|
||||
if (stack.isEmpty()) continue;
|
||||
String displayName = collapseWhitespace(stack.getHoverName().getString());
|
||||
if (!displayName.isEmpty()) names.add(displayName);
|
||||
}
|
||||
}
|
||||
List<Candidate> rebuilt = new java.util.ArrayList<>(names.size());
|
||||
for (String name : names) rebuilt.add(new Candidate(name, name.toLowerCase(Locale.ROOT)));
|
||||
cachedMenu = menu;
|
||||
cachedMenuRevision = revision;
|
||||
cachedNames = List.copyOf(rebuilt);
|
||||
return cachedNames;
|
||||
}
|
||||
|
||||
private static String collapseWhitespace(String input) {
|
||||
if (input == null || input.isBlank()) return "";
|
||||
StringBuilder out = new StringBuilder(input.length());
|
||||
boolean pendingSpace = false;
|
||||
for (int index = 0; index < input.length(); index++) {
|
||||
char chr = input.charAt(index);
|
||||
if (Character.isWhitespace(chr)) {
|
||||
pendingSpace = out.length() > 0;
|
||||
} else {
|
||||
if (pendingSpace) out.append(' ');
|
||||
out.append(chr);
|
||||
pendingSpace = false;
|
||||
}
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
package autismclient.commands.args;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.arguments.ArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class XCarrySlotArgumentType implements ArgumentType<Integer> {
|
||||
public static final int CURSOR = Integer.MIN_VALUE;
|
||||
|
||||
private static final Map<String, Integer> TOKENS = new LinkedHashMap<>();
|
||||
static {
|
||||
TOKENS.put("craft1", 1);
|
||||
TOKENS.put("craft2", 2);
|
||||
TOKENS.put("craft3", 3);
|
||||
TOKENS.put("craft4", 4);
|
||||
TOKENS.put("craft5", 0);
|
||||
TOKENS.put("crafting5", 0);
|
||||
TOKENS.put("result", 0);
|
||||
TOKENS.put("helmet", 5);
|
||||
TOKENS.put("chestplate", 6);
|
||||
TOKENS.put("leggings", 7);
|
||||
TOKENS.put("boots", 8);
|
||||
TOKENS.put("offhand", 45);
|
||||
TOKENS.put("cursor", CURSOR);
|
||||
}
|
||||
|
||||
private static final SimpleCommandExceptionType UNKNOWN =
|
||||
new SimpleCommandExceptionType(Component.literal("Unknown XCarry slot — use craft1..craft5 / helmet / chestplate / leggings / boots / offhand / cursor."));
|
||||
|
||||
public static XCarrySlotArgumentType slot() { return new XCarrySlotArgumentType(); }
|
||||
|
||||
public static int get(CommandContext<AutismCommandSource> ctx, String name) {
|
||||
return ctx.getArgument(name, Integer.class);
|
||||
}
|
||||
|
||||
public static String displayName(int slotId) {
|
||||
for (Map.Entry<String, Integer> e : TOKENS.entrySet()) if (e.getValue() == slotId) return e.getKey();
|
||||
return "slot " + slotId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer parse(StringReader reader) throws CommandSyntaxException {
|
||||
String raw = reader.readUnquotedString().toLowerCase(Locale.ROOT);
|
||||
Integer id = TOKENS.get(raw);
|
||||
if (id == null) throw UNKNOWN.create();
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
for (String name : TOKENS.keySet()) {
|
||||
if (name.startsWith(remaining)) builder.suggest(name);
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
}
|
||||
42
src/main/java/autismclient/commands/impl/BindCommand.java
Normal file
42
src/main/java/autismclient/commands/impl/BindCommand.java
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.args.KeyArgumentType;
|
||||
import autismclient.modules.AutismModule;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
|
||||
public class BindCommand extends Command {
|
||||
public BindCommand() { super("bind", "Bind a key to a command. Usage: bind <key> <command…> | bind clear <key>"); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
String prefix = AutismCommands.effectivePrefix();
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: §f" + prefix + "bind <key> <command>");
|
||||
AutismClientMessaging.sendPrefixed("§7Example: §f" + prefix + "bind G " + prefix + "macro myMacro");
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("clear")
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Integer>argument("key", KeyArgumentType.key())
|
||||
.executes(ctx -> {
|
||||
int key = KeyArgumentType.get(ctx, "key");
|
||||
AutismModule.get().clearCommandBind(key);
|
||||
AutismClientMessaging.sendPrefixed("§eCleared bind for §f" + KeyArgumentType.keyName(key));
|
||||
return SUCCESS;
|
||||
})));
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, Integer>argument("key", KeyArgumentType.key())
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("command", StringArgumentType.greedyString())
|
||||
.executes(ctx -> {
|
||||
int key = KeyArgumentType.get(ctx, "key");
|
||||
String cmd = StringArgumentType.getString(ctx, "command");
|
||||
AutismModule.get().setCommandBind(key, cmd);
|
||||
AutismClientMessaging.sendPrefixed("§aBound §f" + KeyArgumentType.keyName(key) + "§a → §f" + cmd);
|
||||
return SUCCESS;
|
||||
})));
|
||||
}
|
||||
}
|
||||
27
src/main/java/autismclient/commands/impl/BindsCommand.java
Normal file
27
src/main/java/autismclient/commands/impl/BindsCommand.java
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.args.KeyArgumentType;
|
||||
import autismclient.modules.AutismModule;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BindsCommand extends Command {
|
||||
public BindsCommand() { super("binds", "List command keybinds (set with `bind`)."); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
Map<Integer, String> binds = AutismModule.get().getCommandBinds();
|
||||
if (binds.isEmpty()) { AutismClientMessaging.sendPrefixed("§eNo command keybinds set."); return SUCCESS; }
|
||||
AutismClientMessaging.sendPrefixed("§e" + binds.size() + " command keybinds:");
|
||||
for (Map.Entry<Integer, String> e : binds.entrySet()) {
|
||||
AutismClientMessaging.sendPrefixed("§b" + KeyArgumentType.keyName(e.getKey()) + "§7 → §f" + e.getValue());
|
||||
}
|
||||
return SUCCESS;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.CommandSuggest;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismInventoryHelper;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public final class ChangeSlotCommand extends Command {
|
||||
public ChangeSlotCommand() {
|
||||
super("change-slot", "Select hotbar slot 1-9.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(context -> {
|
||||
AutismClientMessaging.sendPrefixed(
|
||||
"§eUsage: §f" + AutismCommands.effectivePrefix() + "change-slot <1-9>");
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, Integer>argument(
|
||||
"hotbar-slot", IntegerArgumentType.integer(1, 9))
|
||||
.suggests((context, builder) -> CommandSuggest.literals(
|
||||
builder, "1", "2", "3", "4", "5", "6", "7", "8", "9"))
|
||||
.executes(context -> changeSlot(IntegerArgumentType.getInteger(context, "hotbar-slot"))));
|
||||
}
|
||||
|
||||
private static int changeSlot(int oneBasedSlot) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.player == null || mc.getConnection() == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cNot in a world.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
AutismInventoryHelper.selectHotbarSlot(mc, oneBasedSlot - 1);
|
||||
AutismClientMessaging.sendPrefixed("§aSelected hotbar slot §f" + oneBasedSlot + "§a.");
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
31
src/main/java/autismclient/commands/impl/ClearCommand.java
Normal file
31
src/main/java/autismclient/commands/impl/ClearCommand.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class ClearCommand extends Command {
|
||||
public ClearCommand() { super("clear", "Clear every message from the chat.", "cls"); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.gui == null || mc.gui.hud == null || mc.gui.hud.getChat() == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cChat unavailable.");
|
||||
return SUCCESS;
|
||||
}
|
||||
try {
|
||||
|
||||
mc.gui.hud.getChat().clearMessages(false);
|
||||
mc.gui.hud.getChat().resetChatScroll();
|
||||
} catch (Throwable t) {
|
||||
AutismClientMessaging.sendPrefixed("§cClear failed: " + t.getMessage());
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.args.VisibleItemNameArgumentType;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.macro.ItemTarget;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ContainerInput;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public final class ClickItemCommand extends Command {
|
||||
public ClickItemCommand() {
|
||||
super("click-item", "Click an item by its visible in-game name.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(context -> {
|
||||
AutismClientMessaging.sendPrefixed(
|
||||
"§eUsage: §f" + AutismCommands.effectivePrefix()
|
||||
+ "click-item \"<item name>\" [click] [times]");
|
||||
return SUCCESS;
|
||||
});
|
||||
|
||||
RequiredArgumentBuilder<AutismCommandSource, String> item = RequiredArgumentBuilder
|
||||
.<AutismCommandSource, String>argument("item-name", VisibleItemNameArgumentType.itemName())
|
||||
.executes(context -> click(context, ItemClickCommandSupport.ClickSpec.click(
|
||||
"Left", ContainerInput.PICKUP, 0), 1));
|
||||
ItemClickCommandSupport.attachModes(item, ClickItemCommand::click);
|
||||
root.then(item);
|
||||
}
|
||||
|
||||
private static int click(
|
||||
com.mojang.brigadier.context.CommandContext<AutismCommandSource> context,
|
||||
ItemClickCommandSupport.ClickSpec spec,
|
||||
int times
|
||||
) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.player == null || mc.player.containerMenu == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cNo active inventory or GUI.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
String requestedName = VisibleItemNameArgumentType.get(context, "item-name");
|
||||
int handlerSlot = findByVisibleName(mc.player.containerMenu, requestedName);
|
||||
if (handlerSlot < 0) {
|
||||
AutismClientMessaging.sendPrefixed(
|
||||
"§cNo visible item named §f" + requestedName + "§c exists in the current GUI.");
|
||||
return SUCCESS;
|
||||
}
|
||||
return ItemClickCommandSupport.clickHandlerSlot(
|
||||
handlerSlot, spec, times, "\"" + requestedName + "\"");
|
||||
}
|
||||
|
||||
private static int findByVisibleName(AbstractContainerMenu menu, String requestedName) {
|
||||
String normalizedTarget = ItemTarget.normalize(requestedName);
|
||||
if (normalizedTarget.isEmpty()) return -1;
|
||||
for (int handlerSlot = 0; handlerSlot < menu.slots.size(); handlerSlot++) {
|
||||
ItemStack stack = menu.slots.get(handlerSlot).getItem();
|
||||
if (stack.isEmpty()) continue;
|
||||
if (normalizedTarget.equals(ItemTarget.normalize(stack.getHoverName().getString()))) {
|
||||
return handlerSlot;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.args.MenuSlotArgumentType;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismInventoryHelper;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.inventory.ContainerInput;
|
||||
|
||||
public final class ClickSlotCommand extends Command {
|
||||
public ClickSlotCommand() {
|
||||
super("click-slot", "Click a GUI/player slot with Item Click actions.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(context -> {
|
||||
AutismClientMessaging.sendPrefixed(
|
||||
"§eUsage: §f" + AutismCommands.effectivePrefix() + "click-slot <slot> [click] [times]");
|
||||
return SUCCESS;
|
||||
});
|
||||
|
||||
RequiredArgumentBuilder<AutismCommandSource, Integer> slot = RequiredArgumentBuilder
|
||||
.<AutismCommandSource, Integer>argument("slot", MenuSlotArgumentType.slot())
|
||||
.executes(context -> click(context, ItemClickCommandSupport.ClickSpec.click(
|
||||
"Left", ContainerInput.PICKUP, 0), 1));
|
||||
ItemClickCommandSupport.attachModes(slot, ClickSlotCommand::click);
|
||||
root.then(slot);
|
||||
}
|
||||
|
||||
private static int click(
|
||||
com.mojang.brigadier.context.CommandContext<AutismCommandSource> context,
|
||||
ItemClickCommandSupport.ClickSpec spec,
|
||||
int times
|
||||
) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.player == null || mc.player.containerMenu == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cNo active inventory or GUI.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int visibleSlot = MenuSlotArgumentType.get(context, "slot");
|
||||
int handlerSlot = AutismInventoryHelper.toHandlerSlot(mc, visibleSlot);
|
||||
return ItemClickCommandSupport.clickHandlerSlot(
|
||||
handlerSlot, spec, times, MenuSlotArgumentType.displayToken(visibleSlot));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
public class CommandsCommand extends Command {
|
||||
public CommandsCommand() { super("commands", "List all available commands.", "cmds"); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
String prefix = AutismCommands.effectivePrefix();
|
||||
AutismClientMessaging.sendPrefixed("§e" + AutismCommands.all().size() + " commands (prefix §f" + prefix + "§e):");
|
||||
StringBuilder line = new StringBuilder();
|
||||
for (Command c : AutismCommands.all()) {
|
||||
if (line.length() > 0) line.append("§7, ");
|
||||
line.append("§f").append(c.name());
|
||||
if (line.length() > 200) { AutismClientMessaging.sendPrefixed(line.toString()); line.setLength(0); }
|
||||
}
|
||||
if (line.length() > 0) AutismClientMessaging.sendPrefixed(line.toString());
|
||||
AutismClientMessaging.sendPrefixed("§7Type §f" + prefix + "help <command>§7 for details.");
|
||||
return SUCCESS;
|
||||
});
|
||||
}
|
||||
}
|
||||
56
src/main/java/autismclient/commands/impl/CopyPosCommand.java
Normal file
56
src/main/java/autismclient/commands/impl/CopyPosCommand.java
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.modules.PackFreecamState;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.multi.MultiPilot;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public final class CopyPosCommand extends Command {
|
||||
public CopyPosCommand() {
|
||||
super("copypos", "Copies current coordinates.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
|
||||
if (PackFreecamState.isActive()) {
|
||||
String coordinates = format(PackFreecamState.footPosition(1.0f));
|
||||
if (mc != null && mc.keyboardHandler != null) mc.keyboardHandler.setClipboard(coordinates);
|
||||
AutismClientMessaging.sendPrefixed("§aPosition copied (freecam): §f" + coordinates);
|
||||
return SUCCESS;
|
||||
}
|
||||
Player controlled = MultiPilot.commandPlayer();
|
||||
if (mc == null || controlled == null || mc.keyboardHandler == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cNo controlled position available.");
|
||||
return SUCCESS;
|
||||
}
|
||||
Entity positionOwner = !MultiPilot.isActive() && controlled.getVehicle() != null
|
||||
? controlled.getVehicle() : controlled;
|
||||
String coordinates = format(positionOwner.position());
|
||||
mc.keyboardHandler.setClipboard(coordinates);
|
||||
AutismClientMessaging.sendPrefixed("§aPosition copied: §f" + coordinates);
|
||||
return SUCCESS;
|
||||
});
|
||||
}
|
||||
|
||||
static String format(Vec3 position) {
|
||||
if (position == null) return "0 0 0";
|
||||
return floorCoordinate(position.x) + " " + safeFeetY(position.y) + " " + floorCoordinate(position.z);
|
||||
}
|
||||
|
||||
private static int floorCoordinate(double value) {
|
||||
return Double.isFinite(value) ? (int) Math.floor(value) : 0;
|
||||
}
|
||||
|
||||
private static int safeFeetY(double value) {
|
||||
return Double.isFinite(value) ? (int) Math.ceil(value - 1.0E-7D) : 0;
|
||||
}
|
||||
}
|
||||
32
src/main/java/autismclient/commands/impl/DamageCommand.java
Normal file
32
src/main/java/autismclient/commands/impl/DamageCommand.java
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.CommandSuggest;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import com.mojang.brigadier.arguments.DoubleArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class DamageCommand extends Command {
|
||||
public DamageCommand() { super("damage", "Take damage to self (vanilla server allows via /damage if op)."); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: " + AutismCommands.effectivePrefix() + "damage <amount>");
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, Double>argument("amount", DoubleArgumentType.doubleArg(0.1, 1024.0))
|
||||
.suggests(CommandSuggest::damage)
|
||||
.executes(ctx -> {
|
||||
double amt = DoubleArgumentType.getDouble(ctx, "amount");
|
||||
var conn = Minecraft.getInstance().getConnection();
|
||||
if (conn == null) { AutismClientMessaging.sendPrefixed("§cNot connected."); return SUCCESS; }
|
||||
conn.sendCommand("damage @s " + amt);
|
||||
return SUCCESS;
|
||||
}));
|
||||
}
|
||||
}
|
||||
50
src/main/java/autismclient/commands/impl/DelayCommand.java
Normal file
50
src/main/java/autismclient/commands/impl/DelayCommand.java
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.CommandSuggest;
|
||||
import autismclient.modules.AutismModule;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismSharedState;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
|
||||
public class DelayCommand extends Command {
|
||||
public DelayCommand() { super("delay", "Toggle the GUI packet delay queue."); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> apply(null));
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("state", StringArgumentType.word())
|
||||
.suggests(CommandSuggest::state)
|
||||
.executes(ctx -> apply(StringArgumentType.getString(ctx, "state"))));
|
||||
}
|
||||
|
||||
private static int apply(String state) {
|
||||
boolean current = AutismSharedState.get().shouldDelayGuiPackets();
|
||||
if (state != null) {
|
||||
String lower = state.toLowerCase();
|
||||
if (!lower.equals("on") && !lower.equals("enable") && !lower.equals("true") && !lower.equals("1")
|
||||
&& !lower.equals("off") && !lower.equals("disable") && !lower.equals("false") && !lower.equals("0")
|
||||
&& !lower.equals("toggle")) {
|
||||
AutismClientMessaging.sendPrefixed("Unknown delay state: " + state);
|
||||
AutismClientMessaging.sendPrefixed("Use on, off, or toggle.");
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
boolean target = state == null ? !current
|
||||
: switch (state.toLowerCase()) {
|
||||
case "on", "enable", "true", "1" -> true;
|
||||
case "off", "disable", "false", "0" -> false;
|
||||
case "toggle" -> !current;
|
||||
default -> !current;
|
||||
};
|
||||
|
||||
AutismModule module = AutismModule.get();
|
||||
int flushed = module.applyDelayGuiPacketsUiBehavior(target);
|
||||
module.notifyDelayPacketsUiResult(target, flushed);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
public class DisconnectCommand extends Command {
|
||||
public DisconnectCommand() { super("disconnect", "Disconnect from the current server."); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.getConnection() == null) { AutismClientMessaging.sendPrefixed("§cNot connected."); return SUCCESS; }
|
||||
try {
|
||||
mc.getConnection().getConnection().disconnect(Component.literal("Disconnected via .disconnect"));
|
||||
} catch (Throwable t) {
|
||||
AutismClientMessaging.sendPrefixed("§cDisconnect failed: " + t.getMessage());
|
||||
}
|
||||
return SUCCESS;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket;
|
||||
|
||||
public class DismountCommand extends Command {
|
||||
public DismountCommand() { super("dismount", "Force-dismount from any vehicle."); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.player == null || mc.getConnection() == null) { AutismClientMessaging.sendPrefixed("§cNot in a world."); return SUCCESS; }
|
||||
if (mc.player.getVehicle() == null) { AutismClientMessaging.sendPrefixed("§eNot riding anything."); return SUCCESS; }
|
||||
try {
|
||||
mc.player.removeVehicle();
|
||||
AutismClientMessaging.sendPrefixed("§aDismounted.");
|
||||
} catch (Throwable t) {
|
||||
AutismClientMessaging.sendPrefixed("§cDismount failed: " + t.getMessage());
|
||||
}
|
||||
return SUCCESS;
|
||||
});
|
||||
}
|
||||
}
|
||||
206
src/main/java/autismclient/commands/impl/DropCommand.java
Normal file
206
src/main/java/autismclient/commands/impl/DropCommand.java
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.CommandSuggest;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismDropHelper;
|
||||
import autismclient.util.AutismInventoryHelper;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DropCommand extends Command {
|
||||
public DropCommand() {
|
||||
super("drop", "Drop hand, full inventory, or an amount of a held/specific item.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
showUsage();
|
||||
return SUCCESS;
|
||||
});
|
||||
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("hand")
|
||||
.executes(ctx -> dropHand()));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("fullinventory")
|
||||
.executes(ctx -> dropFullInventory()));
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, Integer>argument(
|
||||
"amount", IntegerArgumentType.integer(1))
|
||||
.suggests(CommandSuggest::counts)
|
||||
.executes(ctx -> dropHeldAmount(IntegerArgumentType.getInteger(ctx, "amount")))
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument(
|
||||
"item", StringArgumentType.word())
|
||||
.suggests(CommandSuggest::itemIds)
|
||||
.executes(ctx -> dropItemAmount(
|
||||
IntegerArgumentType.getInteger(ctx, "amount"),
|
||||
StringArgumentType.getString(ctx, "item")))));
|
||||
}
|
||||
|
||||
private static void showUsage() {
|
||||
String prefix = AutismCommands.effectivePrefix();
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: §f" + prefix + "drop hand");
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: §f" + prefix + "drop fullinventory");
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: §f" + prefix + "drop <amount> [item_id]");
|
||||
}
|
||||
|
||||
private static int dropHand() {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (!ready(mc)) return SUCCESS;
|
||||
|
||||
ItemStack held = mc.player.getMainHandItem();
|
||||
if (held.isEmpty()) {
|
||||
AutismClientMessaging.sendPrefixed("§cYou are not holding an item.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int amount = held.getCount();
|
||||
Identifier id = BuiltInRegistries.ITEM.getKey(held.getItem());
|
||||
mc.player.drop(true);
|
||||
AutismClientMessaging.sendPrefixed("§aDropped §f" + amount + "x " + id + "§a.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private static int dropFullInventory() {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (!ready(mc)) return SUCCESS;
|
||||
|
||||
int droppedItems = 0;
|
||||
int droppedStacks = 0;
|
||||
for (int inventorySlot = 0; inventorySlot < 36; inventorySlot++) {
|
||||
ItemStack stack = mc.player.getInventory().getItem(inventorySlot);
|
||||
if (stack.isEmpty()) continue;
|
||||
|
||||
int handlerSlot = AutismInventoryHelper.toHandlerSlot(mc, inventorySlot);
|
||||
if (handlerSlot < 0) continue;
|
||||
|
||||
int stackCount = stack.getCount();
|
||||
if (AutismDropHelper.dropFromHandlerSlot(mc, handlerSlot, 0) > 0) {
|
||||
droppedItems += stackCount;
|
||||
droppedStacks++;
|
||||
}
|
||||
}
|
||||
|
||||
if (droppedStacks == 0) {
|
||||
AutismClientMessaging.sendPrefixed("§eYour inventory is empty.");
|
||||
} else {
|
||||
AutismClientMessaging.sendPrefixed(
|
||||
"§aDropped §f" + droppedItems + " items §7(" + droppedStacks + " stacks§7)§a.");
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private static int dropHeldAmount(int requested) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (!ready(mc)) return SUCCESS;
|
||||
|
||||
int selectedSlot = mc.player.getInventory().getSelectedSlot();
|
||||
ItemStack held = mc.player.getInventory().getItem(selectedSlot);
|
||||
if (held.isEmpty()) {
|
||||
AutismClientMessaging.sendPrefixed("§cYou are not holding an item.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
Identifier id = BuiltInRegistries.ITEM.getKey(held.getItem());
|
||||
return dropResolvedItemAmount(mc, requested, id, held.getItem());
|
||||
}
|
||||
|
||||
private static int dropItemAmount(int requested, String rawItemId) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (!ready(mc)) return SUCCESS;
|
||||
|
||||
Identifier id = parseItemId(rawItemId);
|
||||
Item item = id == null ? null : BuiltInRegistries.ITEM.getOptional(id).orElse(null);
|
||||
if (item == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cUnknown item id: §f" + rawItemId);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
return dropResolvedItemAmount(mc, requested, id, item);
|
||||
}
|
||||
|
||||
private static int dropResolvedItemAmount(Minecraft mc, int requested, Identifier id, Item item) {
|
||||
List<Integer> matchingSlots = matchingInventorySlots(mc, item);
|
||||
int available = 0;
|
||||
for (int slot : matchingSlots) {
|
||||
available += mc.player.getInventory().getItem(slot).getCount();
|
||||
}
|
||||
if (available == 0) {
|
||||
AutismClientMessaging.sendPrefixed("§cYou do not have §f" + id + "§c in your inventory.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int remaining = Math.min(requested, available);
|
||||
int dropped = 0;
|
||||
for (int inventorySlot : matchingSlots) {
|
||||
if (remaining <= 0) break;
|
||||
ItemStack stack = mc.player.getInventory().getItem(inventorySlot);
|
||||
if (stack.isEmpty() || stack.getItem() != item) continue;
|
||||
|
||||
int amount = Math.min(remaining, stack.getCount());
|
||||
int handlerSlot = AutismInventoryHelper.toHandlerSlot(mc, inventorySlot);
|
||||
if (handlerSlot < 0) continue;
|
||||
if (AutismDropHelper.dropFromHandlerSlot(mc, handlerSlot, amount) == 0) continue;
|
||||
|
||||
dropped += amount;
|
||||
remaining -= amount;
|
||||
}
|
||||
|
||||
if (dropped == 0) {
|
||||
AutismClientMessaging.sendPrefixed("§cCould not drop §f" + id + "§c from the current screen.");
|
||||
} else {
|
||||
reportDrop(id, dropped, requested);
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private static List<Integer> matchingInventorySlots(Minecraft mc, Item item) {
|
||||
List<Integer> slots = new ArrayList<>();
|
||||
int selected = mc.player.getInventory().getSelectedSlot();
|
||||
addIfMatching(mc, item, selected, slots);
|
||||
for (int slot = 0; slot < 9; slot++) {
|
||||
if (slot != selected) addIfMatching(mc, item, slot, slots);
|
||||
}
|
||||
for (int slot = 9; slot < 36; slot++) {
|
||||
addIfMatching(mc, item, slot, slots);
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
|
||||
private static void addIfMatching(Minecraft mc, Item item, int slot, List<Integer> slots) {
|
||||
ItemStack stack = mc.player.getInventory().getItem(slot);
|
||||
if (!stack.isEmpty() && stack.getItem() == item) slots.add(slot);
|
||||
}
|
||||
|
||||
private static Identifier parseItemId(String raw) {
|
||||
if (raw == null || raw.isBlank()) return null;
|
||||
String value = raw.trim().toLowerCase(java.util.Locale.ROOT);
|
||||
return Identifier.tryParse(value.indexOf(':') >= 0 ? value : "minecraft:" + value);
|
||||
}
|
||||
|
||||
private static void reportDrop(Identifier id, int dropped, int requested) {
|
||||
if (dropped < requested) {
|
||||
AutismClientMessaging.sendPrefixed(
|
||||
"§eDropped §f" + dropped + "/" + requested + "x " + id + "§e (all available).");
|
||||
} else {
|
||||
AutismClientMessaging.sendPrefixed("§aDropped §f" + dropped + "x " + id + "§a.");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean ready(Minecraft mc) {
|
||||
if (mc.player != null && mc.gameMode != null) return true;
|
||||
AutismClientMessaging.sendPrefixed("§cNot in a world.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
46
src/main/java/autismclient/commands/impl/FakeGmCommand.java
Normal file
46
src/main/java/autismclient/commands/impl/FakeGmCommand.java
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.CommandSuggest;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismFakeGamemode;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.world.level.GameType;
|
||||
|
||||
public class FakeGmCommand extends Command {
|
||||
public FakeGmCommand() {
|
||||
super("fakegm", "Set a fake client-side game mode.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: " + AutismCommands.effectivePrefix()
|
||||
+ "fakegm <survival|creative|adventure|spectator|reset>");
|
||||
AutismClientMessaging.sendPrefixed("§7Real change: " + AutismCommands.effectivePrefix() + "gamemode");
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("mode", StringArgumentType.word())
|
||||
.suggests(CommandSuggest::gamemodes)
|
||||
.executes(ctx -> {
|
||||
String mode = StringArgumentType.getString(ctx, "mode").toLowerCase(java.util.Locale.ROOT);
|
||||
AutismFakeGamemode.Result result;
|
||||
if ("reset".equals(mode) || "r".equals(mode)) {
|
||||
result = AutismFakeGamemode.reset();
|
||||
} else {
|
||||
GameType resolved = AutismFakeGamemode.parseMode(mode);
|
||||
if (resolved == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cUnknown mode: §f" + mode);
|
||||
return SUCCESS;
|
||||
}
|
||||
result = AutismFakeGamemode.apply(resolved);
|
||||
}
|
||||
AutismClientMessaging.sendPrefixed((result.success() ? "§a" : "§c") + result.message());
|
||||
return SUCCESS;
|
||||
}));
|
||||
}
|
||||
}
|
||||
71
src/main/java/autismclient/commands/impl/FriendCommand.java
Normal file
71
src/main/java/autismclient/commands/impl/FriendCommand.java
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.modules.TeamsModule;
|
||||
import autismclient.util.AutismPlayerScanner;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public final class FriendCommand extends Command {
|
||||
public FriendCommand() {
|
||||
super("friend", "Manage the friends/teams list. add <name>, remove <name>, clear.", "team");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
|
||||
root.executes(ctx -> listFriends());
|
||||
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("add")
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("name", StringArgumentType.word())
|
||||
.suggests(FriendCommand::suggestServerPlayers)
|
||||
.executes(ctx -> TeamsModule.addFriend(StringArgumentType.getString(ctx, "name")) ? SUCCESS : 0)));
|
||||
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("remove")
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("name", StringArgumentType.word())
|
||||
.suggests(FriendCommand::suggestFriends)
|
||||
.executes(ctx -> TeamsModule.removeFriend(StringArgumentType.getString(ctx, "name")) ? SUCCESS : 0)));
|
||||
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("clear")
|
||||
.executes(ctx -> TeamsModule.clearFriends() ? SUCCESS : 0));
|
||||
}
|
||||
|
||||
private static int listFriends() {
|
||||
List<String> friends = TeamsModule.storedFriendNames();
|
||||
if (friends.isEmpty()) {
|
||||
autismclient.util.AutismClientMessaging.sendPrefixed("§7Friend list is empty.");
|
||||
return SUCCESS;
|
||||
}
|
||||
autismclient.util.AutismClientMessaging.sendPrefixed("§7Friends (§f" + friends.size() + "§7): §f" + String.join("§7, §f", friends));
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private static CompletableFuture<Suggestions> suggestServerPlayers(CommandContext<AutismCommandSource> ctx,
|
||||
SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
for (AutismPlayerScanner.ScannedPlayer player : AutismPlayerScanner.scan(Minecraft.getInstance())) {
|
||||
String name = player.name();
|
||||
if (name != null && name.toLowerCase(Locale.ROOT).startsWith(remaining)) builder.suggest(name);
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
|
||||
private static CompletableFuture<Suggestions> suggestFriends(CommandContext<AutismCommandSource> ctx,
|
||||
SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
for (String name : TeamsModule.storedFriendNames()) {
|
||||
if (name != null && name.toLowerCase(Locale.ROOT).startsWith(remaining)) builder.suggest(name);
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.CommandSuggest;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismFakeGamemode;
|
||||
import autismclient.util.AutismGamemode;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.world.level.GameType;
|
||||
|
||||
public class GamemodeCommand extends Command {
|
||||
public GamemodeCommand() {
|
||||
super("gamemode", "Set your real game mode (no chat command sent).");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: " + AutismCommands.effectivePrefix()
|
||||
+ "gamemode <survival|creative|adventure|spectator>");
|
||||
AutismClientMessaging.sendPrefixed("§7Client-side only: " + AutismCommands.effectivePrefix() + "fakegm");
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("mode", StringArgumentType.word())
|
||||
.suggests(CommandSuggest::realGamemodes)
|
||||
.executes(ctx -> {
|
||||
String mode = StringArgumentType.getString(ctx, "mode").toLowerCase(java.util.Locale.ROOT);
|
||||
GameType resolved = AutismFakeGamemode.parseMode(mode);
|
||||
if (resolved == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cUnknown mode: §f" + mode);
|
||||
if ("reset".equals(mode) || "r".equals(mode)) {
|
||||
AutismClientMessaging.sendPrefixed("§7Reset only applies to the fake mode: §f"
|
||||
+ AutismCommands.effectivePrefix() + "fakegm reset");
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
AutismFakeGamemode.Result result = AutismGamemode.real(resolved);
|
||||
AutismClientMessaging.sendPrefixed((result.success() ? "§a" : "§c") + result.message());
|
||||
return SUCCESS;
|
||||
}));
|
||||
}
|
||||
}
|
||||
123
src/main/java/autismclient/commands/impl/GhostBlockCommand.java
Normal file
123
src/main/java/autismclient/commands/impl/GhostBlockCommand.java
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.CommandSuggest;
|
||||
import autismclient.modules.GhostBlockModule;
|
||||
import autismclient.modules.Module;
|
||||
import autismclient.modules.ModuleRegistry;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
public class GhostBlockCommand extends Command {
|
||||
public GhostBlockCommand() {
|
||||
super("ghostblock", "Client-side ghost blocks: place, remove and manage blocks only you can see.", "gb");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
String prefix = AutismCommands.effectivePrefix();
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: " + prefix + "ghostblock <toggle|reset|creative|block>");
|
||||
AutismClientMessaging.sendPrefixed("§7" + prefix + "ghostblock toggle §8- §7toggle the module");
|
||||
AutismClientMessaging.sendPrefixed("§7" + prefix + "ghostblock reset §8- §7remove all ghost blocks");
|
||||
AutismClientMessaging.sendPrefixed("§7" + prefix + "ghostblock creative [on|off] §8- §7fake creative gamemode");
|
||||
AutismClientMessaging.sendPrefixed("§7" + prefix + "ghostblock block [id|off] §8- §7arm a block for placement");
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("toggle")
|
||||
.executes(ctx -> {
|
||||
GhostBlockModule module = module();
|
||||
if (module == null) return SUCCESS;
|
||||
module.toggle();
|
||||
return SUCCESS;
|
||||
}));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("reset")
|
||||
.executes(ctx -> {
|
||||
GhostBlockModule module = module();
|
||||
if (module == null) return SUCCESS;
|
||||
int removed = module.restoreAll();
|
||||
AutismClientMessaging.sendPrefixed(removed == 0
|
||||
? "§7No ghost blocks to remove."
|
||||
: "§aRemoved §f" + removed + "§a ghost block" + (removed == 1 ? "" : "s")
|
||||
+ " and restored the original states.");
|
||||
return SUCCESS;
|
||||
}));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("creative")
|
||||
.executes(ctx -> setCreative(null))
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("state", StringArgumentType.word())
|
||||
.suggests(CommandSuggest::state)
|
||||
.executes(ctx -> setCreative(StringArgumentType.getString(ctx, "state")))));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("block")
|
||||
.executes(ctx -> {
|
||||
GhostBlockModule module = module();
|
||||
if (module == null) return SUCCESS;
|
||||
Block armed = module.armedBlock();
|
||||
AutismClientMessaging.sendPrefixed(armed == null
|
||||
? "§7No ghost block armed."
|
||||
: "§7Armed ghost block: §f" + BuiltInRegistries.BLOCK.getKey(armed));
|
||||
return SUCCESS;
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("block", StringArgumentType.word())
|
||||
.suggests(CommandSuggest::blockIds)
|
||||
.executes(ctx -> arm(StringArgumentType.getString(ctx, "block")))));
|
||||
}
|
||||
|
||||
private static int setCreative(String state) {
|
||||
GhostBlockModule module = module();
|
||||
if (module == null) return SUCCESS;
|
||||
boolean target;
|
||||
if (state == null || "toggle".equalsIgnoreCase(state)) {
|
||||
target = !module.isCreative();
|
||||
} else if ("on".equalsIgnoreCase(state) || "enable".equalsIgnoreCase(state)) {
|
||||
target = true;
|
||||
} else if ("off".equalsIgnoreCase(state) || "disable".equalsIgnoreCase(state)) {
|
||||
target = false;
|
||||
} else {
|
||||
AutismClientMessaging.sendPrefixed("§cUnknown state: §f" + state);
|
||||
return SUCCESS;
|
||||
}
|
||||
module.setCreative(target);
|
||||
if (target && !module.isEnabled()) module.setEnabled(true);
|
||||
AutismClientMessaging.sendPrefixed(target
|
||||
? "§aFake creative on. §7Whatever you place becomes a ghost block."
|
||||
: "§7Fake creative off. §7Back to your real gamemode.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private static int arm(String input) {
|
||||
GhostBlockModule module = module();
|
||||
if (module == null) return SUCCESS;
|
||||
String value = input.toLowerCase(Locale.ROOT);
|
||||
if ("off".equals(value) || "none".equals(value) || "reset".equals(value)) {
|
||||
module.setArmedBlock(null, false);
|
||||
AutismClientMessaging.sendPrefixed("§7Ghost block disarmed; held blocks place ghosts again.");
|
||||
return SUCCESS;
|
||||
}
|
||||
Identifier id = Identifier.tryParse(value.contains(":") ? value : "minecraft:" + value);
|
||||
Block block = id == null ? null : BuiltInRegistries.BLOCK.getOptional(id).orElse(null);
|
||||
if (block == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cUnknown block: §f" + input);
|
||||
return SUCCESS;
|
||||
}
|
||||
module.setArmedBlock(block, false);
|
||||
if (!module.isEnabled()) module.setEnabled(true);
|
||||
AutismClientMessaging.sendPrefixed("§aGhost block: §f" + BuiltInRegistries.BLOCK.getKey(block)
|
||||
+ (module.isCreative() ? "" : " §7(switch Mode to Creative to place it)"));
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private static GhostBlockModule module() {
|
||||
Module module = ModuleRegistry.get("ghostblock");
|
||||
if (module instanceof GhostBlockModule ghostBlock) return ghostBlock;
|
||||
AutismClientMessaging.sendPrefixed("§cGhostBlock module is not available.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
59
src/main/java/autismclient/commands/impl/GiveCommand.java
Normal file
59
src/main/java/autismclient/commands/impl/GiveCommand.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.CommandSuggest;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.protocol.game.ServerboundSetCreativeModeSlotPacket;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class GiveCommand extends Command {
|
||||
public GiveCommand() { super("give", "Give item to self (creative only)."); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: " + AutismCommands.effectivePrefix() + "give <item> [count]");
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("item", StringArgumentType.word())
|
||||
.suggests(CommandSuggest::itemIds)
|
||||
.executes(ctx -> give(StringArgumentType.getString(ctx, "item"), 1))
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Integer>argument("count", IntegerArgumentType.integer(1, 64))
|
||||
.suggests(CommandSuggest::counts)
|
||||
.executes(ctx -> give(StringArgumentType.getString(ctx, "item"), IntegerArgumentType.getInteger(ctx, "count")))));
|
||||
}
|
||||
|
||||
private static int give(String itemId, int count) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
boolean pov = autismclient.util.multi.MultiPilot.isActive();
|
||||
if (!pov && mc.player == null) { AutismClientMessaging.sendPrefixed("§cNot in a world."); return SUCCESS; }
|
||||
if (!pov && !mc.player.getAbilities().instabuild) { AutismClientMessaging.sendPrefixed("§cCreative mode required."); return SUCCESS; }
|
||||
Identifier id = itemId.contains(":") ? Identifier.tryParse(itemId) : Identifier.tryParse("minecraft:" + itemId);
|
||||
if (id == null) { AutismClientMessaging.sendPrefixed("§cInvalid item id: §f" + itemId); return SUCCESS; }
|
||||
Item item = BuiltInRegistries.ITEM.getOptional(id).orElse(null);
|
||||
if (item == null) { AutismClientMessaging.sendPrefixed("§cUnknown item: §f" + id); return SUCCESS; }
|
||||
ItemStack stack = new ItemStack(item, count);
|
||||
String povResult = autismclient.util.multi.MultiPilot.commandGiveCreative(stack);
|
||||
if (povResult != null) {
|
||||
AutismClientMessaging.sendPrefixed(("Sent".equals(povResult) ? "§a" : "§c")
|
||||
+ "POV give: §f" + povResult);
|
||||
return SUCCESS;
|
||||
}
|
||||
int slot = mc.player.getInventory().getSelectedSlot();
|
||||
int containerSlot = 36 + slot;
|
||||
mc.getConnection().send(new ServerboundSetCreativeModeSlotPacket((short) containerSlot, stack));
|
||||
mc.player.getInventory().setItem(slot, stack);
|
||||
AutismClientMessaging.sendPrefixed("§aGave §f" + id + " x" + count);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
132
src/main/java/autismclient/commands/impl/HClipCommand.java
Normal file
132
src/main/java/autismclient/commands/impl/HClipCommand.java
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.CommandSuggest;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.macro.HClipAction;
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
import com.mojang.brigadier.arguments.DoubleArgumentType;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class HClipCommand extends Command {
|
||||
public HClipCommand() {
|
||||
super("hclip", "Lets you clip through blocks horizontally (forward) with movement packets.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
String prefix = AutismCommands.effectivePrefix();
|
||||
AutismClientMessaging.sendPrefixed("\u00a7eUsage: \u00a7f" + prefix + "hclip <blocks>");
|
||||
AutismClientMessaging.sendPrefixed("\u00a77Modes: \u00a7fdefault, forward, back, padding, single, custom (paper alias still works)");
|
||||
AutismClientMessaging.sendPrefixed("\u00a77Examples: \u00a7f" + prefix + "hclip forward \u00a77or \u00a7f" + prefix + "hclip custom -25 10 20 true true true");
|
||||
return SUCCESS;
|
||||
});
|
||||
|
||||
root.then(blocksArgument("blocks", options -> options));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("forward")
|
||||
.executes(ctx -> {
|
||||
HClipAction.Options options = HClipAction.Options.defaults(0.0);
|
||||
options.mode = HClipAction.Mode.FORWARD;
|
||||
run(options);
|
||||
return SUCCESS;
|
||||
}));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("back")
|
||||
.executes(ctx -> {
|
||||
HClipAction.Options options = HClipAction.Options.defaults(0.0);
|
||||
options.mode = HClipAction.Mode.BACK;
|
||||
run(options);
|
||||
return SUCCESS;
|
||||
}));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("default")
|
||||
.then(blocksArgument("blocks", options -> options)));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("paper")
|
||||
.then(blocksArgument("blocks", options -> options)));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("padding")
|
||||
.then(blocksArgument("blocks", options -> options)));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("single")
|
||||
.then(blocksArgument("blocks", HClipAction.Options::singlePacket)));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("normal")
|
||||
.then(blocksArgument("blocks", HClipAction.Options::singlePacket)));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("custom")
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Double>argument("blocks", DoubleArgumentType.doubleArg())
|
||||
.suggests(CommandSuggest::offsets)
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Integer>argument("segment", IntegerArgumentType.integer(1, 50))
|
||||
.suggests(CommandSuggest::vclipSegments)
|
||||
.executes(ctx -> {
|
||||
HClipAction.Options options = HClipAction.Options.defaults(DoubleArgumentType.getDouble(ctx, "blocks"));
|
||||
options.segmentBlocks = IntegerArgumentType.getInteger(ctx, "segment");
|
||||
run(options);
|
||||
return SUCCESS;
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Integer>argument("maxPackets", IntegerArgumentType.integer(1, 100))
|
||||
.suggests(CommandSuggest::vclipPacketLimits)
|
||||
.executes(ctx -> {
|
||||
HClipAction.Options options = HClipAction.Options.defaults(DoubleArgumentType.getDouble(ctx, "blocks"));
|
||||
options.segmentBlocks = IntegerArgumentType.getInteger(ctx, "segment");
|
||||
options.maxPackets = IntegerArgumentType.getInteger(ctx, "maxPackets");
|
||||
run(options);
|
||||
return SUCCESS;
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Boolean>argument("updateLocal", BoolArgumentType.bool())
|
||||
.executes(ctx -> {
|
||||
HClipAction.Options options = customOptions(ctx);
|
||||
options.updateLocalPosition = BoolArgumentType.getBool(ctx, "updateLocal");
|
||||
run(options);
|
||||
return SUCCESS;
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Boolean>argument("vehicle", BoolArgumentType.bool())
|
||||
.executes(ctx -> {
|
||||
HClipAction.Options options = customOptions(ctx);
|
||||
options.updateLocalPosition = BoolArgumentType.getBool(ctx, "updateLocal");
|
||||
options.tryVehicleFirst = BoolArgumentType.getBool(ctx, "vehicle");
|
||||
run(options);
|
||||
return SUCCESS;
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Boolean>argument("forceGround", BoolArgumentType.bool())
|
||||
.executes(ctx -> {
|
||||
HClipAction.Options options = customOptions(ctx);
|
||||
options.updateLocalPosition = BoolArgumentType.getBool(ctx, "updateLocal");
|
||||
options.tryVehicleFirst = BoolArgumentType.getBool(ctx, "vehicle");
|
||||
options.forceGrounded = BoolArgumentType.getBool(ctx, "forceGround");
|
||||
run(options);
|
||||
return SUCCESS;
|
||||
}))))))));
|
||||
}
|
||||
|
||||
private interface OptionsCustomizer {
|
||||
HClipAction.Options apply(HClipAction.Options options);
|
||||
}
|
||||
|
||||
private static RequiredArgumentBuilder<AutismCommandSource, Double> blocksArgument(String name, OptionsCustomizer customizer) {
|
||||
return RequiredArgumentBuilder.<AutismCommandSource, Double>argument(name, DoubleArgumentType.doubleArg())
|
||||
.suggests(CommandSuggest::offsets)
|
||||
.executes(ctx -> {
|
||||
HClipAction.Options options = HClipAction.Options.defaults(DoubleArgumentType.getDouble(ctx, name));
|
||||
run(customizer.apply(options));
|
||||
return SUCCESS;
|
||||
});
|
||||
}
|
||||
|
||||
private static HClipAction.Options customOptions(com.mojang.brigadier.context.CommandContext<AutismCommandSource> ctx) {
|
||||
HClipAction.Options options = HClipAction.Options.defaults(DoubleArgumentType.getDouble(ctx, "blocks"));
|
||||
options.segmentBlocks = IntegerArgumentType.getInteger(ctx, "segment");
|
||||
options.maxPackets = IntegerArgumentType.getInteger(ctx, "maxPackets");
|
||||
options.maxRoutePackets = options.maxPackets;
|
||||
return options;
|
||||
}
|
||||
|
||||
public static void hclip(double blocks) {
|
||||
run(HClipAction.Options.defaults(blocks));
|
||||
}
|
||||
|
||||
private static void run(HClipAction.Options options) {
|
||||
options.showMessage = true;
|
||||
HClipAction.perform(Minecraft.getInstance(), options);
|
||||
}
|
||||
}
|
||||
46
src/main/java/autismclient/commands/impl/HelpCommand.java
Normal file
46
src/main/java/autismclient/commands/impl/HelpCommand.java
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import java.util.Locale;
|
||||
|
||||
public class HelpCommand extends Command {
|
||||
public HelpCommand() { super("help", "Show usage info for a command (or list all)."); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> { listAll(); return SUCCESS; });
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("command", StringArgumentType.word())
|
||||
.suggests((ctx, builder) -> {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
for (Command command : AutismCommands.all()) {
|
||||
if (command.name().toLowerCase(Locale.ROOT).startsWith(remaining)) builder.suggest(command.name());
|
||||
for (String alias : command.aliases()) {
|
||||
if (alias != null && alias.toLowerCase(Locale.ROOT).startsWith(remaining)) builder.suggest(alias);
|
||||
}
|
||||
}
|
||||
return builder.buildFuture();
|
||||
})
|
||||
.executes(ctx -> {
|
||||
String name = StringArgumentType.getString(ctx, "command");
|
||||
Command cmd = AutismCommands.find(name);
|
||||
if (cmd == null) { AutismClientMessaging.sendPrefixed("§cNo such command: §f" + name); return SUCCESS; }
|
||||
String prefix = AutismCommands.effectivePrefix();
|
||||
AutismClientMessaging.sendPrefixed("§b" + prefix + cmd.name() + " §7" + cmd.description());
|
||||
if (cmd.aliases().length > 0) AutismClientMessaging.sendPrefixed("§7aliases: §f" + String.join(", ", cmd.aliases()));
|
||||
return SUCCESS;
|
||||
}));
|
||||
}
|
||||
|
||||
private static void listAll() {
|
||||
String prefix = AutismCommands.effectivePrefix();
|
||||
for (Command c : AutismCommands.all()) {
|
||||
AutismClientMessaging.sendPrefixed("§b" + prefix + c.name() + "§7 - " + c.description());
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/main/java/autismclient/commands/impl/IrcCommand.java
Normal file
34
src/main/java/autismclient/commands/impl/IrcCommand.java
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.mm.MatchmakingManager;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
|
||||
public class IrcCommand extends Command {
|
||||
public IrcCommand() { super("irc", "Send a message to the Matchmaking lobby chat."); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: " + AutismCommands.effectivePrefix() + "irc <message>");
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("message", StringArgumentType.greedyString())
|
||||
.executes(ctx -> {
|
||||
String msg = StringArgumentType.getString(ctx, "message");
|
||||
MatchmakingManager mm = MatchmakingManager.get();
|
||||
if (!mm.inLobby()) {
|
||||
AutismClientMessaging.sendPrefixed("§cNot in a lobby. Open Matchmaking and join or create one first.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
mm.sendChat(msg);
|
||||
return SUCCESS;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,149 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.CommandSuggest;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismDropHelper;
|
||||
import autismclient.util.AutismInventoryClickHelper;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.inventory.ContainerInput;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
final class ItemClickCommandSupport {
|
||||
static final int MAX_REPEAT_COUNT = 100_000;
|
||||
|
||||
private ItemClickCommandSupport() {
|
||||
}
|
||||
|
||||
record ClickSpec(String label, ContainerInput input, int button, DropMode dropMode) {
|
||||
static ClickSpec click(String label, ContainerInput input, int button) {
|
||||
return new ClickSpec(label, input, button, DropMode.NONE);
|
||||
}
|
||||
|
||||
static ClickSpec drop(String label, DropMode dropMode) {
|
||||
return new ClickSpec(label, ContainerInput.THROW, dropMode == DropMode.STACK ? 1 : 0, dropMode);
|
||||
}
|
||||
}
|
||||
|
||||
enum DropMode {
|
||||
NONE,
|
||||
ITEM,
|
||||
STACK
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface ClickExecutor {
|
||||
int execute(CommandContext<AutismCommandSource> context, ClickSpec spec, int times);
|
||||
}
|
||||
|
||||
static void attachModes(ArgumentBuilder<AutismCommandSource, ?> target, ClickExecutor executor) {
|
||||
target.then(repeated("left", ClickSpec.click("Left", ContainerInput.PICKUP, 0), executor));
|
||||
target.then(repeated("right", ClickSpec.click("Right", ContainerInput.PICKUP, 1), executor));
|
||||
target.then(repeated("middle", ClickSpec.click("Middle", ContainerInput.PICKUP, 2), executor));
|
||||
target.then(repeated("shift-left", ClickSpec.click("Shift Left", ContainerInput.QUICK_MOVE, 0), executor));
|
||||
target.then(repeated("shift-right", ClickSpec.click("Shift Right", ContainerInput.QUICK_MOVE, 1), executor));
|
||||
target.then(repeated("clone", ClickSpec.click("Clone", ContainerInput.CLONE, 2), executor));
|
||||
target.then(repeated("pickup-all", ClickSpec.click("Pick Up All", ContainerInput.PICKUP_ALL, 0), executor));
|
||||
target.then(repeated("drop-item", ClickSpec.drop("Drop Item", DropMode.ITEM), executor));
|
||||
target.then(single("drop-stack", ClickSpec.drop("Drop Stack", DropMode.STACK), executor));
|
||||
|
||||
LiteralArgumentBuilder<AutismCommandSource> swap = LiteralArgumentBuilder.literal("swap");
|
||||
RequiredArgumentBuilder<AutismCommandSource, Integer> hotbar = RequiredArgumentBuilder
|
||||
.<AutismCommandSource, Integer>argument("swap-hotbar", IntegerArgumentType.integer(1, 9))
|
||||
.suggests((context, builder) -> CommandSuggest.literals(
|
||||
builder, "1", "2", "3", "4", "5", "6", "7", "8", "9"))
|
||||
.executes(context -> executor.execute(
|
||||
context,
|
||||
ClickSpec.click("Swap " + IntegerArgumentType.getInteger(context, "swap-hotbar"),
|
||||
ContainerInput.SWAP,
|
||||
IntegerArgumentType.getInteger(context, "swap-hotbar") - 1),
|
||||
1));
|
||||
hotbar.then(timesArgument((context, times) -> executor.execute(
|
||||
context,
|
||||
ClickSpec.click("Swap " + IntegerArgumentType.getInteger(context, "swap-hotbar"),
|
||||
ContainerInput.SWAP,
|
||||
IntegerArgumentType.getInteger(context, "swap-hotbar") - 1),
|
||||
times)));
|
||||
swap.then(hotbar);
|
||||
target.then(swap);
|
||||
}
|
||||
|
||||
static int clickHandlerSlot(int handlerSlot, ClickSpec spec, int times, String targetLabel) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc.player == null || mc.gameMode == null || mc.getConnection() == null || mc.player.containerMenu == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cNo active inventory or GUI.");
|
||||
return 1;
|
||||
}
|
||||
if (handlerSlot < 0 || handlerSlot >= mc.player.containerMenu.slots.size()) {
|
||||
AutismClientMessaging.sendPrefixed("§cThat slot does not exist in the current GUI.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int requested = Math.max(1, times);
|
||||
int completed = 0;
|
||||
if (spec.dropMode() == DropMode.ITEM) {
|
||||
ItemStack stack = mc.player.containerMenu.slots.get(handlerSlot).getItem();
|
||||
if (!stack.isEmpty()) {
|
||||
int actual = Math.min(requested, stack.getCount());
|
||||
if (AutismDropHelper.dropFromHandlerSlot(mc, handlerSlot, actual) > 0) completed = actual;
|
||||
}
|
||||
} else if (spec.dropMode() == DropMode.STACK) {
|
||||
completed = AutismDropHelper.dropFromHandlerSlot(mc, handlerSlot, 0) > 0 ? 1 : 0;
|
||||
} else {
|
||||
for (int i = 0; i < requested; i++) {
|
||||
if (!AutismInventoryClickHelper.click(mc, handlerSlot, spec.button(), spec.input())) {
|
||||
break;
|
||||
}
|
||||
completed++;
|
||||
}
|
||||
}
|
||||
|
||||
if (completed == 0) {
|
||||
AutismClientMessaging.sendPrefixed("§cCould not click §f" + targetLabel + "§c.");
|
||||
} else {
|
||||
String repeat = completed > 1 && spec.dropMode() != DropMode.STACK ? " x" + completed : "";
|
||||
String partial = completed < requested && spec.dropMode() != DropMode.STACK
|
||||
? " §e(" + completed + "/" + requested + ")"
|
||||
: "";
|
||||
AutismClientMessaging.sendPrefixed(
|
||||
"§a" + spec.label() + " clicked §f" + targetLabel + "§a" + repeat + "." + partial);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
private static LiteralArgumentBuilder<AutismCommandSource> repeated(
|
||||
String literal,
|
||||
ClickSpec spec,
|
||||
ClickExecutor executor
|
||||
) {
|
||||
LiteralArgumentBuilder<AutismCommandSource> node = single(literal, spec, executor);
|
||||
node.then(timesArgument((context, times) -> executor.execute(context, spec, times)));
|
||||
return node;
|
||||
}
|
||||
|
||||
private static LiteralArgumentBuilder<AutismCommandSource> single(
|
||||
String literal,
|
||||
ClickSpec spec,
|
||||
ClickExecutor executor
|
||||
) {
|
||||
return LiteralArgumentBuilder.<AutismCommandSource>literal(literal)
|
||||
.executes(context -> executor.execute(context, spec, 1));
|
||||
}
|
||||
|
||||
private static RequiredArgumentBuilder<AutismCommandSource, Integer> timesArgument(TimesExecutor executor) {
|
||||
return RequiredArgumentBuilder.<AutismCommandSource, Integer>argument(
|
||||
"times", IntegerArgumentType.integer(1, MAX_REPEAT_COUNT))
|
||||
.suggests(CommandSuggest::counts)
|
||||
.executes(context -> executor.execute(context, IntegerArgumentType.getInteger(context, "times")));
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface TimesExecutor {
|
||||
int execute(CommandContext<AutismCommandSource> context, int times);
|
||||
}
|
||||
}
|
||||
197
src/main/java/autismclient/commands/impl/MacroCommand.java
Normal file
197
src/main/java/autismclient/commands/impl/MacroCommand.java
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.args.MacroArgumentType;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismMacroManager;
|
||||
import autismclient.util.macro.MacroExecutor;
|
||||
import autismclient.util.multi.MultiManager;
|
||||
import autismclient.util.multi.MultiTakeoverState;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.Set;
|
||||
|
||||
public class MacroCommand extends Command {
|
||||
private static final ConcurrentHashMap<String, AtomicBoolean> RUNNING_LOOPS = new ConcurrentHashMap<>();
|
||||
|
||||
public MacroCommand() { super("macro", "Run a macro, optionally N times with a delay between starts."); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
String prefix = AutismCommands.effectivePrefix();
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: §f" + prefix + "macro <name> [times] [delayTicks]");
|
||||
AutismClientMessaging.sendPrefixed("§7Also: §f" + prefix + "macro stop [name] §7or §f" + prefix + "macro clear");
|
||||
return SUCCESS;
|
||||
});
|
||||
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("stop")
|
||||
.executes(ctx -> {
|
||||
String pov = MultiTakeoverState.activeAccountId();
|
||||
if (pov != null) {
|
||||
stopPovLoops(pov);
|
||||
MultiManager mgr = MultiManager.getIfInitialized();
|
||||
MultiManager.BroadcastResult result = mgr == null
|
||||
? new MultiManager.BroadcastResult(0, 1, 0, java.util.List.of("Multi unavailable"))
|
||||
: mgr.stopMacroOnScope(Set.of(pov));
|
||||
AutismClientMessaging.sendPrefixed("§ePOV macro stop: §f" + result.summary());
|
||||
return SUCCESS;
|
||||
}
|
||||
stopAllLoops();
|
||||
AutismMacroManager.get().stopMacro();
|
||||
AutismClientMessaging.sendPrefixed("§eStopped all macros.");
|
||||
return SUCCESS;
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("name", MacroArgumentType.macroName())
|
||||
.executes(ctx -> {
|
||||
String name = MacroArgumentType.get(ctx, "name");
|
||||
String pov = MultiTakeoverState.activeAccountId();
|
||||
if (pov != null) {
|
||||
AtomicBoolean flag = RUNNING_LOOPS.remove(povLoopKey(pov, name));
|
||||
if (flag != null) flag.set(false);
|
||||
MultiManager mgr = MultiManager.getIfInitialized();
|
||||
MultiManager.BroadcastResult result = mgr == null
|
||||
? new MultiManager.BroadcastResult(0, 1, 0, java.util.List.of("Multi unavailable"))
|
||||
: mgr.stopMacroOnScope(Set.of(pov));
|
||||
AutismClientMessaging.sendPrefixed("§eStopped POV macro §f" + name + "§e: " + result.summary());
|
||||
return SUCCESS;
|
||||
}
|
||||
AtomicBoolean flag = RUNNING_LOOPS.remove(name.toLowerCase());
|
||||
if (flag != null) flag.set(false);
|
||||
MacroExecutor.stopMacro(name);
|
||||
AutismClientMessaging.sendPrefixed("§eStopped: §f" + name);
|
||||
return SUCCESS;
|
||||
})));
|
||||
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("clear")
|
||||
.executes(ctx -> {
|
||||
String pov = MultiTakeoverState.activeAccountId();
|
||||
if (pov != null) {
|
||||
stopPovLoops(pov);
|
||||
AutismClientMessaging.sendPrefixed("§eCleared POV macro loops for §f" + pov + "§e.");
|
||||
} else {
|
||||
stopAllLoops();
|
||||
AutismClientMessaging.sendPrefixed("§eCleared macro loops.");
|
||||
}
|
||||
return SUCCESS;
|
||||
}));
|
||||
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("name", MacroArgumentType.macroName())
|
||||
.executes(ctx -> startLoop(MacroArgumentType.get(ctx, "name"), 1, 0))
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Integer>argument("times", IntegerArgumentType.integer(1, 100_000))
|
||||
.executes(ctx -> startLoop(MacroArgumentType.get(ctx, "name"), IntegerArgumentType.getInteger(ctx, "times"), 0))
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Integer>argument("delayTicks", IntegerArgumentType.integer(0, 20 * 60 * 60))
|
||||
.executes(ctx -> startLoop(
|
||||
MacroArgumentType.get(ctx, "name"),
|
||||
IntegerArgumentType.getInteger(ctx, "times"),
|
||||
IntegerArgumentType.getInteger(ctx, "delayTicks"))))));
|
||||
}
|
||||
|
||||
private static int startLoop(String name, int times, int delayTicks) {
|
||||
autismclient.util.AutismMacro macro = AutismMacroManager.get().get(name);
|
||||
if (macro == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cMacro not found: §f" + name);
|
||||
return SUCCESS;
|
||||
}
|
||||
String pov = MultiTakeoverState.activeAccountId();
|
||||
if (pov != null) return startPovLoop(name, macro, times, delayTicks, pov);
|
||||
if (times <= 1 && delayTicks <= 0) {
|
||||
AutismMacroManager.get().executeMacro(name);
|
||||
return SUCCESS;
|
||||
}
|
||||
AtomicBoolean flag = new AtomicBoolean(true);
|
||||
RUNNING_LOOPS.put(name.toLowerCase(), flag);
|
||||
long sleepMs = Math.max(0L, delayTicks * 50L);
|
||||
final int totalTimes = Math.max(1, times);
|
||||
Thread t = new Thread(() -> {
|
||||
try {
|
||||
for (int i = 0; i < totalTimes && flag.get(); i++) {
|
||||
AutismMacroManager.get().executeMacro(name);
|
||||
|
||||
long start = System.nanoTime();
|
||||
long waitTimeoutNanos = 24L * 60L * 60L * 1_000_000_000L;
|
||||
while (MacroExecutor.isMacroRunning(name) && flag.get()
|
||||
&& System.nanoTime() - start < waitTimeoutNanos) {
|
||||
Thread.sleep(50);
|
||||
}
|
||||
if (!flag.get()) break;
|
||||
if (i + 1 < totalTimes && sleepMs > 0) Thread.sleep(sleepMs);
|
||||
}
|
||||
} catch (InterruptedException ignored) { Thread.currentThread().interrupt(); }
|
||||
finally { RUNNING_LOOPS.remove(name.toLowerCase(), flag); }
|
||||
}, "MacroLoop-" + name);
|
||||
t.setDaemon(true);
|
||||
t.start();
|
||||
AutismClientMessaging.sendPrefixed("§aQueued " + totalTimes + "x §f" + name + "§a (delay " + delayTicks + "t)");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private static int startPovLoop(String name, autismclient.util.AutismMacro macro, int times,
|
||||
int delayTicks, String accountId) {
|
||||
MultiManager mgr = MultiManager.getIfInitialized();
|
||||
if (mgr == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cMulti is unavailable.");
|
||||
return SUCCESS;
|
||||
}
|
||||
Set<String> scope = Set.of(accountId);
|
||||
if (times <= 1 && delayTicks <= 0) {
|
||||
MultiManager.BroadcastResult result = mgr.runMacroDirect(macro, scope);
|
||||
AutismClientMessaging.sendPrefixed((result.sent() > 0 ? "§a" : "§c")
|
||||
+ "POV macro §f" + name + "§a: " + result.summary());
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
String key = povLoopKey(accountId, name);
|
||||
AtomicBoolean flag = new AtomicBoolean(true);
|
||||
AtomicBoolean previous = RUNNING_LOOPS.put(key, flag);
|
||||
if (previous != null) previous.set(false);
|
||||
long sleepMs = Math.max(0L, delayTicks * 50L);
|
||||
int totalTimes = Math.max(1, times);
|
||||
Thread thread = new Thread(() -> {
|
||||
try {
|
||||
for (int i = 0; i < totalTimes && flag.get(); i++) {
|
||||
mgr.runMacroDirect(macro, scope);
|
||||
long start = System.nanoTime();
|
||||
long timeout = 24L * 60L * 60L * 1_000_000_000L;
|
||||
while (mgr.isMacroPlayingOnScope(name, scope) && flag.get()
|
||||
&& System.nanoTime() - start < timeout) {
|
||||
Thread.sleep(50L);
|
||||
}
|
||||
if (!flag.get()) break;
|
||||
if (i + 1 < totalTimes && sleepMs > 0L) Thread.sleep(sleepMs);
|
||||
}
|
||||
} catch (InterruptedException ignored) {
|
||||
Thread.currentThread().interrupt();
|
||||
} finally {
|
||||
RUNNING_LOOPS.remove(key, flag);
|
||||
}
|
||||
}, "PovMacroLoop-" + name);
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
AutismClientMessaging.sendPrefixed("§aQueued POV §f" + totalTimes + "x " + name
|
||||
+ "§a for §f" + accountId + "§a.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private static String povLoopKey(String accountId, String name) {
|
||||
return "pov:" + accountId.toLowerCase(java.util.Locale.ROOT) + ":" + name.toLowerCase(java.util.Locale.ROOT);
|
||||
}
|
||||
|
||||
private static void stopPovLoops(String accountId) {
|
||||
String prefix = "pov:" + accountId.toLowerCase(java.util.Locale.ROOT) + ":";
|
||||
RUNNING_LOOPS.forEach((key, flag) -> {
|
||||
if (key.startsWith(prefix) && RUNNING_LOOPS.remove(key, flag)) flag.set(false);
|
||||
});
|
||||
}
|
||||
|
||||
private static void stopAllLoops() {
|
||||
for (AtomicBoolean flag : RUNNING_LOOPS.values()) flag.set(false);
|
||||
RUNNING_LOOPS.clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.modules.AutismModule;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
public class MatchmakingCommand extends Command {
|
||||
public MatchmakingCommand() { super("matchmaking", "Toggle the Matchmaking overlay.", "mm"); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
|
||||
mc.execute(() -> {
|
||||
AutismModule mod = AutismModule.get();
|
||||
if (mod != null) mod.toggleMatchmakingUiBehavior();
|
||||
});
|
||||
return SUCCESS;
|
||||
});
|
||||
}
|
||||
}
|
||||
27
src/main/java/autismclient/commands/impl/ModulesCommand.java
Normal file
27
src/main/java/autismclient/commands/impl/ModulesCommand.java
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.modules.ModuleRegistry;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
public class ModulesCommand extends Command {
|
||||
public ModulesCommand() { super("modules", "List installed modules.", "features"); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
java.util.List<String> names = ModuleRegistry.names();
|
||||
AutismClientMessaging.sendPrefixed("§e" + names.size() + " modules:");
|
||||
StringBuilder line = new StringBuilder();
|
||||
for (String n : names) {
|
||||
if (line.length() > 0) line.append("§7, ");
|
||||
line.append("§f").append(n);
|
||||
if (line.length() > 200) { AutismClientMessaging.sendPrefixed(line.toString()); line.setLength(0); }
|
||||
}
|
||||
if (line.length() > 0) AutismClientMessaging.sendPrefixed(line.toString());
|
||||
return SUCCESS;
|
||||
});
|
||||
}
|
||||
}
|
||||
184
src/main/java/autismclient/commands/impl/MultiCommand.java
Normal file
184
src/main/java/autismclient/commands/impl/MultiCommand.java
Normal file
|
|
@ -0,0 +1,184 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.args.MacroArgumentType;
|
||||
import autismclient.commands.args.MultiBotArgumentType;
|
||||
import autismclient.commands.args.MultiProfileArgumentType;
|
||||
import autismclient.gui.screen.AutismMultiConsoleScreen;
|
||||
import autismclient.gui.screen.AutismMultiScreen;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismMacro;
|
||||
import autismclient.util.AutismMacroManager;
|
||||
import autismclient.util.multi.MultiManager;
|
||||
import autismclient.util.multi.MultiProfile;
|
||||
import autismclient.util.multi.MultiProfileManager;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ServerData;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
public class MultiCommand extends Command {
|
||||
public MultiCommand() {
|
||||
super("multi", "Open the Multi menu, or launch/stop a profile.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> { openMenu(); return SUCCESS; });
|
||||
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("open")
|
||||
.executes(ctx -> { openMenu(); return SUCCESS; }));
|
||||
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("stop")
|
||||
.executes(ctx -> { stopBatch(); return SUCCESS; }));
|
||||
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("status")
|
||||
.executes(ctx -> { status(); return SUCCESS; }));
|
||||
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("launch")
|
||||
.executes(ctx -> {
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: §f" + AutismCommands.effectivePrefix() + "multi launch <profile>");
|
||||
return SUCCESS;
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("profile", MultiProfileArgumentType.profileName())
|
||||
.executes(ctx -> { launch(MultiProfileArgumentType.get(ctx, "profile")); return SUCCESS; })));
|
||||
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("macro")
|
||||
.executes(ctx -> {
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: §f" + AutismCommands.effectivePrefix()
|
||||
+ "multi macro <macro> [bot] §7- no bot = all bots");
|
||||
return SUCCESS;
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("macro", MacroArgumentType.macroName())
|
||||
.executes(ctx -> { runMacro(MacroArgumentType.get(ctx, "macro"), ""); return SUCCESS; })
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("bot", MultiBotArgumentType.botName())
|
||||
.executes(ctx -> {
|
||||
runMacro(MacroArgumentType.get(ctx, "macro"), MultiBotArgumentType.get(ctx, "bot"));
|
||||
return SUCCESS;
|
||||
}))));
|
||||
}
|
||||
|
||||
private static void runMacro(String macroName, String botName) {
|
||||
MultiManager manager = MultiManager.get();
|
||||
if (!manager.isActive()) {
|
||||
AutismClientMessaging.sendPrefixed("§7No Multi batch is active.");
|
||||
return;
|
||||
}
|
||||
AutismMacro macro = AutismMacroManager.get().get(macroName);
|
||||
if (macro == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cNo macro named: §f" + macroName);
|
||||
return;
|
||||
}
|
||||
Set<String> scope = manager.scopeForBot(botName);
|
||||
if (scope == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cNo bot named: §f" + botName);
|
||||
String live = liveBotNames(manager);
|
||||
if (!live.isEmpty()) AutismClientMessaging.sendPrefixed("§7Bots: §f" + live);
|
||||
return;
|
||||
}
|
||||
MultiManager.BroadcastResult result = manager.runMacroDirect(macro, scope);
|
||||
String target = botName == null || botName.isBlank() ? "all bots" : botName;
|
||||
AutismClientMessaging.sendPrefixed("§aRunning §f" + macro.name + " §aon §f" + target
|
||||
+ " §7- " + result.summary());
|
||||
}
|
||||
|
||||
private static String liveBotNames(MultiManager manager) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (MultiManager.BotHandle bot : manager.liveBots()) {
|
||||
if (sb.length() > 0) sb.append("§7, §f");
|
||||
sb.append(bot.username());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void openMenu() {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc == null) return;
|
||||
mc.execute(() -> {
|
||||
if (mc.gui.screen() != null) return;
|
||||
Runnable proceed = () -> {
|
||||
if (mc.level != null) {
|
||||
|
||||
autismclient.modules.AutismModule module = autismclient.modules.AutismModule.get();
|
||||
if (module != null) module.openMultiUiInGame();
|
||||
} else if (MultiManager.get().isActive()) {
|
||||
mc.gui.setScreen(new AutismMultiConsoleScreen(null));
|
||||
} else {
|
||||
mc.gui.setScreen(new AutismMultiScreen(null, currentServerAddress(mc)));
|
||||
}
|
||||
};
|
||||
|
||||
autismclient.gui.screen.AutismMultiDisclaimerScreen.open(mc, null, proceed);
|
||||
});
|
||||
}
|
||||
|
||||
private static void launch(String name) {
|
||||
MultiProfile profile = resolveByName(MultiProfileManager.get().all(), name);
|
||||
if (profile == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cNo profile named: §f" + name);
|
||||
String available = availableNames();
|
||||
if (!available.isEmpty()) AutismClientMessaging.sendPrefixed("§7Profiles: §f" + available);
|
||||
return;
|
||||
}
|
||||
MultiManager.StartResult result = MultiManager.get().start(profile);
|
||||
if (result.ok()) {
|
||||
AutismClientMessaging.sendPrefixed("§aLaunching Multi profile: §f" + profile.name
|
||||
+ " §7(" + profile.sessions.size() + " account(s)) - run "
|
||||
+ AutismCommands.effectivePrefix() + "multi to open the console.");
|
||||
} else {
|
||||
AutismClientMessaging.sendPrefixed("§cCould not launch: §f" + result.message());
|
||||
}
|
||||
}
|
||||
|
||||
private static void stopBatch() {
|
||||
if (!MultiManager.get().isActive()) {
|
||||
AutismClientMessaging.sendPrefixed("§7No Multi batch is active.");
|
||||
return;
|
||||
}
|
||||
MultiManager.get().disconnectAll("Stopped via command");
|
||||
AutismClientMessaging.sendPrefixed("§eStopped the Multi batch.");
|
||||
}
|
||||
|
||||
private static void status() {
|
||||
MultiManager mm = MultiManager.get();
|
||||
if (!mm.isActive()) {
|
||||
AutismClientMessaging.sendPrefixed("§7Multi: no batch active.");
|
||||
return;
|
||||
}
|
||||
MultiProfile active = mm.activeProfile();
|
||||
String name = active == null || active.name == null ? "(unknown)" : active.name;
|
||||
AutismClientMessaging.sendPrefixed("§aMulti: §f" + name
|
||||
+ " §7- §f" + mm.readyCount() + "§7 ready, §f" + mm.connectedCount() + "§7 connected.");
|
||||
}
|
||||
|
||||
private static String currentServerAddress(Minecraft mc) {
|
||||
ServerData sd = mc.getCurrentServer();
|
||||
return sd == null || sd.ip == null ? "" : sd.ip.trim();
|
||||
}
|
||||
|
||||
private static String availableNames() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (MultiProfile p : MultiProfileManager.get().all()) {
|
||||
if (p == null || p.name == null) continue;
|
||||
if (sb.length() > 0) sb.append("§7, §f");
|
||||
sb.append(p.name);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static MultiProfile resolveByName(Collection<MultiProfile> profiles, String name) {
|
||||
if (profiles == null || name == null) return null;
|
||||
String want = name.trim().toLowerCase(Locale.ROOT);
|
||||
if (want.isEmpty()) return null;
|
||||
for (MultiProfile p : profiles) {
|
||||
if (p != null && p.name != null && p.name.trim().toLowerCase(Locale.ROOT).equals(want)) return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.util.AutismNameScrape;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
|
||||
public final class NameScrapeCommand extends Command {
|
||||
public NameScrapeCommand() {
|
||||
super("namescrape", "Scrape player names to clipboard. [count] limits it; deep = exhaustive; pause/resume/stop.",
|
||||
"scrapenames");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> apply(0, false));
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, Integer>argument("count", IntegerArgumentType.integer(1))
|
||||
.executes(ctx -> apply(IntegerArgumentType.getInteger(ctx, "count"), false)));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("deep")
|
||||
.executes(ctx -> apply(0, true))
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Integer>argument("count", IntegerArgumentType.integer(1))
|
||||
.executes(ctx -> apply(IntegerArgumentType.getInteger(ctx, "count"), true))));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("pause").executes(ctx -> {
|
||||
AutismNameScrape.pause();
|
||||
return SUCCESS;
|
||||
}));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("resume").executes(ctx -> {
|
||||
AutismNameScrape.resume();
|
||||
return SUCCESS;
|
||||
}));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("stop").executes(ctx -> {
|
||||
AutismNameScrape.stop();
|
||||
return SUCCESS;
|
||||
}));
|
||||
}
|
||||
|
||||
private static int apply(int count, boolean deep) {
|
||||
AutismNameScrape.start(count, deep);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
79
src/main/java/autismclient/commands/impl/NbtCommand.java
Normal file
79
src/main/java/autismclient/commands/impl/NbtCommand.java
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.gui.screen.AutismOverlayHostScreen;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismItemCommandSerializer;
|
||||
import autismclient.util.AutismItemNbtInspectOverlay;
|
||||
import autismclient.util.AutismNotifications;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class NbtCommand extends Command {
|
||||
public NbtCommand() {
|
||||
super("nbt", "Inspect or copy the held item's components (NBT).");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
inspect();
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("get").executes(ctx -> {
|
||||
inspect();
|
||||
return SUCCESS;
|
||||
}));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("copy").executes(ctx -> {
|
||||
copy();
|
||||
return SUCCESS;
|
||||
}));
|
||||
}
|
||||
|
||||
private static ItemStack held() {
|
||||
net.minecraft.world.entity.player.Player player = autismclient.util.multi.MultiPilot.commandPlayer();
|
||||
if (player == null) return ItemStack.EMPTY;
|
||||
ItemStack main = player.getMainHandItem();
|
||||
return !main.isEmpty() ? main : player.getOffhandItem();
|
||||
}
|
||||
|
||||
private static void inspect() {
|
||||
ItemStack stack = held();
|
||||
if (stack.isEmpty()) {
|
||||
AutismClientMessaging.sendPrefixed("\u00a7cHold an item in either hand first.");
|
||||
return;
|
||||
}
|
||||
if (!AutismItemNbtInspectOverlay.openGlobal(stack)) {
|
||||
AutismClientMessaging.sendPrefixed("\u00a7cCould not open the NBT inspector.");
|
||||
return;
|
||||
}
|
||||
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc != null) {
|
||||
autismclient.util.AutismItemNbtInspectOverlay overlay =
|
||||
autismclient.util.AutismItemNbtInspectOverlay.getSharedOverlay(mc.font);
|
||||
mc.execute(() -> {
|
||||
|
||||
if (mc.gui.screen() == null) {
|
||||
mc.gui.setScreen(new AutismOverlayHostScreen(overlay));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void copy() {
|
||||
ItemStack stack = held();
|
||||
if (stack.isEmpty()) {
|
||||
AutismClientMessaging.sendPrefixed("\u00a7cHold an item in either hand first.");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Minecraft.getInstance().keyboardHandler.setClipboard(AutismItemCommandSerializer.giveCommand(stack));
|
||||
AutismNotifications.copied("Copied /give command.");
|
||||
} catch (Throwable t) {
|
||||
AutismNotifications.error("Copy failed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
80
src/main/java/autismclient/commands/impl/OreSimCommand.java
Normal file
80
src/main/java/autismclient/commands/impl/OreSimCommand.java
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.modules.Module;
|
||||
import autismclient.modules.ModuleOreSim;
|
||||
import autismclient.modules.ModuleRegistry;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismWaypoints;
|
||||
import autismclient.util.oresim.AutismOreSimEngine;
|
||||
import autismclient.util.oresim.AutismOreSimSeedInput;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class OreSimCommand extends Command {
|
||||
|
||||
private static final String G = "§7";
|
||||
private static final String W = "§f";
|
||||
private static final String R = "§c";
|
||||
private static final String Y = "§e";
|
||||
private static final String A = "§a";
|
||||
|
||||
public OreSimCommand() {
|
||||
super("oresim", "Report why OreSim is or is not predicting.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
report();
|
||||
return SUCCESS;
|
||||
});
|
||||
}
|
||||
|
||||
private static void report() {
|
||||
Module xray = ModuleRegistry.get("xray");
|
||||
if (xray == null) {
|
||||
AutismClientMessaging.sendPrefixed(R + "Xray module not registered.");
|
||||
return;
|
||||
}
|
||||
|
||||
AutismClientMessaging.sendPrefixed(Y + "--- OreSim ---");
|
||||
AutismClientMessaging.sendPrefixed(G + "enabled: " + W + xray.isEnabled()
|
||||
+ G + " mode: " + W + xray.value("mode")
|
||||
+ G + " style: " + W + xray.value("render-style"));
|
||||
|
||||
Long seed = ModuleOreSim.debugSeed(xray);
|
||||
AutismOreSimSeedInput.Status seedStatus = ModuleOreSim.seedInputStatus(xray);
|
||||
AutismClientMessaging.sendPrefixed(G + "seed: "
|
||||
+ (seedStatus == AutismOreSimSeedInput.Status.INVALID ? R + "INVALID"
|
||||
: seed == null ? R + "NONE - enter a signed 64-bit value" : W + seed)
|
||||
+ G + " from: " + W + "the World Seed text field");
|
||||
AutismClientMessaging.sendPrefixed(G + "saved scope: " + W
|
||||
+ AutismWaypoints.scopeKey(Minecraft.getInstance())
|
||||
+ G + "; the same world/server scoping as waypoints. No world or server seed is read.");
|
||||
|
||||
AutismClientMessaging.sendPrefixed(G + "ore list entries: " + W + ModuleOreSim.debugSelectionSize(xray)
|
||||
+ G + " families: " + W + Integer.bitCount(ModuleOreSim.debugEnabledMask(xray)));
|
||||
|
||||
String worldgen = AutismOreSimEngine.failed() ? R + "FAILED"
|
||||
: AutismOreSimEngine.loading() ? Y + AutismOreSimEngine.status().name().toLowerCase(java.util.Locale.ROOT)
|
||||
: AutismOreSimEngine.ready() ? A + "ready" : R + AutismOreSimEngine.status().name().toLowerCase(java.util.Locale.ROOT);
|
||||
AutismClientMessaging.sendPrefixed(G + "local Minecraft 26.2 worldgen: " + worldgen);
|
||||
if (AutismOreSimEngine.failed()
|
||||
|| AutismOreSimEngine.status() == AutismOreSimEngine.Status.UNVERIFIED_WORLDGEN) {
|
||||
AutismClientMessaging.sendPrefixed(R + AutismOreSimEngine.failureMessage());
|
||||
}
|
||||
|
||||
AutismClientMessaging.sendPrefixed(G + "chunks simulated: " + W + AutismOreSimEngine.chunkCount()
|
||||
+ G + " positions: " + W + AutismOreSimEngine.storedPositions());
|
||||
|
||||
AutismClientMessaging.sendPrefixed(G + "generation source: " + W
|
||||
+ "local vanilla registries + terrain + carvers + biome decoration"
|
||||
+ G + "; received server chunks are not inputs.");
|
||||
|
||||
AutismClientMessaging.sendPrefixed(G + "nearby real ore: " + W + ModuleOreSim.nearDiagnostics());
|
||||
AutismClientMessaging.sendPrefixed(G + "matched = real ore within 5 blocks; touchingAir = of those,"
|
||||
+ " exposed; drawn = also in line of sight.");
|
||||
}
|
||||
}
|
||||
14
src/main/java/autismclient/commands/impl/PluginsCommand.java
Normal file
14
src/main/java/autismclient/commands/impl/PluginsCommand.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
public class PluginsCommand extends Command {
|
||||
public PluginsCommand() { super("plugins", "Open the plugin scanner (alias of `server plugins`)."); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> { ServerCommand.openPlugins(); return SUCCESS; });
|
||||
}
|
||||
}
|
||||
48
src/main/java/autismclient/commands/impl/PrefixCommand.java
Normal file
48
src/main/java/autismclient/commands/impl/PrefixCommand.java
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.CommandSuggest;
|
||||
import autismclient.modules.AutismModule;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismCompatManager;
|
||||
import autismclient.util.AutismNotifications;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
|
||||
public class PrefixCommand extends Command {
|
||||
public PrefixCommand() {
|
||||
super("prefix", "Change the AUTISM command prefix.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
AutismClientMessaging.sendPrefixed("Current prefix: " + AutismCompatManager.effectiveCommandPrefix());
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("reset").executes(ctx -> {
|
||||
String prefix = AutismCompatManager.environmentDefaultCommandPrefix();
|
||||
AutismModule.get().setCommandPrefix(prefix);
|
||||
AutismClientMessaging.sendPrefixed("Prefix reset to " + prefix);
|
||||
return SUCCESS;
|
||||
}));
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("new", StringArgumentType.word())
|
||||
.suggests(CommandSuggest::prefixes)
|
||||
.executes(ctx -> {
|
||||
String requested = StringArgumentType.getString(ctx, "new");
|
||||
if (!AutismCompatManager.COMMAND_PREFIX_CHOICES.contains(requested)) {
|
||||
AutismClientMessaging.sendPrefixed("Prefix must be one of: . % - _ * # @ & =");
|
||||
return SUCCESS;
|
||||
}
|
||||
String selected = AutismCompatManager.normalizeStoredCommandPrefix(requested);
|
||||
AutismModule.get().setCommandPrefix(selected);
|
||||
if (!selected.equals(requested)) {
|
||||
AutismNotifications.warning("Meteor uses '.'. Prefix kept as '%'.");
|
||||
}
|
||||
AutismClientMessaging.sendPrefixed("Prefix set to " + selected);
|
||||
return SUCCESS;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismPlayerScanner;
|
||||
import autismclient.util.AutismRemoteView;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public final class RemoteViewCommand extends Command {
|
||||
public RemoteViewCommand() {
|
||||
super("rv", "Watch a loaded player's POV.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> openLookedAt());
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("stop")
|
||||
.executes(ctx -> {
|
||||
if (!AutismRemoteView.isActive()) {
|
||||
AutismClientMessaging.sendPrefixed("§7Remote view is not active.");
|
||||
} else {
|
||||
AutismRemoteView.stop(false);
|
||||
AutismClientMessaging.sendPrefixed("§aRemote view stopped.");
|
||||
}
|
||||
return SUCCESS;
|
||||
}));
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("player", StringArgumentType.greedyString())
|
||||
.suggests(RemoteViewCommand::suggestPlayers)
|
||||
.executes(ctx -> openNamed(StringArgumentType.getString(ctx, "player"))));
|
||||
}
|
||||
|
||||
private static int openLookedAt() {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
Entity entity = mc == null ? null : mc.crosshairPickEntity;
|
||||
if (!(entity instanceof Player) && mc != null && mc.hitResult instanceof EntityHitResult hit) {
|
||||
entity = hit.getEntity();
|
||||
}
|
||||
if (!(entity instanceof Player player)) {
|
||||
AutismClientMessaging.sendPrefixed("§cLook at a loaded player first.");
|
||||
return SUCCESS;
|
||||
}
|
||||
report(AutismRemoteView.start(player));
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private static int openNamed(String requested) {
|
||||
Player player = findLoadedPlayer(Minecraft.getInstance(), requested);
|
||||
if (player == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cPlayer is not loaded: §f" + requested.trim());
|
||||
return SUCCESS;
|
||||
}
|
||||
report(AutismRemoteView.start(player));
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
static Player findLoadedPlayer(Minecraft mc, String requested) {
|
||||
if (mc == null || mc.level == null || requested == null) return null;
|
||||
String wanted = requested.trim();
|
||||
if (wanted.isEmpty()) return null;
|
||||
for (Player player : mc.level.players()) {
|
||||
if (player == null) continue;
|
||||
String profile = player.getGameProfile() == null ? "" : player.getGameProfile().name();
|
||||
String shown = player.getName().getString();
|
||||
if (wanted.equalsIgnoreCase(profile) || wanted.equalsIgnoreCase(shown)) return player;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void report(AutismRemoteView.Result result) {
|
||||
AutismClientMessaging.sendPrefixed((result.ok() ? "§a" : "§c") + result.message());
|
||||
}
|
||||
|
||||
private static CompletableFuture<Suggestions> suggestPlayers(CommandContext<AutismCommandSource> ignored,
|
||||
SuggestionsBuilder builder) {
|
||||
String remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
|
||||
for (AutismPlayerScanner.ScannedPlayer player : AutismPlayerScanner.scan(Minecraft.getInstance())) {
|
||||
if (player.name().toLowerCase(Locale.ROOT).startsWith(remaining)) builder.suggest(player.name());
|
||||
}
|
||||
return builder.buildFuture();
|
||||
}
|
||||
}
|
||||
32
src/main/java/autismclient/commands/impl/SayCommand.java
Normal file
32
src/main/java/autismclient/commands/impl/SayCommand.java
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class SayCommand extends Command {
|
||||
public SayCommand() { super("say", "Send a chat message."); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: " + AutismCommands.effectivePrefix() + "say <message>");
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("message", StringArgumentType.greedyString())
|
||||
.executes(ctx -> {
|
||||
String msg = StringArgumentType.getString(ctx, "message");
|
||||
var conn = Minecraft.getInstance().getConnection();
|
||||
if (conn == null) { AutismClientMessaging.sendPrefixed("§cNot connected."); return SUCCESS; }
|
||||
if (msg.startsWith("/")) conn.sendCommand(msg.substring(1));
|
||||
|
||||
else AutismCommands.sendPlainChat(conn, msg);
|
||||
return SUCCESS;
|
||||
}));
|
||||
}
|
||||
}
|
||||
85
src/main/java/autismclient/commands/impl/SendCommand.java
Normal file
85
src/main/java/autismclient/commands/impl/SendCommand.java
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.args.PacketClassArgumentType;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismPacketArgumentBuilder;
|
||||
import autismclient.util.AutismPacketRegistry;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
|
||||
public class SendCommand extends Command {
|
||||
public SendCommand() { super("send", "Send a raw C2S packet by class name with optional field=value arguments."); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: §f" + AutismCommands.effectivePrefix() + "send <packetName> [field=value ...]");
|
||||
AutismClientMessaging.sendPrefixed("§7Tip: press Tab after the space to search C2S packet classes.");
|
||||
AutismClientMessaging.sendPrefixed("§7Example: §f" + AutismCommands.effectivePrefix() + "send ServerboundSetCarriedItemPacket slot=0");
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("packet", PacketClassArgumentType.packetClass())
|
||||
.executes(ctx -> send(PacketClassArgumentType.get(ctx, "packet"), ""))
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("args", StringArgumentType.greedyString())
|
||||
.suggests((ctx, builder) -> {
|
||||
Class<? extends Packet<?>> cls = AutismPacketRegistry.getPacket(PacketClassArgumentType.get(ctx, "packet"));
|
||||
return AutismPacketArgumentBuilder.suggest(cls, builder);
|
||||
})
|
||||
.executes(ctx -> send(PacketClassArgumentType.get(ctx, "packet"), StringArgumentType.getString(ctx, "args")))));
|
||||
}
|
||||
|
||||
private int send(String name, String args) {
|
||||
Class<? extends Packet<?>> cls = AutismPacketRegistry.getPacket(name);
|
||||
if (cls == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cUnknown packet: §f" + name);
|
||||
return SUCCESS;
|
||||
}
|
||||
if (!AutismPacketRegistry.getC2SPackets().contains(cls)) {
|
||||
AutismClientMessaging.sendPrefixed("§cRefusing to send non-C2S packet: §f" + name);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
AutismPacketArgumentBuilder.PreparedArgs prepared;
|
||||
try {
|
||||
prepared = AutismPacketArgumentBuilder.prepare(args);
|
||||
} catch (IllegalArgumentException e) {
|
||||
AutismClientMessaging.sendPrefixed("§cBad arguments: " + e.getMessage());
|
||||
return SUCCESS;
|
||||
}
|
||||
AutismPacketArgumentBuilder.Result result = AutismPacketArgumentBuilder.build(cls, prepared.args());
|
||||
if (result.help()) {
|
||||
sendLines("§e", result.message());
|
||||
return SUCCESS;
|
||||
}
|
||||
if (!result.ok()) {
|
||||
sendLines("§c", "Failed to build §f" + name + "§c: " + result.message());
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
if (prepared.dryRun()) {
|
||||
AutismClientMessaging.sendPrefixed("§eBuilt §f" + name + "§7 (" + result.source() + ") §e- dry run, not sent.");
|
||||
return SUCCESS;
|
||||
}
|
||||
var conn = Minecraft.getInstance().getConnection();
|
||||
if (conn == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cNo network connection.");
|
||||
return SUCCESS;
|
||||
}
|
||||
autismclient.util.AutismSharedState.get().sendPacketBypassDelay(conn, result.packet());
|
||||
AutismClientMessaging.sendPrefixed("§aSent §f" + name + "§7 (" + result.source() + ")");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private static void sendLines(String color, String message) {
|
||||
if (message == null || message.isBlank()) return;
|
||||
for (String line : message.split("\\R")) {
|
||||
if (!line.isBlank()) AutismClientMessaging.sendPrefixed(color + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
53
src/main/java/autismclient/commands/impl/ServerCommand.java
Normal file
53
src/main/java/autismclient/commands/impl/ServerCommand.java
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.gui.screen.AutismOverlayHostScreen;
|
||||
import autismclient.modules.AutismModule;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismOverlayManager;
|
||||
import autismclient.util.AutismServerInfoOverlay;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class ServerCommand extends Command {
|
||||
public ServerCommand() { super("server", "Open the server info panel, or the plugin scanner."); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> { openInfo(); return SUCCESS; });
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("info").executes(ctx -> { openInfo(); return SUCCESS; }));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("plugins").executes(ctx -> { openPlugins(); return SUCCESS; }));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("tps").executes(ctx -> { tps(); return SUCCESS; }));
|
||||
}
|
||||
|
||||
static void openInfo() {
|
||||
openOverlay(false);
|
||||
}
|
||||
|
||||
static void openPlugins() {
|
||||
openOverlay(true);
|
||||
}
|
||||
|
||||
private static void openOverlay(boolean pluginsTab) {
|
||||
AutismServerInfoOverlay overlay = AutismModule.get().getServerDataOverlay();
|
||||
if (overlay == null) { AutismClientMessaging.sendPrefixed("§cServer overlay unavailable."); return; }
|
||||
AutismOverlayManager.get().register(overlay);
|
||||
if (pluginsTab) overlay.openPluginsTab();
|
||||
else overlay.openInfoTab();
|
||||
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc != null) {
|
||||
mc.execute(() -> {
|
||||
if (mc.gui.screen() == null) {
|
||||
mc.gui.setScreen(new AutismOverlayHostScreen(overlay));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void tps() {
|
||||
double tps = autismclient.util.macro.ServerTickTracker.getEstimatedTps();
|
||||
AutismClientMessaging.sendPrefixed(String.format("§eTPS: §f%.2f §7(estimated)", tps));
|
||||
}
|
||||
}
|
||||
78
src/main/java/autismclient/commands/impl/SyncCommand.java
Normal file
78
src/main/java/autismclient/commands/impl/SyncCommand.java
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.args.MacroArgumentType;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismLANSync;
|
||||
import autismclient.util.AutismMacro;
|
||||
import autismclient.util.AutismMacroManager;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
|
||||
public final class SyncCommand extends Command {
|
||||
public SyncCommand() {
|
||||
super("sync", "Synchronize a chat message, server command, or macro across the LAN session.",
|
||||
"lan-sync", "lansync");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(context -> usage());
|
||||
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("send")
|
||||
.executes(context -> {
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: §f" + AutismCommands.effectivePrefix()
|
||||
+ "sync send <message or /command>");
|
||||
return SUCCESS;
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument(
|
||||
"message", StringArgumentType.greedyString())
|
||||
.executes(context -> send(StringArgumentType.getString(context, "message")))));
|
||||
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("macro")
|
||||
.executes(context -> {
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: §f" + AutismCommands.effectivePrefix()
|
||||
+ "sync macro <name>");
|
||||
return SUCCESS;
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument(
|
||||
"name", MacroArgumentType.macroName())
|
||||
.executes(context -> macro(MacroArgumentType.get(context, "name")))));
|
||||
}
|
||||
|
||||
private static int usage() {
|
||||
String prefix = AutismCommands.effectivePrefix();
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: §f" + prefix + "sync send <message or /command>");
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: §f" + prefix + "sync macro <name>");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private static int send(String message) {
|
||||
AutismLANSync sync = AutismLANSync.getInstance();
|
||||
if (!sync.isInSession()) {
|
||||
AutismClientMessaging.sendPrefixed("§cJoin a LAN Sync session first.");
|
||||
return SUCCESS;
|
||||
}
|
||||
sync.sendChatMessage(message);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private static int macro(String name) {
|
||||
AutismLANSync sync = AutismLANSync.getInstance();
|
||||
if (!sync.isInSession()) {
|
||||
AutismClientMessaging.sendPrefixed("§cJoin a LAN Sync session first.");
|
||||
return SUCCESS;
|
||||
}
|
||||
AutismMacro macro = AutismMacroManager.get().get(name);
|
||||
if (macro == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cMacro not found: §f" + name);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
sync.executeMacroSynchronized(macro.name);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
54
src/main/java/autismclient/commands/impl/ToggleCommand.java
Normal file
54
src/main/java/autismclient/commands/impl/ToggleCommand.java
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.CommandSuggest;
|
||||
import autismclient.commands.args.ModuleArgumentType;
|
||||
import autismclient.modules.PackHideState;
|
||||
import autismclient.modules.ModuleRegistry;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.macro.ToggleModuleAction;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
|
||||
public class ToggleCommand extends Command {
|
||||
public ToggleCommand() { super("toggle", "Toggle a module on/off.", "t"); }
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: §f" + AutismCommands.effectivePrefix() + "toggle <module> [on|off|toggle]");
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("module", ModuleArgumentType.moduleName())
|
||||
.executes(ctx -> doToggle(ModuleArgumentType.get(ctx, "module"), ToggleModuleAction.ToggleMode.TOGGLE))
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("state", StringArgumentType.word())
|
||||
.suggests(CommandSuggest::state)
|
||||
.executes(ctx -> {
|
||||
String state = StringArgumentType.getString(ctx, "state").toLowerCase();
|
||||
if (!state.equals("on") && !state.equals("enable") && !state.equals("true") && !state.equals("1")
|
||||
&& !state.equals("off") && !state.equals("disable") && !state.equals("false") && !state.equals("0")
|
||||
&& !state.equals("toggle")) {
|
||||
AutismClientMessaging.sendPrefixed("§cUnknown toggle state: §f" + state);
|
||||
AutismClientMessaging.sendPrefixed("§7Use §fon§7, §foff§7, or §ftoggle§7.");
|
||||
return SUCCESS;
|
||||
}
|
||||
ToggleModuleAction.ToggleMode mode = switch (state) {
|
||||
case "on", "enable", "true", "1" -> ToggleModuleAction.ToggleMode.ENABLE;
|
||||
case "off", "disable", "false", "0" -> ToggleModuleAction.ToggleMode.DISABLE;
|
||||
default -> ToggleModuleAction.ToggleMode.TOGGLE;
|
||||
};
|
||||
return doToggle(ModuleArgumentType.get(ctx, "module"), mode);
|
||||
})));
|
||||
}
|
||||
|
||||
private static int doToggle(String moduleName, ToggleModuleAction.ToggleMode mode) {
|
||||
boolean ok = ModuleRegistry.toggle(moduleName, mode);
|
||||
if (ok && PackHideState.isHideModuleName(moduleName)) return SUCCESS;
|
||||
if (ok) AutismClientMessaging.sendPrefixed("§a" + mode.name().toLowerCase() + ": §f" + moduleName);
|
||||
else AutismClientMessaging.sendPrefixed("§cModule not found: §f" + moduleName);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
98
src/main/java/autismclient/commands/impl/TpCommand.java
Normal file
98
src/main/java/autismclient/commands/impl/TpCommand.java
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismWaypoints;
|
||||
import autismclient.util.multi.PacketTeleportController;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public final class TpCommand extends Command {
|
||||
public TpCommand() {
|
||||
super("tp", "Ground-first HClip teleport.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
show(PacketTeleportController.executeMain(""));
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument(
|
||||
"arguments", StringArgumentType.greedyString())
|
||||
.suggests((ctx, suggestions) -> {
|
||||
String remaining = suggestions.getRemaining();
|
||||
|
||||
String bare = remaining.startsWith("\"") ? remaining.substring(1) : remaining;
|
||||
String lower = bare.toLowerCase(Locale.ROOT);
|
||||
for (String value : new String[]{"~ ~ ~", "stop", "status", "config 20 500", "reset"}) {
|
||||
if (value.startsWith(remaining)) suggestions.suggest(value);
|
||||
}
|
||||
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc != null) {
|
||||
for (AutismWaypoints.Waypoint wp : AutismWaypoints.get().list(AutismWaypoints.scopeKey(mc))) {
|
||||
String name = wp.name();
|
||||
if (!name.toLowerCase(Locale.ROOT).startsWith(lower)) continue;
|
||||
suggestions.suggest(name.contains(" ") ? "\"" + name + "\"" : name);
|
||||
}
|
||||
}
|
||||
return suggestions.buildFuture();
|
||||
})
|
||||
.executes(ctx -> {
|
||||
show(PacketTeleportController.executeMain(resolveWaypoint(StringArgumentType.getString(ctx, "arguments"))));
|
||||
return SUCCESS;
|
||||
}));
|
||||
}
|
||||
|
||||
private static String resolveWaypoint(String args) {
|
||||
String trimmed = args == null ? "" : args.trim();
|
||||
if (trimmed.isEmpty()) return args;
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc == null) return args;
|
||||
String scope = AutismWaypoints.scopeKey(mc);
|
||||
|
||||
if (trimmed.length() >= 2 && trimmed.startsWith("\"") && trimmed.endsWith("\"")) {
|
||||
return toCoords(AutismWaypoints.get().find(scope, trimmed.substring(1, trimmed.length() - 1)), args);
|
||||
}
|
||||
String lower = trimmed.toLowerCase(Locale.ROOT);
|
||||
if (lower.equals("stop") || lower.equals("status") || lower.equals("reset")
|
||||
|| lower.startsWith("config") || looksLikeCoords(trimmed)) return args;
|
||||
|
||||
return toCoords(AutismWaypoints.get().find(scope, trimmed), args);
|
||||
}
|
||||
|
||||
private static String toCoords(AutismWaypoints.Waypoint wp, String fallback) {
|
||||
return wp == null ? fallback : wp.x() + " " + wp.y() + " " + wp.z();
|
||||
}
|
||||
|
||||
private static boolean looksLikeCoords(String value) {
|
||||
String[] parts = value.split("\\s+");
|
||||
if (parts.length < 3) return false;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (parts[i].startsWith("~")) continue;
|
||||
try {
|
||||
Double.parseDouble(parts[i]);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void show(String result) {
|
||||
String text = result == null || result.isBlank()
|
||||
? "Usage: " + AutismCommands.effectivePrefix()
|
||||
+ "tp <x> <y> <z> [maxPackets] [pauseMs]"
|
||||
: result;
|
||||
String color = text.startsWith("TP started") || text.startsWith("TP defaults") ? "§a"
|
||||
: text.startsWith("Usage") || text.startsWith("No active") ? "§e" : "§7";
|
||||
AutismClientMessaging.sendPrefixed(color + text);
|
||||
}
|
||||
}
|
||||
129
src/main/java/autismclient/commands/impl/VClipCommand.java
Normal file
129
src/main/java/autismclient/commands/impl/VClipCommand.java
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.CommandSuggest;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.macro.VClipAction;
|
||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||
import com.mojang.brigadier.arguments.DoubleArgumentType;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class VClipCommand extends Command {
|
||||
public VClipCommand() {
|
||||
super("vclip", "Lets you clip through blocks vertically with movement packets.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
String prefix = AutismCommands.effectivePrefix();
|
||||
AutismClientMessaging.sendPrefixed("\u00a7eUsage: \u00a7f" + prefix + "vclip <blocks>");
|
||||
AutismClientMessaging.sendPrefixed("\u00a77Modes: \u00a7fdefault, top, bottom, paper, single, custom");
|
||||
AutismClientMessaging.sendPrefixed("\u00a77Examples: \u00a7f" + prefix + "vclip top \u00a77or \u00a7f" + prefix + "vclip custom -25 10 20 true true");
|
||||
return SUCCESS;
|
||||
});
|
||||
|
||||
root.then(blocksArgument("blocks", options -> options));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("top")
|
||||
.executes(ctx -> {
|
||||
VClipAction.Options options = VClipAction.Options.defaults(0.0);
|
||||
options.mode = VClipAction.Mode.TOP;
|
||||
run(options);
|
||||
return SUCCESS;
|
||||
}));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("bottom")
|
||||
.executes(ctx -> {
|
||||
VClipAction.Options options = VClipAction.Options.defaults(0.0);
|
||||
options.mode = VClipAction.Mode.BOTTOM;
|
||||
run(options);
|
||||
return SUCCESS;
|
||||
}));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("default")
|
||||
.then(blocksArgument("blocks", options -> options)));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("paper")
|
||||
.then(blocksArgument("blocks", options -> options)));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("single")
|
||||
.then(blocksArgument("blocks", VClipAction.Options::singlePacket)));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("normal")
|
||||
.then(blocksArgument("blocks", VClipAction.Options::singlePacket)));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("custom")
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Double>argument("blocks", DoubleArgumentType.doubleArg())
|
||||
.suggests(CommandSuggest::offsets)
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Integer>argument("segment", IntegerArgumentType.integer(1, 50))
|
||||
.suggests(CommandSuggest::vclipSegments)
|
||||
.executes(ctx -> {
|
||||
VClipAction.Options options = VClipAction.Options.defaults(DoubleArgumentType.getDouble(ctx, "blocks"));
|
||||
options.segmentBlocks = IntegerArgumentType.getInteger(ctx, "segment");
|
||||
run(options);
|
||||
return SUCCESS;
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Integer>argument("maxPackets", IntegerArgumentType.integer(1, 100))
|
||||
.suggests(CommandSuggest::vclipPacketLimits)
|
||||
.executes(ctx -> {
|
||||
VClipAction.Options options = VClipAction.Options.defaults(DoubleArgumentType.getDouble(ctx, "blocks"));
|
||||
options.segmentBlocks = IntegerArgumentType.getInteger(ctx, "segment");
|
||||
options.maxPackets = IntegerArgumentType.getInteger(ctx, "maxPackets");
|
||||
run(options);
|
||||
return SUCCESS;
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Boolean>argument("updateLocal", BoolArgumentType.bool())
|
||||
.executes(ctx -> {
|
||||
VClipAction.Options options = customOptions(ctx);
|
||||
options.updateLocalPosition = BoolArgumentType.getBool(ctx, "updateLocal");
|
||||
run(options);
|
||||
return SUCCESS;
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Boolean>argument("vehicle", BoolArgumentType.bool())
|
||||
.executes(ctx -> {
|
||||
VClipAction.Options options = customOptions(ctx);
|
||||
options.updateLocalPosition = BoolArgumentType.getBool(ctx, "updateLocal");
|
||||
options.tryVehicleFirst = BoolArgumentType.getBool(ctx, "vehicle");
|
||||
run(options);
|
||||
return SUCCESS;
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Boolean>argument("forceGround", BoolArgumentType.bool())
|
||||
.executes(ctx -> {
|
||||
VClipAction.Options options = customOptions(ctx);
|
||||
options.updateLocalPosition = BoolArgumentType.getBool(ctx, "updateLocal");
|
||||
options.tryVehicleFirst = BoolArgumentType.getBool(ctx, "vehicle");
|
||||
options.forceGrounded = BoolArgumentType.getBool(ctx, "forceGround");
|
||||
run(options);
|
||||
return SUCCESS;
|
||||
}))))))));
|
||||
}
|
||||
|
||||
private interface OptionsCustomizer {
|
||||
VClipAction.Options apply(VClipAction.Options options);
|
||||
}
|
||||
|
||||
private static RequiredArgumentBuilder<AutismCommandSource, Double> blocksArgument(String name, OptionsCustomizer customizer) {
|
||||
return RequiredArgumentBuilder.<AutismCommandSource, Double>argument(name, DoubleArgumentType.doubleArg())
|
||||
.suggests(CommandSuggest::offsets)
|
||||
.executes(ctx -> {
|
||||
VClipAction.Options options = VClipAction.Options.defaults(DoubleArgumentType.getDouble(ctx, name));
|
||||
run(customizer.apply(options));
|
||||
return SUCCESS;
|
||||
});
|
||||
}
|
||||
|
||||
private static VClipAction.Options customOptions(com.mojang.brigadier.context.CommandContext<AutismCommandSource> ctx) {
|
||||
VClipAction.Options options = VClipAction.Options.defaults(DoubleArgumentType.getDouble(ctx, "blocks"));
|
||||
options.segmentBlocks = IntegerArgumentType.getInteger(ctx, "segment");
|
||||
options.maxPackets = IntegerArgumentType.getInteger(ctx, "maxPackets");
|
||||
return options;
|
||||
}
|
||||
|
||||
public static void vclip(double blocks) {
|
||||
run(VClipAction.Options.defaults(blocks));
|
||||
}
|
||||
|
||||
private static void run(VClipAction.Options options) {
|
||||
options.showMessage = true;
|
||||
VClipAction.perform(Minecraft.getInstance(), options);
|
||||
}
|
||||
}
|
||||
145
src/main/java/autismclient/commands/impl/WaypointsCommand.java
Normal file
145
src/main/java/autismclient/commands/impl/WaypointsCommand.java
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.gui.screen.AutismWaypointsScreen;
|
||||
import autismclient.modules.Module;
|
||||
import autismclient.modules.ModuleRegistry;
|
||||
import autismclient.modules.WaypointsModule;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismWaypoints;
|
||||
import com.mojang.brigadier.arguments.DoubleArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public final class WaypointsCommand extends Command {
|
||||
private static final int FALLBACK_DEFAULT_COLOR = 0xFF3BD7FF;
|
||||
|
||||
public WaypointsCommand() {
|
||||
super("waypoints", "Save and manage waypoints.", "wp");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> addCurrentPosition());
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("gui").executes(ctx -> openGui()));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("list").executes(ctx -> openGui()));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("clear").executes(ctx -> clearScope()));
|
||||
root.then(LiteralArgumentBuilder.<AutismCommandSource>literal("del")
|
||||
.executes(ctx -> usage())
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("name", StringArgumentType.greedyString())
|
||||
.executes(ctx -> delete(StringArgumentType.getString(ctx, "name")))));
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, Double>argument("x", DoubleArgumentType.doubleArg())
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Double>argument("y", DoubleArgumentType.doubleArg())
|
||||
.then(RequiredArgumentBuilder.<AutismCommandSource, Double>argument("z", DoubleArgumentType.doubleArg())
|
||||
.executes(ctx -> addAt(DoubleArgumentType.getDouble(ctx, "x"),
|
||||
DoubleArgumentType.getDouble(ctx, "y"), DoubleArgumentType.getDouble(ctx, "z"))))));
|
||||
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, String>argument("args", StringArgumentType.greedyString())
|
||||
.executes(ctx -> fallback(StringArgumentType.getString(ctx, "args"))));
|
||||
}
|
||||
|
||||
private int fallback(String args) {
|
||||
String trimmed = args == null ? "" : args.trim();
|
||||
if (trimmed.equalsIgnoreCase("gui") || trimmed.equalsIgnoreCase("list")) return openGui();
|
||||
if (trimmed.equalsIgnoreCase("clear")) return clearScope();
|
||||
if (trimmed.regionMatches(true, 0, "del ", 0, 4)) return delete(trimmed.substring(4));
|
||||
double[] coords = parseCoords(trimmed);
|
||||
if (coords != null) return addAt(coords[0], coords[1], coords[2]);
|
||||
return usage();
|
||||
}
|
||||
|
||||
private int usage() {
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: " + AutismCommands.effectivePrefix()
|
||||
+ "wp [x y z] | gui | del <name> | clear");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private int addCurrentPosition() {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc == null || mc.player == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cNot in a world.");
|
||||
return SUCCESS;
|
||||
}
|
||||
AutismWaypoints store = AutismWaypoints.get();
|
||||
String scope = AutismWaypoints.scopeKey(mc);
|
||||
int x = (int) Math.floor(mc.player.getX());
|
||||
int y = (int) Math.floor(mc.player.getY());
|
||||
int z = (int) Math.floor(mc.player.getZ());
|
||||
String name = store.nextName(scope, "Waypoint");
|
||||
store.add(scope, new AutismWaypoints.Waypoint(name, x, y, z, defaultColor(), System.currentTimeMillis()));
|
||||
AutismClientMessaging.sendPrefixed("§aWaypoint saved: §f" + name + " §7(" + x + " " + y + " " + z + ")");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private int addAt(double dx, double dy, double dz) {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
AutismWaypoints store = AutismWaypoints.get();
|
||||
String scope = AutismWaypoints.scopeKey(mc);
|
||||
int x = floorCoordinate(dx);
|
||||
int y = floorCoordinate(dy);
|
||||
int z = floorCoordinate(dz);
|
||||
String name = store.nextName(scope, "Waypoint");
|
||||
store.add(scope, new AutismWaypoints.Waypoint(name, x, y, z, defaultColor(), System.currentTimeMillis()));
|
||||
AutismClientMessaging.sendPrefixed("§aWaypoint saved: §f" + name + " §7(" + x + " " + y + " " + z + ")");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private int delete(String name) {
|
||||
String trimmed = name == null ? "" : name.trim();
|
||||
if (trimmed.isEmpty()) return usage();
|
||||
String scope = AutismWaypoints.scopeKey(Minecraft.getInstance());
|
||||
if (AutismWaypoints.get().remove(scope, trimmed)) {
|
||||
AutismClientMessaging.sendPrefixed("§aWaypoint deleted: §f" + trimmed);
|
||||
} else {
|
||||
AutismClientMessaging.sendPrefixed("§cNo waypoint named '" + trimmed + "'.");
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private int clearScope() {
|
||||
String scope = AutismWaypoints.scopeKey(Minecraft.getInstance());
|
||||
AutismWaypoints store = AutismWaypoints.get();
|
||||
int count = store.list(scope).size();
|
||||
store.clear(scope);
|
||||
AutismClientMessaging.sendPrefixed(count == 0
|
||||
? "§7No waypoints to clear."
|
||||
: "§aCleared " + count + " waypoint" + (count == 1 ? "" : "s") + ".");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private int openGui() {
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (mc == null || mc.gui == null) return SUCCESS;
|
||||
|
||||
mc.execute(() -> mc.gui.setScreen(new AutismWaypointsScreen(mc.gui.screen())));
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private static int defaultColor() {
|
||||
Module module = ModuleRegistry.get("waypoints");
|
||||
return module instanceof WaypointsModule waypoints ? waypoints.defaultColor() : FALLBACK_DEFAULT_COLOR;
|
||||
}
|
||||
|
||||
private static double[] parseCoords(String args) {
|
||||
String[] parts = args.split("\\s+");
|
||||
if (parts.length != 3) return null;
|
||||
double[] out = new double[3];
|
||||
try {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
out[i] = Double.parseDouble(parts[i]);
|
||||
if (!Double.isFinite(out[i])) return null;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private static int floorCoordinate(double value) {
|
||||
return Double.isFinite(value) ? (int) Math.floor(value) : 0;
|
||||
}
|
||||
}
|
||||
140
src/main/java/autismclient/commands/impl/XCarryCommand.java
Normal file
140
src/main/java/autismclient/commands/impl/XCarryCommand.java
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
package autismclient.commands.impl;
|
||||
|
||||
import autismclient.commands.Command;
|
||||
import autismclient.commands.AutismCommandSource;
|
||||
import autismclient.commands.AutismCommands;
|
||||
import autismclient.commands.args.XCarrySlotArgumentType;
|
||||
import autismclient.util.AutismClientMessaging;
|
||||
import autismclient.util.AutismSharedState;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.inventory.InventoryScreen;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.ContainerInput;
|
||||
import net.minecraft.world.inventory.InventoryMenu;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class XCarryCommand extends Command {
|
||||
public XCarryCommand() {
|
||||
super("xcarry",
|
||||
"Stash the held item into an XCarry slot: craft1..craft5 / helmet / chestplate / leggings / boots / offhand / cursor.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(LiteralArgumentBuilder<AutismCommandSource> root) {
|
||||
root.executes(ctx -> {
|
||||
String prefix = AutismCommands.effectivePrefix();
|
||||
AutismClientMessaging.sendPrefixed("§eUsage: §f" + prefix + "xcarry <slot>");
|
||||
AutismClientMessaging.sendPrefixed("§7Slots: §fcraft1§7..§fcraft5§7, §fhelmet§7, §fchestplate§7, §fleggings§7, §fboots§7, §foffhand§7, §fcursor§7.");
|
||||
return SUCCESS;
|
||||
});
|
||||
root.then(RequiredArgumentBuilder.<AutismCommandSource, Integer>argument("slot", XCarrySlotArgumentType.slot())
|
||||
.executes(ctx -> stash(XCarrySlotArgumentType.get(ctx, "slot"))));
|
||||
}
|
||||
|
||||
private static int stash(int targetSlot) {
|
||||
String povResult = autismclient.util.multi.MultiPilot.commandStashXCarry(targetSlot);
|
||||
if (povResult != null) {
|
||||
AutismClientMessaging.sendPrefixed(("Sent".equals(povResult) ? "§a" : "§c")
|
||||
+ "POV XCarry: §f" + povResult);
|
||||
return SUCCESS;
|
||||
}
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
LocalPlayer p = mc.player;
|
||||
if (p == null || mc.gameMode == null) {
|
||||
AutismClientMessaging.sendPrefixed("§cNot in a world.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
ItemStack heldStack = p.getMainHandItem().copy();
|
||||
if (heldStack == null || heldStack.isEmpty()) {
|
||||
AutismClientMessaging.sendPrefixed("§cHold an item first.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
if (p.containerMenu != p.inventoryMenu) {
|
||||
AutismClientMessaging.sendPrefixed("§cOpen your inventory first (E), then run the command.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
AbstractContainerMenu container = p.containerMenu;
|
||||
|
||||
int hotbar = p.getInventory().getSelectedSlot();
|
||||
int sourceSlotId = 36 + hotbar;
|
||||
|
||||
AutismSharedState shared = AutismSharedState.get();
|
||||
boolean prevBypass = shared.isXCarryArmorBypass();
|
||||
shared.setXCarryArmorBypass(true);
|
||||
try {
|
||||
|
||||
mc.gameMode.handleContainerInput(container.containerId, sourceSlotId, 0, ContainerInput.PICKUP, p);
|
||||
if (container.getCarried().isEmpty()) {
|
||||
AutismClientMessaging.sendPrefixed("§cCould not pick up the held item.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
String itemName = heldStack.getHoverName().getString();
|
||||
String slotName = XCarrySlotArgumentType.displayName(targetSlot);
|
||||
LinkedHashSet<Integer> forcedSlots = mergedForcedSlots(shared);
|
||||
boolean forcedCursor = shared.isXCarryForced() && shared.isXCarryForcedCarryCursor();
|
||||
|
||||
if (targetSlot == XCarrySlotArgumentType.CURSOR) {
|
||||
|
||||
shared.setXCarryForcedTargets(forcedSlots, true);
|
||||
shared.setXCarryForced(true);
|
||||
shared.setXCarryActive(true);
|
||||
AutismClientMessaging.sendPrefixed("§aHolding §f" + itemName + "§a on cursor (XCarry).");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
if (targetSlot < 0 || targetSlot >= container.slots.size()) {
|
||||
AutismClientMessaging.sendPrefixed("§cInvalid slot (" + targetSlot + ").");
|
||||
|
||||
mc.gameMode.handleContainerInput(container.containerId, sourceSlotId, 0, ContainerInput.PICKUP, p);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
mc.gameMode.handleContainerInput(container.containerId, targetSlot, 0, ContainerInput.PICKUP, p);
|
||||
|
||||
boolean placed = container.getCarried().isEmpty()
|
||||
&& targetSlot >= 0
|
||||
&& targetSlot < container.slots.size()
|
||||
&& !container.slots.get(targetSlot).getItem().isEmpty();
|
||||
if (!placed && !container.getCarried().isEmpty()) {
|
||||
mc.gameMode.handleContainerInput(container.containerId, sourceSlotId, 0, ContainerInput.PICKUP, p);
|
||||
}
|
||||
|
||||
if (!placed) {
|
||||
AutismClientMessaging.sendPrefixed("§cCould not stash into §f" + slotName + "§c.");
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
forcedSlots.add(targetSlot);
|
||||
shared.setXCarryForcedTargets(forcedSlots, forcedCursor);
|
||||
shared.setXCarryForced(true);
|
||||
shared.setXCarryActive(true);
|
||||
AutismClientMessaging.sendPrefixed("§aStashed §f" + itemName + "§a into §f" + slotName + "§a.");
|
||||
return SUCCESS;
|
||||
} finally {
|
||||
shared.setXCarryArmorBypass(prevBypass);
|
||||
}
|
||||
}
|
||||
|
||||
private static LinkedHashSet<Integer> mergedForcedSlots(AutismSharedState shared) {
|
||||
LinkedHashSet<Integer> slots = new LinkedHashSet<>();
|
||||
if (shared != null && shared.isXCarryForced()) {
|
||||
Set<Integer> existing = shared.getXCarryForcedSlotMask();
|
||||
if (existing != null) {
|
||||
for (Integer slot : existing) {
|
||||
if (slot != null && slot >= 0) slots.add(slot);
|
||||
}
|
||||
}
|
||||
}
|
||||
return slots;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue