Skip to content

スマート回収とインベントリ分配 (MC 26.1.2)

本書では、Minecraft 26.1.2 におけるインベントリへの分割取得、容量シミュレーション、バニラスタック生成、NBT汚染防止を解説します。


📊 機能情報ボックス

項目仕様
システム名分割インベントリ分配エンジン
対象クラスnet.minecraft.world.entity.item.ItemEntity
インベントリ上限バニラ制限を厳守 (通常アイテム: $64$、パール/卵: $16$)
データ純度$100%\text{ 完全なバニラItemStack}$ (NBT汚染ゼロ)
回収ループ分割反復処理 (Math.min(count, maxStack))
統計追跡バニラの Stats.ITEM_PICKED_UP.get(item) を正常に実行

🎒 分割取得ループアーキテクチャ

Minecraft 26.1.2 では、Item Clumps は分割whileループを使用して、安全なバニラスタックサイズ (例: 1回につき64個) に分解しながらプレイヤーのインベントリにアイテムを分配します:

                ┌──────────────────────────────────────────────┐
                │ 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       │
        └─────────────────────────┘         └─────────────────────────┘

💻 実際のJavaソースコード実装

Minecraft 26.1.2 の ItemEntityMixin.java より:

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
    }
}

🔗 関連ドキュメント (MC 26.1.2)

Official documentation & web portal for Dasik Igaijinn mods.