User Tools

Site Tools






Blocks and Block Entities



World Generation

Recipe Types




Dynamic Data Generation

Tutorials for Minecraft 1.15

Tutorials for Minecraft 1.14

Contribute to Fabric

Extremely Strange People


Make a Block Waterloggable

To make blocks waterloggable, implement Waterloggable interface and override some methods.

public class VerticalSlabBlock extends HorizontalFacingBlock implements Waterloggable {

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.

    // Note the ''Properties'' is Don't import the wrong one.
    public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;
    // Let default value of the WATERLOGGED property become ``false``
    public VerticalSlabBlock(Settings settings) {
            .with(Properties.HORIZONTAL_FACING, Direction.NORTH)
            .with(WATERLOGGED, false);
    // Make the block recognize the property, otherwise setting the property will through exceptions.
    protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
        stateManager.add(Properties.HORIZONTAL_FACING, WATERLOGGED);

We also have to override getPlacementState, so that the block placed in water is initially waterlogged.

    public BlockState getPlacementState(ItemPlacementContext ctx) {
        return (BlockState)this.getDefaultState()
            .with(Properties.HORIZONTAL_FACING, ctx.getPlayerFacing().getOpposite())
            .with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);

Override getFluidState so that when it is waterlogged the block displays water.

    public FluidState getFluidState(BlockState state) {
        return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);

Override getStateForNeighborUpdate so that it correctly handles the flowing of water.

    public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
        if (state.get(WATERLOGGED)) {
            // 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));
        return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);

Now the block becomes waterloggable, and works correctly with water.

tutorial/waterloggable.txt · Last modified: 2022/03/20 13:39 by solidblock