|
5 | 5 |
|
6 | 6 | package meteordevelopment.meteorclient.commands.commands; |
7 | 7 |
|
| 8 | +import com.mojang.brigadier.arguments.IntegerArgumentType; |
8 | 9 | import com.mojang.brigadier.builder.LiteralArgumentBuilder; |
| 10 | +import com.mojang.brigadier.context.CommandContext; |
9 | 11 | import com.mojang.brigadier.exceptions.CommandSyntaxException; |
10 | 12 | import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; |
11 | 13 | import meteordevelopment.meteorclient.commands.Command; |
@@ -67,17 +69,38 @@ public void build(LiteralArgumentBuilder<CommandSource> builder) { |
67 | 69 | }))); |
68 | 70 |
|
69 | 71 | // Specific item |
70 | | - builder.then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)).executes(context -> drop(player -> { |
71 | | - ItemStack stack = ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false); |
| 72 | + builder.then(argument("item", ItemStackArgumentType.itemStack(REGISTRY_ACCESS)) |
| 73 | + .executes(context -> drop(player -> { |
| 74 | + dropItem(player, context, Integer.MAX_VALUE); |
| 75 | + })) |
| 76 | + .then(argument("amount", IntegerArgumentType.integer(1)) |
| 77 | + .executes(context -> drop(player -> { |
| 78 | + int amount = IntegerArgumentType.getInteger(context, "amount"); |
| 79 | + dropItem(player, context, amount); |
| 80 | + }))) |
| 81 | + ); |
| 82 | + } |
72 | 83 |
|
73 | | - if (stack == null || stack.getItem() == Items.AIR) throw NO_SUCH_ITEM.create(); |
| 84 | + private void dropItem(ClientPlayerEntity player, CommandContext<CommandSource> context, int amount) throws CommandSyntaxException { |
| 85 | + ItemStack stack = ItemStackArgumentType.getItemStackArgument(context, "item").createStack(1, false); |
| 86 | + if (stack == null || stack.getItem() == Items.AIR) throw NO_SUCH_ITEM.create(); |
74 | 87 |
|
75 | | - for (int i = 0; i < player.getInventory().size(); i++) { |
76 | | - if (stack.getItem() == player.getInventory().getStack(i).getItem()) { |
77 | | - InvUtils.drop().slot(i); |
| 88 | + for (int i = 0; i < player.getInventory().size() && amount > 0; i++) { |
| 89 | + ItemStack invStack = player.getInventory().getStack(i); |
| 90 | + if (invStack.isEmpty() || stack.getItem() != invStack.getItem()) continue; |
| 91 | + |
| 92 | + int dropCount = Math.min(amount, invStack.getCount()); |
| 93 | + |
| 94 | + if (dropCount == invStack.getCount()) { |
| 95 | + InvUtils.drop().slot(i); |
| 96 | + } else { |
| 97 | + for (int j = 0; j < dropCount; j++) { |
| 98 | + InvUtils.dropOne().slot(i); |
78 | 99 | } |
79 | 100 | } |
80 | | - }))); |
| 101 | + |
| 102 | + amount -= dropCount; |
| 103 | + } |
81 | 104 | } |
82 | 105 |
|
83 | 106 | private int drop(PlayerConsumer consumer) throws CommandSyntaxException { |
|
0 commit comments