From 5dd2c19d1458d002a3fb4305c42b4b8fbc954204 Mon Sep 17 00:00:00 2001 From: Moxvallix Mox Date: Mon, 8 Jul 2024 19:56:36 +0930 Subject: [PATCH 1/3] wip: start implementing .item --- .../meteorclient/commands/Commands.java | 1 + .../commands/commands/ItemCommand.java | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/main/java/meteordevelopment/meteorclient/commands/commands/ItemCommand.java diff --git a/src/main/java/meteordevelopment/meteorclient/commands/Commands.java b/src/main/java/meteordevelopment/meteorclient/commands/Commands.java index de498a625c..f38d17c4d1 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/Commands.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/Commands.java @@ -62,6 +62,7 @@ public static void init() { add(new InputCommand()); add(new WaspCommand()); add(new LocateCommand()); + add(new ItemCommand()); COMMANDS.sort(Comparator.comparing(Command::getName)); } diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/ItemCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/ItemCommand.java new file mode 100644 index 0000000000..8b4b5e4ecf --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/ItemCommand.java @@ -0,0 +1,46 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.commands.commands; + +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import meteordevelopment.meteorclient.MeteorClient; +import meteordevelopment.meteorclient.commands.Command; +import meteordevelopment.meteorclient.commands.arguments.ModuleArgumentType; +import meteordevelopment.meteorclient.systems.hud.Hud; +import meteordevelopment.meteorclient.systems.modules.Module; +import meteordevelopment.meteorclient.systems.modules.Modules; +import net.minecraft.command.CommandSource; +import net.minecraft.command.argument.ItemStackArgument; +import net.minecraft.command.argument.ItemStackArgumentType; +import net.minecraft.item.Item; + +import java.util.ArrayList; + +public class ItemCommand extends Command { + public ItemCommand() { + super("item", "Manages item related modules."); + } + + @Override + public void build(LiteralArgumentBuilder builder) { + builder + + .then(literal("highlight") + .then(literal("add") + .then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)) + .executes(context -> { + MeteorClient.LOG.info(context.getArgument("item", ItemStackArgument.class).getItem().toString()); + return SINGLE_SUCCESS; + }) + )) + .then(literal("remove") + .executes(context -> { + return SINGLE_SUCCESS; + }) + ) + ); + } +} From 20cf0880ac93a9ce27d67d4f1a66ec07b7df3bf3 Mon Sep 17 00:00:00 2001 From: Moxvallix Mox Date: Sat, 6 Sep 2025 01:58:19 +0930 Subject: [PATCH 2/3] feat(command): implement .item command --- .../commands/commands/ItemCommand.java | 284 +++++++++++++++++- .../systems/modules/misc/InventoryTweaks.java | 4 +- .../systems/modules/render/ItemHighlight.java | 2 +- 3 files changed, 275 insertions(+), 15 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/ItemCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/ItemCommand.java index 8b4b5e4ecf..7d3ce53bcf 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/ItemCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/ItemCommand.java @@ -6,41 +6,301 @@ package meteordevelopment.meteorclient.commands.commands; import com.mojang.brigadier.builder.LiteralArgumentBuilder; -import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.commands.Command; -import meteordevelopment.meteorclient.commands.arguments.ModuleArgumentType; -import meteordevelopment.meteorclient.systems.hud.Hud; -import meteordevelopment.meteorclient.systems.modules.Module; import meteordevelopment.meteorclient.systems.modules.Modules; +import meteordevelopment.meteorclient.systems.modules.misc.InventoryTweaks; +import meteordevelopment.meteorclient.systems.modules.render.ItemHighlight; import net.minecraft.command.CommandSource; import net.minecraft.command.argument.ItemStackArgument; import net.minecraft.command.argument.ItemStackArgumentType; import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import java.util.ArrayList; +import java.util.List; public class ItemCommand extends Command { + final InventoryTweaks inventoryTweaks; + final ItemHighlight itemHighlight; + public ItemCommand() { super("item", "Manages item related modules."); + + inventoryTweaks = Modules.get().get(InventoryTweaks.class); + itemHighlight = Modules.get().get(ItemHighlight.class); } @Override public void build(LiteralArgumentBuilder builder) { - builder + buildHighlight(builder); + buildBlock(builder); + buildLock(builder); + } + + private void buildHighlight(LiteralArgumentBuilder builder) { + builder.then(literal("highlight") + .executes(context -> { + List items = itemHighlight.items.get(); + ItemStack itemStack = getItemStack(); + + if (itemStack == null) { + error("Not holding an item."); + + return SINGLE_SUCCESS; + } + + Item item = itemStack.getItem(); + + if (items.contains(item)) return SINGLE_SUCCESS; + + items.add(item); + + itemHighlight.items.set(items); + itemHighlight.info("Added " + item.toString() + " to highlighted items."); + + return SINGLE_SUCCESS; + }) + .then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)) + .executes(context -> { + List items = itemHighlight.items.get(); + Item item = context.getArgument("item", ItemStackArgument.class).getItem(); + + if (items.contains(item)) return SINGLE_SUCCESS; + + items.add(item); + + itemHighlight.items.set(items); + itemHighlight.info("Added " + item.toString() + " to highlighted items."); + + return SINGLE_SUCCESS; + }) + ) + .then(literal("clear") + .executes(context -> { + List items = itemHighlight.items.get(); + ItemStack itemStack = getItemStack(); + + if (itemStack == null) { + error("Not holding an item."); + + return SINGLE_SUCCESS; + } + + Item item = itemStack.getItem(); + + if (!items.contains(item)) return SINGLE_SUCCESS; + + items.remove(item); + + itemHighlight.items.set(items); + itemHighlight.info("Removed " + item.toString() + " from highlighted items."); + + return SINGLE_SUCCESS; + }) + .then(literal("*") + .executes(context -> { + itemHighlight.items.set(new ArrayList<>()); + itemHighlight.info("Removed all from highlighted items."); + + return SINGLE_SUCCESS; + }) + ) + .then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)) + .executes(context -> { + List items = itemHighlight.items.get(); + Item item = context.getArgument("item", ItemStackArgument.class).getItem(); + + if (!items.contains(item)) return SINGLE_SUCCESS; + + items.remove(item); + + itemHighlight.items.set(items); + itemHighlight.info("Removed " + item.toString() + " from highlighted items."); + + return SINGLE_SUCCESS; + }) + ) + ) + ); + } + + private void buildBlock(LiteralArgumentBuilder builder) { + builder.then(literal("block") + .executes(context -> { + List items = inventoryTweaks.autoDropItems.get(); + ItemStack itemStack = getItemStack(); + + if (itemStack == null) { + error("Not holding an item."); + + return SINGLE_SUCCESS; + } + + Item item = itemStack.getItem(); + + if (items.contains(item)) return SINGLE_SUCCESS; + + items.add(item); + + inventoryTweaks.autoDropItems.set(items); + inventoryTweaks.info("Added " + item.toString() + " to automatically dropped items."); + + return SINGLE_SUCCESS; + }) + .then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)) + .executes(context -> { + List items = inventoryTweaks.autoDropItems.get(); + Item item = context.getArgument("item", ItemStackArgument.class).getItem(); + + if (items.contains(item)) return SINGLE_SUCCESS; + + items.add(item); + + inventoryTweaks.autoDropItems.set(items); + inventoryTweaks.info("Added " + item.toString() + " to automatically dropped items."); + + return SINGLE_SUCCESS; + }) + ) + .then(literal("clear") + .executes(context -> { + List items = inventoryTweaks.autoDropItems.get(); + ItemStack itemStack = getItemStack(); - .then(literal("highlight") - .then(literal("add") - .then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)) + if (itemStack == null) { + error("Not holding an item."); + + return SINGLE_SUCCESS; + } + + Item item = itemStack.getItem(); + + if (!items.contains(item)) return SINGLE_SUCCESS; + + items.remove(item); + + inventoryTweaks.autoDropItems.set(items); + inventoryTweaks.info("Removed " + item.toString() + " from automatically dropped items."); + + return SINGLE_SUCCESS; + }) + .then(literal("*") .executes(context -> { - MeteorClient.LOG.info(context.getArgument("item", ItemStackArgument.class).getItem().toString()); + inventoryTweaks.autoDropItems.set(new ArrayList<>()); + inventoryTweaks.info("Removed all from automatically dropped items."); + return SINGLE_SUCCESS; }) - )) - .then(literal("remove") + ) + .then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)) .executes(context -> { + List items = inventoryTweaks.autoDropItems.get(); + Item item = context.getArgument("item", ItemStackArgument.class).getItem(); + + if (!items.contains(item)) return SINGLE_SUCCESS; + + items.remove(item); + + inventoryTweaks.autoDropItems.set(items); + inventoryTweaks.info("Removed " + item.toString() + " from automatically dropped items."); + return SINGLE_SUCCESS; }) ) - ); + ) + ); + } + + private void buildLock(LiteralArgumentBuilder builder) { + builder.then(literal("lock") + .executes(context -> { + List items = inventoryTweaks.antiDropItems.get(); + ItemStack itemStack = getItemStack(); + + if (itemStack == null) { + error("Not holding an item."); + + return SINGLE_SUCCESS; + } + + Item item = itemStack.getItem(); + + if (items.contains(item)) return SINGLE_SUCCESS; + + items.add(item); + + inventoryTweaks.antiDropItems.set(items); + inventoryTweaks.info("Added " + item.toString() + " to anti drop items."); + + return SINGLE_SUCCESS; + }) + .then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)) + .executes(context -> { + List items = inventoryTweaks.antiDropItems.get(); + Item item = context.getArgument("item", ItemStackArgument.class).getItem(); + + if (items.contains(item)) return SINGLE_SUCCESS; + + items.add(item); + + inventoryTweaks.antiDropItems.set(items); + inventoryTweaks.info("Added " + item.toString() + " to anti drop items."); + + return SINGLE_SUCCESS; + }) + ) + .then(literal("clear") + .executes(context -> { + List items = inventoryTweaks.antiDropItems.get(); + ItemStack itemStack = getItemStack(); + + if (itemStack == null) { + error("Not holding an item."); + + return SINGLE_SUCCESS; + } + + Item item = itemStack.getItem(); + + if (!items.contains(item)) return SINGLE_SUCCESS; + + items.remove(item); + + inventoryTweaks.antiDropItems.set(items); + inventoryTweaks.info("Removed " + item.toString() + " from anti drop items."); + + return SINGLE_SUCCESS; + }) + .then(literal("*") + .executes(context -> { + inventoryTweaks.antiDropItems.set(new ArrayList<>()); + inventoryTweaks.info("Removed all from anti drop items."); + + return SINGLE_SUCCESS; + }) + ) + .then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)) + .executes(context -> { + List items = inventoryTweaks.antiDropItems.get(); + Item item = context.getArgument("item", ItemStackArgument.class).getItem(); + + if (!items.contains(item)) return SINGLE_SUCCESS; + + items.remove(item); + + inventoryTweaks.antiDropItems.set(items); + inventoryTweaks.info("Removed " + item.toString() + " from anti drop items."); + + return SINGLE_SUCCESS; + }) + ) + ) + ); + } + + private ItemStack getItemStack() { + ItemStack itemStack = mc.player.getMainHandStack(); + if (itemStack == null) itemStack = mc.player.getOffHandStack(); + return itemStack.isEmpty() ? null : itemStack; } } diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/InventoryTweaks.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/InventoryTweaks.java index d9b4106e49..cb6bf9cefb 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/InventoryTweaks.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/misc/InventoryTweaks.java @@ -106,7 +106,7 @@ public class InventoryTweaks extends Module { // Anti drop - private final Setting> antiDropItems = sgAntiDrop.add(new ItemListSetting.Builder() + public final Setting> antiDropItems = sgAntiDrop.add(new ItemListSetting.Builder() .name("anti-drop-items") .description("Items to prevent dropping. Doesn't work in creative inventory screen.") .build() @@ -127,7 +127,7 @@ public class InventoryTweaks extends Module { // Auto Drop - private final Setting> autoDropItems = sgAutoDrop.add(new ItemListSetting.Builder() + public final Setting> autoDropItems = sgAutoDrop.add(new ItemListSetting.Builder() .name("auto-drop-items") .description("Items to drop.") .build() diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/ItemHighlight.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/ItemHighlight.java index 3b4d786bb1..35de69d7f7 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/ItemHighlight.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/ItemHighlight.java @@ -20,7 +20,7 @@ public class ItemHighlight extends Module { private final SettingGroup sgGeneral = settings.getDefaultGroup(); - private final Setting> items = sgGeneral.add(new ItemListSetting.Builder() + public final Setting> items = sgGeneral.add(new ItemListSetting.Builder() .name("items") .description("Items to highlight.") .build() From 3a7f0b600aa8c8614d73e2400d4d4516dba90584 Mon Sep 17 00:00:00 2001 From: Moxvallix Date: Sat, 8 Nov 2025 23:45:57 +1030 Subject: [PATCH 3/3] feat(command): refactor .item command based on feedback --- .../commands/commands/ItemCommand.java | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/ItemCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/ItemCommand.java index 7d3ce53bcf..9a1b7bcb91 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/ItemCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/ItemCommand.java @@ -76,6 +76,14 @@ private void buildHighlight(LiteralArgumentBuilder builder) { }) ) .then(literal("clear") + .executes(context -> { + itemHighlight.items.set(new ArrayList<>()); + itemHighlight.info("Removed all from highlighted items."); + + return SINGLE_SUCCESS; + }) + ) + .then(literal("remove") .executes(context -> { List items = itemHighlight.items.get(); ItemStack itemStack = getItemStack(); @@ -97,14 +105,6 @@ private void buildHighlight(LiteralArgumentBuilder builder) { return SINGLE_SUCCESS; }) - .then(literal("*") - .executes(context -> { - itemHighlight.items.set(new ArrayList<>()); - itemHighlight.info("Removed all from highlighted items."); - - return SINGLE_SUCCESS; - }) - ) .then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)) .executes(context -> { List items = itemHighlight.items.get(); @@ -163,6 +163,14 @@ private void buildBlock(LiteralArgumentBuilder builder) { }) ) .then(literal("clear") + .executes(context -> { + inventoryTweaks.autoDropItems.set(new ArrayList<>()); + inventoryTweaks.info("Removed all from automatically dropped items."); + + return SINGLE_SUCCESS; + }) + ) + .then(literal("remove") .executes(context -> { List items = inventoryTweaks.autoDropItems.get(); ItemStack itemStack = getItemStack(); @@ -184,14 +192,6 @@ private void buildBlock(LiteralArgumentBuilder builder) { return SINGLE_SUCCESS; }) - .then(literal("*") - .executes(context -> { - inventoryTweaks.autoDropItems.set(new ArrayList<>()); - inventoryTweaks.info("Removed all from automatically dropped items."); - - return SINGLE_SUCCESS; - }) - ) .then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)) .executes(context -> { List items = inventoryTweaks.autoDropItems.get(); @@ -250,6 +250,14 @@ private void buildLock(LiteralArgumentBuilder builder) { }) ) .then(literal("clear") + .executes(context -> { + inventoryTweaks.antiDropItems.set(new ArrayList<>()); + inventoryTweaks.info("Removed all from anti drop items."); + + return SINGLE_SUCCESS; + }) + ) + .then(literal("remove") .executes(context -> { List items = inventoryTweaks.antiDropItems.get(); ItemStack itemStack = getItemStack(); @@ -271,14 +279,6 @@ private void buildLock(LiteralArgumentBuilder builder) { return SINGLE_SUCCESS; }) - .then(literal("*") - .executes(context -> { - inventoryTweaks.antiDropItems.set(new ArrayList<>()); - inventoryTweaks.info("Removed all from anti drop items."); - - return SINGLE_SUCCESS; - }) - ) .then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)) .executes(context -> { List items = inventoryTweaks.antiDropItems.get();