容器、库存与流体
基本信息
| 属性 | 值 |
|---|---|
| 涉及包 | codechicken.lib.inventory(13 类)、codechicken.core.fluid(3 类)、codechicken.core.inventory(1 类) |
| 公开类型数 | 17 |
| 消费者 | InventoryUtils 被 ForgeMultipart import 1 次 |
功能
这一组提供与同步的容器基类,让附属模组不必重写「容器 ↔ 客户端」的数据同步逻辑。
库存实现(codechicken.lib.inventory,13 类)
| 类 | 说明 |
|---|---|
InventorySimple |
基础库存实现 |
InventoryRange |
区间库存 |
InventoryCopy |
库存拷贝 |
InventoryNBT |
NBT 持久化库存 |
ItemKey |
物品键 |
InventoryUtils |
工具方法集(NBT 读写、物品比较等) |
InventoryUtils 内部直接操作 NBT,例如 items[b].stackSize = ((NBTBase.NBTPrimitive) tag.getTag("Quantity")).func_150287_d()(InventoryUtils.java:128)与 tag.removeTag("id")(:308)——注意 1.7.10 的方法名仍为混淆名。
容器与同步(codechicken.lib.inventory)
| 类 | 说明 |
|---|---|
ContainerExtended |
支持分页/超出的容器基类 |
ContainerSynchronised |
自动同步容器基类 |
IContainerSyncVar |
可同步变量接口 |
IntegerSync |
整数同步器抽象基类,模板方法模式 |
IntegerSync 的结构是标准模板方法:
| 方法 | 行 | 作用 |
|---|---|---|
isChanged() |
IntegerSync.java:11 |
getValue() != c_value |
onChanged() |
:16 |
同步 c_value |
write(PacketCustom) |
:21 |
packet.writeInt(getValue()) |
getValue() |
:29 |
抽象,由子类实现 |
ContainerSynchronised 遍历容器内的 IContainerSyncVar 实例并调用 onChanged() / write(...),从而把「哪个槽位变了」与「怎么打包」分离。
槽位辅助
SlotDummy(可接收物品但不真正存放的虚拟槽)、SlotDummyOutput(输出槽)、SlotHandleClicks(点击拦截槽)。
流体(codechicken.core.fluid,3 类)
| 类 | 说明 |
|---|---|
ExtendedFluidTank |
扩展流体罐 |
FluidUtils |
流体工具 |
TankAccess |
罐访问抽象 |
杂项(codechicken.core.inventory,1 类)
该包下仅 1 个公开类型。
相关条目
- 网络与序列化 -
IntegerSync.write()依赖PacketCustom - CodeChicken 生态契约 - 外部模组的实际使用情况