zh_cn:tutorial:blockentity_modify_data
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| zh_cn:tutorial:blockentity_modify_data [2025/06/11 15:58] – [序列化数据] 更新有关的写法 solidblock | zh_cn:tutorial:blockentity_modify_data [2025/06/11 16:02] (current) – [使用数据组件] solidblock | ||
|---|---|---|---|
| Line 133: | Line 133: | ||
| @Override | @Override | ||
| - | public NbtCompound toInitialChunkDataNbt() { | + | public NbtCompound toInitialChunkDataNbt(RegistryWrapper.WrapperLookup registries) { |
| - | return createNbt(); | + | return createNbt(registries); |
| } | } | ||
| </ | </ | ||
| Line 147: | Line 147: | ||
| } | } | ||
| + | // 以下两个方法,在 1.21.6 中有所改变,参见上面的示例。 | ||
| @Override | @Override | ||
| public void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { | public void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registries) { | ||
| + | super.writeNbt(nbt, | ||
| nbt.putInt(" | nbt.putInt(" | ||
| - | |||
| - | super.writeNbt(nbt, | ||
| } | } | ||
| | | ||
| Line 247: | Line 247: | ||
| } | } | ||
| + | // 仅限 1.21.5 及之前的版本: | ||
| @Override | @Override | ||
| public void removeFromCopiedStackNbt(NbtCompound nbt) { | public void removeFromCopiedStackNbt(NbtCompound nbt) { | ||
| nbt.remove(" | nbt.remove(" | ||
| + | } | ||
| + | | ||
| + | // 对于 1.21.6 及之后的版本: | ||
| + | @Override | ||
| + | public void removeFromCopiedStackData(WriteView view) { | ||
| + | view.remove(" | ||
| } | } | ||
| </ | </ | ||
| - | '' | + | '' |
zh_cn/tutorial/blockentity_modify_data.1749657504.txt.gz · Last modified: 2025/06/11 15:58 by solidblock