InventoryBaubles
基本信息
| 属性 | 值 |
|---|---|
| 路径 | baubles.common.container.InventoryBaubles |
| 类型 | class |
| 接口 | IInventory |
| 包名 | baubles.common.container |
字段
| 字段 | 类型 | 说明 |
|---|---|---|
stackList |
ItemStack[] |
槽位物品数组 |
eventHandler |
Container |
关联的 GUI container(可空) |
player |
WeakReference<EntityPlayer> |
持有此栏的玩家 |
blockEvents |
boolean |
是否阻断 IBauble.onEquipped/onUnequipped 回调(GUI 同步阶段使用) |
构造
public InventoryBaubles(EntityPlayer player)
stackList 长度等于 BaubleExpandedSlots.slotsCurrentlyUsed()。
关键方法
| 方法 | 行为 |
|---|---|
getSizeInventory / getStackInSlot / getStackInSlotOnClosing |
标准 IInventory |
decrStackSize(slot, count) |
扣除槽位;扣除时调用 IBauble.onUnequipped;最后调用 syncSlotToClients |
setInventorySlotContents(slot, stack) |
设置槽位;如果 blockEvents=false 且原 item 是 IBauble,先调 onUnequipped,新 item 是 IBauble 再调 onEquipped;最后 syncSlotToClients |
getInventoryStackLimit |
返回 1 |
markDirty |
调用 player.inventory.markDirty() |
isItemValidForSlot(slot, stack) |
通过 BaublesConfig.canTypeFitSlot + BaubleExpandedSlots.getSlotType 判断;并要求 IBauble.canEquip |
saveNBT / readNBT |
写入 Baubles.Inventory NBTTagList(每条记录 Slot byte + ItemStack NBT) |
dropItems(ArrayList<EntityItem>) |
把所有非空槽位以 EntityItem 形式加到 drops 列表,清空槽位 |
dropItemsAt(ArrayList<EntityItem>, Entity entity) |
同上,但跳过 ItemStackHelper.isSoulBound 返回 true 的物品 |
syncSlotToClients(slot) |
对追踪此玩家的所有玩家(含自身)发 PacketSyncBauble |
事件流
setInventorySlotContents是核心:- 卸下旧物品 →
onUnequipped - 放入新物品 →
onEquipped
- 卸下旧物品 →
- GUI 加载初始槽位时
blockEvents=true(由 ContainerPlayerExpanded 在putStacksInSlots临时设置),避免假触发 - GuiPlayerExpanded 在每帧
updateScreen把blockEvents重置为false,让玩家手动操作能正常触发回调
灵魂绑定
dropItemsAt 与 ItemStackHelper.isSoulBound 配合:当玩家死亡时若配置了灵魂绑定附魔 ID,绑定物品不会被掉落。