Component

基本信息

api.diagram.component.Component —— 统一物品与流体的顶层接口。 源码注释:

Interface to allow us to handle both items and fluids. Each Component contains either an Item or a Fluid. This class is intended to help with comparing different types of items and fluids, ignoring concrete details such as stack size. NBT is however included in this class, as it is sometimes a concrete detail (e.g. enchantments) and sometimes part of the definition of an object.

两个实现

实现 代表
ItemComponent Item + damage + NBT
FluidComponent Fluid + NBT

ComponentType 枚举

Component.ComponentType 区分组件是 ITEM 还是 FLUID, 由 DisplayComponent.type() 暴露 —— 渲染与匹配时据此决定画物品图标还是流体图标。

与栈数的关系

Component 不含堆叠数;堆叠数属于 DisplayComponent。 ItemComponent.DEFAULT_STACK_SIZE = 1, FluidComponent.DEFAULT_STACK_SIZE = 1000(两个不同的常量,别混用)。

NBT 的参与

尽管比较时忽略堆叠数,NBT 参与相等与比较 —— 这就是 ImmutableNbtWrapper 存在的原因: 不同物品堆叠数相同但 NBT 不同时必须区分(附魔、GT 自定义工具属性)。

相关条目

源码

  • src/main/java/com/github/dcysteine/neicustomdiagram/api/diagram/component/Component.java