From 489ca7cada279c25e5f7560d3a24a7b092a100e3 Mon Sep 17 00:00:00 2001 From: IExploitableMan Date: Wed, 27 Aug 2025 20:57:48 +0300 Subject: [PATCH 1/3] Enhance `DropCommand` to support item quantity --- .../commands/commands/DropCommand.java | 38 +++++++++++++++---- .../meteorclient/utils/player/InvUtils.java | 6 +++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/DropCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/DropCommand.java index 5e0942398f..2eb79e9d2e 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/DropCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/DropCommand.java @@ -5,7 +5,9 @@ package meteordevelopment.meteorclient.commands.commands; +import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; import meteordevelopment.meteorclient.commands.Command; @@ -17,6 +19,7 @@ import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; public class DropCommand extends Command { @@ -67,17 +70,38 @@ public void build(LiteralArgumentBuilder builder) { }))); // Specific item - builder.then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)).executes(context -> drop(player -> { - ItemStack stack = ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false); + builder.then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)) + .executes(context -> drop(player -> { + dropItem(player, context, Integer.MAX_VALUE); + })) + .then(argument("amount", IntegerArgumentType.integer(1)) + .executes(context -> drop(player -> { + int amount = IntegerArgumentType.getInteger(context, "amount"); + dropItem(player, context, amount); + }))) + ); + } - if (stack == null || stack.getItem() == Items.AIR) throw NO_SUCH_ITEM.create(); + private void dropItem(ClientPlayerEntity player, CommandContext context, int amount) throws CommandSyntaxException { + ItemStack stack = ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false); + if (stack == null || stack.getItem() == Items.AIR) throw NO_SUCH_ITEM.create(); - for (int i = 0; i < player.getInventory().size(); i++) { - if (stack.getItem() == player.getInventory().getStack(i).getItem()) { - InvUtils.drop().slot(i); + for (int i = 0; i < player.getInventory().size() && amount > 0; i++) { + ItemStack invStack = player.getInventory().getStack(i); + if (invStack.isEmpty() || stack.getItem() != invStack.getItem()) continue; + + int dropCount = Math.min(amount, invStack.getCount()); + + if (dropCount == invStack.getCount()) { + InvUtils.drop().slot(i); + } else { + for (int j = 0; j < dropCount; j++) { + InvUtils.dropOne().slot(i); } } - }))); + + amount -= dropCount; + } } private int drop(PlayerConsumer consumer) throws CommandSyntaxException { diff --git a/src/main/java/meteordevelopment/meteorclient/utils/player/InvUtils.java b/src/main/java/meteordevelopment/meteorclient/utils/player/InvUtils.java index ae5f603b22..3cc2b154a9 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/player/InvUtils.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/player/InvUtils.java @@ -207,6 +207,12 @@ public static Action drop() { return ACTION; } + public static Action dropOne() { + ACTION.type = SlotActionType.THROW; + ACTION.data = 0; + return ACTION; + } + public static void dropHand() { if (!mc.player.currentScreenHandler.getCursorStack().isEmpty()) mc.interactionManager.clickSlot(mc.player.currentScreenHandler.syncId, ScreenHandler.EMPTY_SPACE_SLOT_INDEX, 0, SlotActionType.PICKUP, mc.player); } From 7bf8bb45d6ad93f4529b695b91d19d33e3086fcb Mon Sep 17 00:00:00 2001 From: IExploitableMan Date: Thu, 28 Aug 2025 00:23:41 +0300 Subject: [PATCH 2/3] Error if not enough items --- .../meteorclient/commands/commands/DropCommand.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/DropCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/DropCommand.java index 2eb79e9d2e..37a94e4a4f 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/DropCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/DropCommand.java @@ -86,6 +86,18 @@ private void dropItem(ClientPlayerEntity player, CommandContext c ItemStack stack = ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false); if (stack == null || stack.getItem() == Items.AIR) throw NO_SUCH_ITEM.create(); + int total = 0; + for (int i = 0; i < player.getInventory().size(); i++) { + ItemStack invStack = player.getInventory().getStack(i); + if (!invStack.isEmpty() && stack.getItem() == invStack.getItem()) { + total += invStack.getCount(); + } + } + if (total < amount) { + error("Not enough items to drop! Have: " + total); + return; + } + for (int i = 0; i < player.getInventory().size() && amount > 0; i++) { ItemStack invStack = player.getInventory().getStack(i); if (invStack.isEmpty() || stack.getItem() != invStack.getItem()) continue; From d703b55a919e5e8b966be6be71c151f44b739e45 Mon Sep 17 00:00:00 2001 From: Wide_Cat Date: Sat, 30 Aug 2025 12:27:14 +0100 Subject: [PATCH 3/3] revert the error changes --- .../meteorclient/commands/commands/DropCommand.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/commands/commands/DropCommand.java b/src/main/java/meteordevelopment/meteorclient/commands/commands/DropCommand.java index 37a94e4a4f..4816bedd09 100644 --- a/src/main/java/meteordevelopment/meteorclient/commands/commands/DropCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/commands/commands/DropCommand.java @@ -19,7 +19,6 @@ import net.minecraft.entity.EquipmentSlot; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.server.command.ServerCommandSource; import net.minecraft.text.Text; public class DropCommand extends Command { @@ -86,18 +85,6 @@ private void dropItem(ClientPlayerEntity player, CommandContext c ItemStack stack = ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false); if (stack == null || stack.getItem() == Items.AIR) throw NO_SUCH_ITEM.create(); - int total = 0; - for (int i = 0; i < player.getInventory().size(); i++) { - ItemStack invStack = player.getInventory().getStack(i); - if (!invStack.isEmpty() && stack.getItem() == invStack.getItem()) { - total += invStack.getCount(); - } - } - if (total < amount) { - error("Not enough items to drop! Have: " + total); - return; - } - for (int i = 0; i < player.getInventory().size() && amount > 0; i++) { ItemStack invStack = player.getInventory().getStack(i); if (invStack.isEmpty() || stack.getItem() != invStack.getItem()) continue;