public class DemoBlock extends BlockWithEntity { [...] @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { if (!world.isClient){ BlockEntity blockEntity = world.getBlockEntity(pos); if (blockEntity instanceof DemoBlockEntity demoBlockEntity) { demoBlockEntity.number++; player.sendMessage(Text.literal("Number is " + demoBlockEntity.number)); demoBlockEntity.markDirty(); } } return ActionResult.SUCCESS; } }