public class DemoBlockEntity extends BlockEntity { // 储存数字的当前值 private int number = 7; public DemoBlockEntity(BlockPos pos, BlockState state) { super(TutorialBlockEntityTypes.DEMO_BLOCK, pos, state); } // 序列化方块实体 @Override public void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapper) { // 将数字的当前值保存到 nbt nbt.putInt("number", number); super.writeNbt(nbt, wrapper); } }