Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -67,17 +69,38 @@ public void build(LiteralArgumentBuilder<CommandSource> 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<CommandSource> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down