清空(Clear Grid)
基本信息
| 属性 | 值 |
|---|---|
| 键位 ID | key.craftingtweaks.clear |
| 默认按键 | Keyboard.KEY_NONE(未绑定) |
| 分类 | key.categories.craftingtweaks |
| 注册位置 | ClientProxy.init() → ClientRegistry.registerKeyBinding |
| 触发方式 | TickEvent.ClientTickEvent 边沿触发 |
英文显示名 Clear Grid,中文「清空」。
触发条件
与 旋转 完全相同:需已登记的容器、getModSupportState 为
ENABLED 或 HOTKEYS_ONLY、NEI 输入框未聚焦。
行为
| 按键组合 | 行为 | 封包字段 |
|---|---|---|
| 直接按 | 普通清空:把网格内物品退回背包;背包放不下的留在原槽 | force = false |
| 按住 Shift | 强制清空:背包放不下的物品直接丢在地上 | force = true |
isShiftDown 作为 force 随 MessageClear(id 1)发送。
与 phantomItems 的交互
「普通清空是否退回背包」由容器的 phantomItems 决定
(见 容器注册表):
| phantomItems | 普通清空(force=false) | 强制清空(force=true) |
|---|---|---|
false |
逐槽尝试 addItemStackToInventory;失败则保留该槽物品,继续下一槽 |
失败则 dropPlayerItemWithRandomChoice(itemStack, false) 丢出并清空该槽 |
true |
直接 setInventorySlotContents(slotIndex, null),不回背包(幽灵物品,本就不占玩家库存) |
同左(forced 分支被 !phantomItems 短路掉) |
phantomItems 为 true 时 SimpleTweakProviderImpl.requiresServerSide() 也返回 true,
所以清空必然走服务端路径 —— 这正是幽灵物品容器必须由服务端处理的原因。
⚠️ DefaultProviderV2Impl.clearGrid 在 phantomItems == false 分支里没有判空,
空槽同样进入 addItemStackToInventory 调用;其返回 false 时,若 forced 为真
会走到丢物语句。