public class DemoBlockEntity extends BlockEntity { // Store the current value of the number private int number = 0; public DemoBlockEntity(BlockPos pos, BlockState state) { super(TutorialBlockEntityTypes.DEMO_BLOCK, pos, state); } // Serialize the BlockEntity @Override public void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup wrapper) { // Save the current value of the number to the nbt nbt.putInt("number", number); super.writeNbt(nbt, wrapper); } }