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("数字是" + demoBlockEntity.number)); demoBlockEntity.markDirty(); } } return ActionResult.SUCCESS; } }