Pengambilan Cerdas & Distribusi Inventaris (MC 26.1.2)
Dokumen ini menjelaskan pengambilan inventaris iteratif bertahap, simulasi kapasitas, pembuatan tumpukan vanilla, dan arsitektur nol polusi NBT dari Item Clumps untuk Minecraft 26.1.2.
📊 Kotak Info Fitur
| Properti | Spesifikasi |
|---|---|
| Nama Sistem | Pembagi Inventaris Bertahap |
| Kelas Target | net.minecraft.world.entity.item.ItemEntity |
| Batas Inventaris | Kepatuhan ketat standar vanilla (64 untuk item normal, 16 untuk mutiara/telur) |
| Kebersihan Data | 100% ItemStack Vanilla Murni (Nol polusi NBT atau tag) |
| Loop Pengambilan | Iterasi bertahap (Math.min(count, maxStack)) |
| Pelacakan Statistik | Memicu statistik vanilla Stats.ITEM_PICKED_UP.get(item) |
🎒 Arsitektur Loop Pengambilan Bertahap
Di Minecraft 26.1.2, Item Clumps memasukkan mega-clump ke dalam inventaris pemain menggunakan loop bertahap yang memecah jumlah besar menjadi tumpukan vanilla yang aman (misalnya 64 item sekaligus):
┌──────────────────────────────────────────────┐
│ 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 │
└─────────────────────────┘ └─────────────────────────┘💻 Implementasi Kode Sumber Java Asli
Dari ItemEntityMixin.java di 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
}
}