漏斗与自動化流水线集成 (MC 26.1.2)
本文件详细解析 Minecraft 26.1.2 下 Item Clumps 的漏斗抽取機制、传输速率對齊、紅石分揀器稳定性及容器集成細節。
📊 特性資訊框
| 属性 | 技术规格 |
|---|---|
| 系统名称 | 漏斗滴灌式抽取引擎 |
| 目標类 | net.minecraft.world.level.block.entity.HopperBlockEntity |
| 抽取方法 | HopperBlockEntity.addItem(Container, ItemEntity) |
| 抽取速率 | 每 $8\text{ tick}$ 抽取 $1\text{ 个物品}$($2.5\text{ 个/秒}$) |
| 切片策略 | baseItem.setCount(1) |
| 自動化相容 | 100% 相容原版紅石物品分揀器与漏斗过滤器 |
⚙️ 自動化滴灌抽取架構
在原版 Minecraft 中,若掉落物堆疊 $\le 64$ 且漏斗有空位,漏斗会一次性吸收整个實體。若模组盲目允许漏斗直接吸收包含 $5,000$ 个物品的巨型聚合体,会导致漏斗瞬间爆滿或遺失数千物品。
Item Clumps 拦截 HopperBlockEntity.addItem 以强制执行滴灌抽取:
┌────────────────────────────┐
│ Hopper Tick Cycle │
│ (Every 8 Game Ticks) │
└─────────────┬──────────────┘
│
▼
┌────────────────────────────┐
│ Is Item Entity Count > 1? │
└─────────────┬──────────────┘
│
┌────────────────┴────────────────┐
│ (Yes) │ (No)
▼ ▼
┌───────────────────────────┐ ┌───────────────────────────┐
│ Clone Single Item Slice │ │ Native Vanilla Extraction │
│ baseItem = stack.copy() │ │ (Standard 1-item / stack) │
│ baseItem.setCount(1) │ └───────────────────────────┘
└─────────────┬─────────────┘
│
▼
┌───────────────────────────┐
│ Try Insert Into Hopper │
│ HopperBlockEntity.addItem │
└─────────────┬─────────────┘
│
┌────────┴────────┐
│ │
(Success) (Failed / Full)
│ │
▼ ▼
┌───────────────────┐ ┌───────────────┐
│ Shrink Ground │ │ Abort Transfer│
│ Clump by 1; │ │ Entity Retains│
│ Refresh Name Tag. │ │ Full Count. │
└───────────────────┘ └───────────────┘💻 真實源码实现参考
源自 Minecraft 26.1.2 的 HopperBlockEntityMixin.java:
java
@Inject(method = "addItem(Lnet/minecraft/world/Container;Lnet/minecraft/world/entity/item/ItemEntity;)Z", at = @At("HEAD"), cancellable = true)
private static void item_clumps$customHopperExtract(Container container, ItemEntity entity, CallbackInfoReturnable<Boolean> cir) {
ItemStack itemStack = entity.getItem();
int count = itemStack.getCount();
if (count > 1) {
// Entity is a clump. Extract exactly 1 item.
ItemStack baseItem = itemStack.copy();
baseItem.setCount(1);
ItemStack result = HopperBlockEntity.addItem(null, container, baseItem, null);
if (result.isEmpty()) {
// Hopper successfully absorbed the 1 item. Shrink entity stack.
ItemStack originalStack = entity.getItem();
originalStack.shrink(1);
entity.setItem(originalStack); // Updates standard item tracker and custom name
cir.setReturnValue(true);
} else {
// Hopper was full or couldn't take it
cir.setReturnValue(false);
}
}
}