-
Notifications
You must be signed in to change notification settings - Fork 0
Give Command Handling
In vanilla Minecraft, the /give command is hardcoded with safety checks designed around small stack sizes (up to 100 stacks of item max stack size). When stack sizes are adjusted to thousands or millions, running /give without modification can cause memory exhaustion or drop massive item entities.
GiveCommandMixin intercepts GiveCommand.giveItem and delegates execution to GiveCommandHelper.giveItem:
public class GiveCommandHelper {
public static int giveItem(CommandSourceStack source, ItemInput input, Collection<ServerPlayer> players, int count) throws CommandSyntaxException {
ItemStack prototypeItemStack = input.createItemStack(1);
int maxStackSize = prototypeItemStack.getMaxStackSize();
long maxAllowedCountLong = (long) maxStackSize * 100;
if (count > maxAllowedCountLong) {
int displayCount = (int) Math.min(maxAllowedCountLong, Integer.MAX_VALUE);
source.sendFailure(Component.translatable("commands.give.failed.toomanyitems", displayCount, prototypeItemStack.getDisplayName()));
return 0;
}
for (ServerPlayer player : players) {
int remaining = count;
while (remaining > 0) {
ItemEntity drop;
int size = Math.min(maxStackSize, remaining);
remaining -= size;
ItemStack copyToDrop = prototypeItemStack.copyWithCount(size);
boolean added = player.getInventory().add(copyToDrop);
if (!added || !copyToDrop.isEmpty()) {
drop = player.drop(copyToDrop, false);
if (drop == null) continue;
drop.setNoPickUpDelay();
drop.setTarget(player.getUUID());
continue;
}
drop = player.drop(prototypeItemStack.copy(), false);
if (drop != null) {
drop.makeFakeItem();
}
player.level().playSound(null, player.getX(), player.getY(), player.getZ(),
SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, 0.2f,
((player.getRandom().nextFloat() - player.getRandom().nextFloat()) * 0.7f + 1.0f) * 2.0f);
player.containerMenu.broadcastChanges();
}
}
...
}
}To prevent accidental command inputs (e.g. /give @p diamond 2000000000) from locking up the server, GiveCommandHelper enforces a dynamic maximum allowed give count:
| Modified Stack Limit ( |
/give Max Allowed Item Count |
|---|---|
| 64 | |
| 128 | |
| 1,000 | |
| 1,000,000 |
๐ Repository Source Disclaimer: The documentation in this Wiki reflects the current source code state in the repository, which may include recent unreleased commits or developmental features ahead of public release builds on CurseForge and Modrinth.
Copyright ยฉ 2026 Dasik (Rifaditya). Licensed under the GNU General Public License v3.0 (GPLv3).
๐ Home
- Dynamic GameRules
- Category Stack Limits
- Container Drop Optim.
- Large Chest Overflow
- ModMenu & YACL Config
- Item Count Rendering
- Item Clumps Synergies
- Troubleshooting & FAQ
- Developer Setup
- Architecture Layout
- Mixin Reference
- Addon Override API
- Network Sync Protocol
- Give Command Handling
- Behavior Profiles
- Consumer Mods Guide
- Performance Impact
- Advancements Matrix
- Author: Dasik (Rifaditya)
- License: GPL-3.0-or-later