User Tools

Site Tools


tutorial:waterloggable

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:waterloggable [2022/02/07 05:48] solidblocktutorial:waterloggable [2023/09/06 08:21] (current) – Fix syntax error drakonkinst
Line 8: Line 8:
 </code> </code>
  
-In this case, we store the ''Properties.WATERLOGGED'' as a static field in this class, and you can use ''WATERLOGGED'' to access the field. (Of course you can refuse to do that, and use ''Properties.WATERLOGGED'' every time to access it.) We have to manually make the block recognize the property, as it is not done for you by ''Waterloggable'' interface.+In this case, we store the ''Properties.WATERLOGGED'' as a static field in this class, and you can use ''WATERLOGGED'' to access the field. (Unnecessary as it looks, most vanilla Minecraft block classes do that, so we do as well. Of course you can refuse to do that, and use ''Properties.WATERLOGGED'' every time to access it, or just directly import the static field.) We have to manually make the block recognize the property, as it is not done for you by ''Waterloggable'' interface.
  
 <code java> <code java>
Line 17: Line 17:
     public VerticalSlabBlock(Settings settings) {     public VerticalSlabBlock(Settings settings) {
         super(settings);         super(settings);
-        setDefaultState(this.stateManager.getDefaultState()+        setDefaultState(getDefaultState()
             .with(Properties.HORIZONTAL_FACING, Direction.NORTH)             .with(Properties.HORIZONTAL_FACING, Direction.NORTH)
             .with(WATERLOGGED, false);             .with(WATERLOGGED, false);
Line 24: Line 24:
     // Make the block recognize the property, otherwise setting the property will through exceptions.     // Make the block recognize the property, otherwise setting the property will through exceptions.
     @Override     @Override
-    protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) { +    protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { 
-        stateManager.add(Properties.HORIZONTAL_FACING, WATERLOGGED);+        builder.add(Properties.HORIZONTAL_FACING, WATERLOGGED);
     }     }
 </code> </code>
Line 35: Line 35:
         return (BlockState)this.getDefaultState()         return (BlockState)this.getDefaultState()
             .with(Properties.HORIZONTAL_FACING, ctx.getPlayerFacing().getOpposite())             .with(Properties.HORIZONTAL_FACING, ctx.getPlayerFacing().getOpposite())
-            .with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);+            .with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).isOf(Fluids.WATER));
     }     }
 </code> </code>
- 
  
 Override ''getFluidState'' so that when it is waterlogged the block displays water. Override ''getFluidState'' so that when it is waterlogged the block displays water.
Line 49: Line 48:
  
 Override ''getStateForNeighborUpdate'' so that it correctly handles the flowing of water. Override ''getStateForNeighborUpdate'' so that it correctly handles the flowing of water.
-<code java>+<yarncode java>
     @Override     @Override
     public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {     public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
         if (state.get(WATERLOGGED)) {         if (state.get(WATERLOGGED)) {
             // This is for 1.17 and below: world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));             // This is for 1.17 and below: world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
-            world.createAndScheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));+            world.method_39281(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
         }         }
  
         return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);         return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
     }     }
-</code>+</yarncode>
  
 Now the block becomes waterloggable, and works correctly with water. Now the block becomes waterloggable, and works correctly with water.
tutorial/waterloggable.1644212929.txt.gz · Last modified: 2022/02/07 05:48 by solidblock