Recogida inteligente y distribución en el inventario (MC 26.1.2)
Este documento detalla la absorción iterativa por bloques en inventario, simulación de capacidad, creación de pilas vanilla y arquitectura de cero contaminación NBT de Item Clumps para Minecraft 26.1.2.
📊 Ficha técnica de características
| Propiedad | Especificación |
|---|---|
| Nombre del sistema | Despachador de inventario por fragmentos |
| Clase objetivo | net.minecraft.world.entity.item.ItemEntity |
| Límites de inventario | Estricto cumplimiento vanilla ($64\text{ para objetos normales}$, $16\text{ para perlas/huevos}$) |
| Limpieza de datos | $100%\text{ ItemStacks Vanilla puros}$ (Cero contaminación de etiquetas o NBT personalizados) |
| Bucle de recogida | Iteración por fragmentos (Math.min(count, maxStack)) |
| Seguimiento de estadísticas | Activa Stats.ITEM_PICKED_UP.get(item) vanilla |
🎒 Arquitectura de bucle de recogida por fragmentos
En Minecraft 26.1.2, Item Clumps ingresa mega-grupos en el inventario del jugador usando un bucle while fragmentado que divide grandes cantidades en pilas seguras de tamaño vanilla (ej. 64 a la vez):
┌──────────────────────────────────────────────┐
│ Player Collides with Ground Clump (e.g. 500x)│
└──────────────────────┬───────────────────────┘
│
▼
┌──────────────────────────────────────────────┐
│ Pickup Validity & Target Check │
│ - pickupDelay == 0? │
│ - target == null || target == player? │
└──────────────────────┬───────────────────────┘
│ (Pass)
▼
┌──────────────────────────────────────────────┐
│ Iterative Chunked Loop │
│ toTake = Math.min(count, maxStackSize) │
│ player.getInventory().add(chunk) │
└──────────────────────┬───────────────────────┘
│
┌─────────────────┴─────────────────┐
│ │
Inventory Has Space Inventory Becomes Full
│ │
▼ ▼
┌─────────────────────────┐ ┌─────────────────────────┐
│ Entire Clump Absorbed │ │ Partial Pickup │
│ - 500 items transferred │ │ - Transferred what fits │
│ - Clump entity removed │ │ - Remaining items stay │
│ - Sound & particles play│ │ in ground clump │
└─────────────────────────┘ └─────────────────────────┘💻 Implementación del código fuente Java real
De ItemEntityMixin.java en Minecraft 26.1.2:
java
@Inject(method = "playerTouch", at = @At("HEAD"), cancellable = true)
private void item_clumps$smartPickup(Player player, CallbackInfo ci) {
if (!DynamicGameRuleManager.getBoolean(this.level(), ItemClumpsFabric.ENABLE_CLUMPING) ||
this.level().isClientSide()) return;
int count = this.getItem().getCount();
if (count <= 1) return; // Allow vanilla to handle normal 1-count items
ItemStack baseItem = this.getItem().copy();
baseItem.setCount(1); // Ensure base count is 1 for simulation
if (this.pickupDelay == 0 && (this.target == null || this.target.equals(player.getUUID()))) {
int originalCount = count;
int maxStack = baseItem.getMaxStackSize();
while (count > 0) {
int toTake = Math.min(count, maxStack);
ItemStack chunk = baseItem.copy();
chunk.setCount(toTake);
player.getInventory().add(chunk);
int added = toTake - chunk.getCount();
if (added > 0) {
count -= added;
player.take(this, added);
player.awardStat(net.minecraft.stats.Stats.ITEM_PICKED_UP.get(baseItem.getItem()), added);
}
if (!chunk.isEmpty()) {
// Player inventory is full
break;
}
}
if (count != originalCount) {
ItemStack stack = this.getItem();
stack.setCount(count);
this.setItem(stack);
if (count <= 0) {
player.onItemPickup((ItemEntity) (Object) this);
}
}
ci.cancel(); // Prevent vanilla pickup interference
}
}