自定义门 NBT 格式
基本信息
| 属性 | 值 |
|---|---|
| 载体 | 自定义门 物品的 stackTagCompound |
| 写入方 | DoorDescriptor.writeNBT(NBTTagCompound)(DoorDescriptor.java:241-252) |
| 读取方 | new DoorDescriptor(NBTTagCompound)(CustomDoorItem.java:59-62)→ DoorDescriptor 构造器 DoorDescriptor.java:78、readNBT DoorDescriptor.java:226 |
| 字段数 | 最多 10 个键(2 个必写 + 8 个可选) |
字段定义
writeNBT 的完整写入逻辑(DoorDescriptor.java:241-252):
| NBT 键 | 类型 | 必写 | 含义 |
|---|---|---|---|
block |
int | 是 | 门方块的数字 ID(Block.getIdFromBlock(block)) |
item |
int | 是 | 门物品的数字 ID(Item.getIdFromItem(item)) |
movement |
String | 移动方式非 null 时写 | DoorRegistry.getId(movement) 返回的动作 ID |
sound |
String | 音效非 null 时写 | DoorRegistry.getId(sound) 返回的音效 ID |
openingTime |
int | 是 | 开门动画时长(tick) |
redstone |
boolean | 是 | 是否需要红石触发 |
doubleDoor |
boolean | 是 | 是否为对开门 |
autoCloseTime |
int | 是 | 自动关闭延时(0 = 不自动关) |
code |
String | 有密码时写,无密码时删除 | 数字密码 |
关键实现细节(DoorDescriptor.java:250-251):
if (hasCode()) nbt.setString("code", getCode());
else nbt.removeTag("code");
即清空密码时会主动删除 code 键,而不是写入空串——用旧 NBT 编辑工具残留的 code 键不会造成意外上锁。
可调动作与音效 ID
movement 与 sound 存的是 DoorRegistry 中的字符串 ID,由 DoorRegistry.getId(...) 取得(DoorDescriptor.java:244-245)。门工厂 GUI 下拉框中的可选项与语言文件一一对应。
18 种开合动作(en_US.lang:135-152,键前缀 door_movement.):
| ID | 显示名 | ID | 显示名 |
|---|---|---|---|
rotating_door |
Rotating | rotate_place |
Rotating and replacing |
sliding_door |
Sliding on the side | vanishing_door |
Vanishing |
sliding_up_door |
Sliding up | spinning_door |
Spinning |
sliding_split_door |
Sliding up and down | spinning_around_door |
Vortex |
rotating_split_door |
Rotating up and down | double_slide_left |
Double sliding left |
vault_door |
Vault | double_slide_right |
Double sliding right |
sliding_4ways |
Sliding four ways | double_rotate_left |
Double rotating left |
rotating_4ways |
Rotating four ways | double_rotate_right |
Double rotating right |
rotate_around |
Rotating around | ||
rotate_slide |
Rotating and sliding |
7 种门音效(en_US.lang:167-173,键前缀 gui.door_factory.door_sound.):
| ID | 显示名 |
|---|---|
silent_door |
Silent |
vanilla_door |
Vanilla door |
glass_door |
Glass door |
jail_door |
Jail door |
pneumatic_door |
Pneumatic door |
shoji_door |
Shoji door |
carriage_door |
Big Door |
各描述符使用的动作/音效组合见:
- 木门:
RotatingDoorMovement+VanillaDoorSound - 玻璃推拉门:
SlidingDoorMovement+GlassDoorSound - 窗帘:
CurtainMovement+SilentDoorSound - 特殊造型门:
SlidingUpDoorMovement/SlidingSplitDoorMovement/SaloonDoorMovement等 - 活板门:
TrapDoorMovement/SlidingTrapDoorMovement - 栅栏门:
FenceGateMovement
门工厂的写入路径
门工厂 的编辑模式直接复用 writeNBT 覆写已有门(DoorFactoryTileEntity.java:157-167):
ItemStack doors = doorEditSlot.extract(ItemUtils.FULL_STACK);
NBTTagCompound nbt = doors.stackTagCompound;
if (nbt == null) nbt = new NBTTagCompound();
buildDescriptor().writeNBT(nbt);
doors.stackTagCompound = nbt;
outputSlot.insert(doors);
buildDescriptor()(DoorFactoryTileEntity.java:187-200)把方块/物品固定为 Blocks.customDoor / Items.customDoorItem,其余 7 项取自 GUI 控件。
门工厂的创建路径
创建模式走 CustomDoorItem.fromDoorFactory(DoorFactoryTileEntity)(CustomDoorItem.java:81+),它额外处理门框与上下门板三种材料到方块的转换(含 4 个非方块物品的映射表,CustomDoorItem.java:45-50),再由 buildDescriptor().writeNBT 写出属性。
生产的前置校验(DoorFactoryTileEntity.canCreateDoor,DoorFactoryTileEntity.java:171-185)要求:
doorMovement、doorSound均非 nullopeningTime != 0- 门框槽、上面板槽、下面板槽全部非空
数值
| 数值名 | 值 | 出处 |
|---|---|---|
| NBT 字段上限 | 10 | DoorDescriptor.java:241-252 |
| 必写字段 | 7(block、item、openingTime、redstone、doubleDoor、autoCloseTime + 至多 2 个可选) | 同上 |
| 门工厂最小开门时间 | > 0 | DoorFactoryTileEntity.java:172 |
| 创建模式最少材料槽 | 3 | DoorFactoryTileEntity.java:175-177 |
交互
| 场景 | NBT 行为 |
|---|---|
| 门工厂编辑模式 | 覆写门物品 NBT,不消耗材料(DoorFactoryTileEntity.java:157-167) |
| 门工厂创建模式 | 消耗 3 个材料槽各 1 个,产出新门(DoorFactoryTileEntity.java:152-156) |
| 清空密码 | code 键被删除而非置空(DoorDescriptor.java:251) |
| 放置自定义门 | CustomDoor.getIcon 按 NBT 解析外观(CustomDoor.java:53-55) |
| 右键带密码的门 | 弹出 Digicode GUI,回车校验通过后发包到服务端 |