How to make a block that can hold water in a Minecraft mod
A waterloggable block implements SimpleWaterloggedBlock and has the WATERLOGGED block state property. Add the property in createBlockStateDefinition, set it in getStateForPlacement when the spot already holds water, return water from getFluidState when it is true, and in updateShape schedule a fluid tick so the water keeps flowing. The block should not be a full cube (use .noOcclusion()), or the water is never seen.
Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.16.5 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge. Each example was compiled against its loader and version before it shipped in Linen.
- Implement SimpleWaterloggedBlock and add BlockStateProperties.WATERLOGGED in createBlockStateDefinition.
- Set a default state with WATERLOGGED false in the constructor.
- In getStateForPlacement, set WATERLOGGED when the clicked spot holds water.
- Return Fluids.WATER.getSource(false) from getFluidState when it is waterlogged.
- In updateShape, schedule a water tick when it is waterlogged.
- Add .noOcclusion() to the properties.
For each loader and version
Section titled “For each loader and version”The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.
Fabric and NeoForge 1.20.1 to 1.20.4, Fabric 1.20, Forge 1.20 to 1.20.1
Section titled “Fabric and NeoForge 1.20.1 to 1.20.4, Fabric 1.20, Forge 1.20 to 1.20.1”Uses:
SimpleWaterloggedBlockBlockStateProperties.WATERLOGGEDBlockBehaviour.getFluidStateBlockBehaviour.updateShapeFluids.WATER
src/main/java/com/example/examplemod/block/GlassPaneBlock.java
package com.example.examplemod.block;
import net.minecraft.core.BlockPos;import net.minecraft.core.Direction;import net.minecraft.world.item.context.BlockPlaceContext;import net.minecraft.world.level.LevelAccessor;import net.minecraft.world.level.block.Block;import net.minecraft.world.level.block.SimpleWaterloggedBlock;import net.minecraft.world.level.block.state.BlockBehaviour;import net.minecraft.world.level.block.state.BlockState;import net.minecraft.world.level.block.state.StateDefinition;import net.minecraft.world.level.block.state.properties.BlockStateProperties;import net.minecraft.world.level.material.FluidState;import net.minecraft.world.level.material.Fluids;
// Glass Pane Block: a block that water can fill. WATERLOGGED is a block state property, true when the block holds water.public class GlassPaneBlock extends Block implements SimpleWaterloggedBlock { public GlassPaneBlock(BlockBehaviour.Properties properties) { super(properties); registerDefaultState(stateDefinition.any().setValue(BlockStateProperties.WATERLOGGED, false)); }
@Override public void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { builder.add(BlockStateProperties.WATERLOGGED); }
@Override public BlockState getStateForPlacement(BlockPlaceContext context) { FluidState fluid = context.getLevel().getFluidState(context.getClickedPos()); return defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, fluid.getType() == Fluids.WATER); }
@Override public FluidState getFluidState(BlockState state) { return state.getValue(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); }
@Override public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor level, BlockPos pos, BlockPos neighborPos) { if (state.getValue(BlockStateProperties.WATERLOGGED)) { level.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); } return super.updateShape(state, direction, neighborState, level, pos, neighborPos); }}It’s registered like any other block, as GlassPaneBlock: see a new block.
BlockBehaviour.Properties.of().mapColor(MapColor.GLOW_LICHEN).strength(0.5F).noOcclusion()Fabric and NeoForge 1.20.5 to 1.21.1
Section titled “Fabric and NeoForge 1.20.5 to 1.21.1”Uses:
SimpleWaterloggedBlockBlockStateProperties.WATERLOGGEDBlockBehaviour.getFluidStateBlockBehaviour.updateShapeFluids.WATER
src/main/java/com/example/examplemod/block/GlassPaneBlock.java
package com.example.examplemod.block;
import com.mojang.serialization.MapCodec;import net.minecraft.core.BlockPos;import net.minecraft.core.Direction;import net.minecraft.world.item.context.BlockPlaceContext;import net.minecraft.world.level.LevelAccessor;import net.minecraft.world.level.block.Block;import net.minecraft.world.level.block.SimpleWaterloggedBlock;import net.minecraft.world.level.block.state.BlockBehaviour;import net.minecraft.world.level.block.state.BlockState;import net.minecraft.world.level.block.state.StateDefinition;import net.minecraft.world.level.block.state.properties.BlockStateProperties;import net.minecraft.world.level.material.FluidState;import net.minecraft.world.level.material.Fluids;
// Glass Pane Block: a block that water can fill. WATERLOGGED is a block state property, true when the block holds water.public class GlassPaneBlock extends Block implements SimpleWaterloggedBlock { public static final MapCodec<GlassPaneBlock> CODEC = simpleCodec(GlassPaneBlock::new);
public GlassPaneBlock(BlockBehaviour.Properties properties) { super(properties); registerDefaultState(stateDefinition.any().setValue(BlockStateProperties.WATERLOGGED, false)); }
@Override protected MapCodec<? extends Block> codec() { return CODEC; }
@Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { builder.add(BlockStateProperties.WATERLOGGED); }
@Override public BlockState getStateForPlacement(BlockPlaceContext context) { FluidState fluid = context.getLevel().getFluidState(context.getClickedPos()); return defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, fluid.getType() == Fluids.WATER); }
@Override protected FluidState getFluidState(BlockState state) { return state.getValue(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); }
@Override protected BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor level, BlockPos pos, BlockPos neighborPos) { if (state.getValue(BlockStateProperties.WATERLOGGED)) { level.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); } return super.updateShape(state, direction, neighborState, level, pos, neighborPos); }}It’s registered like any other block, as GlassPaneBlock: see a new block.
BlockBehaviour.Properties.of().mapColor(MapColor.GLOW_LICHEN).strength(0.5F).noOcclusion()Fabric and NeoForge 1.21.2 to 1.21.10
Section titled “Fabric and NeoForge 1.21.2 to 1.21.10”Uses:
SimpleWaterloggedBlockBlockStateProperties.WATERLOGGEDBlockBehaviour.getFluidStateBlockBehaviour.updateShapeFluids.WATER
A block’s properties need its id set before the block is made (setId); register the block with the same id, or the game crashes at startup.
src/main/java/com/example/examplemod/block/GlassPaneBlock.java
package com.example.examplemod.block;
import com.mojang.serialization.MapCodec;import net.minecraft.core.BlockPos;import net.minecraft.core.Direction;import net.minecraft.world.item.context.BlockPlaceContext;import net.minecraft.util.RandomSource;import net.minecraft.world.level.LevelReader;import net.minecraft.world.level.ScheduledTickAccess;import net.minecraft.world.level.block.Block;import net.minecraft.world.level.block.SimpleWaterloggedBlock;import net.minecraft.world.level.block.state.BlockBehaviour;import net.minecraft.world.level.block.state.BlockState;import net.minecraft.world.level.block.state.StateDefinition;import net.minecraft.world.level.block.state.properties.BlockStateProperties;import net.minecraft.world.level.material.FluidState;import net.minecraft.world.level.material.Fluids;
// Glass Pane Block: a block that water can fill. WATERLOGGED is a block state property, true when the block holds water.public class GlassPaneBlock extends Block implements SimpleWaterloggedBlock { public static final MapCodec<GlassPaneBlock> CODEC = simpleCodec(GlassPaneBlock::new);
public GlassPaneBlock(BlockBehaviour.Properties properties) { super(properties); registerDefaultState(stateDefinition.any().setValue(BlockStateProperties.WATERLOGGED, false)); }
@Override protected MapCodec<? extends Block> codec() { return CODEC; }
@Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { builder.add(BlockStateProperties.WATERLOGGED); }
@Override public BlockState getStateForPlacement(BlockPlaceContext context) { FluidState fluid = context.getLevel().getFluidState(context.getClickedPos()); return defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, fluid.getType() == Fluids.WATER); }
@Override protected FluidState getFluidState(BlockState state) { return state.getValue(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); }
@Override protected BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess ticks, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, RandomSource random) { if (state.getValue(BlockStateProperties.WATERLOGGED)) { ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); } return super.updateShape(state, level, ticks, pos, direction, neighborPos, neighborState, random); }}It’s registered like any other block, as GlassPaneBlock: see a new block.
BlockBehaviour.Properties.of().setId(ResourceKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath("examplemod", "glass_pane_block"))).mapColor(MapColor.GLOW_LICHEN).strength(0.5F).noOcclusion()Fabric and NeoForge 1.21.11 to 26.2
Section titled “Fabric and NeoForge 1.21.11 to 26.2”Uses:
SimpleWaterloggedBlockBlockStateProperties.WATERLOGGEDBlockBehaviour.getFluidStateBlockBehaviour.updateShapeFluids.WATER
A block’s properties need its id set before the block is made (setId); register the block with the same id, or the game crashes at startup.
src/main/java/com/example/examplemod/block/GlassPaneBlock.java
package com.example.examplemod.block;
import com.mojang.serialization.MapCodec;import net.minecraft.core.BlockPos;import net.minecraft.core.Direction;import net.minecraft.world.item.context.BlockPlaceContext;import net.minecraft.util.RandomSource;import net.minecraft.world.level.LevelReader;import net.minecraft.world.level.ScheduledTickAccess;import net.minecraft.world.level.block.Block;import net.minecraft.world.level.block.SimpleWaterloggedBlock;import net.minecraft.world.level.block.state.BlockBehaviour;import net.minecraft.world.level.block.state.BlockState;import net.minecraft.world.level.block.state.StateDefinition;import net.minecraft.world.level.block.state.properties.BlockStateProperties;import net.minecraft.world.level.material.FluidState;import net.minecraft.world.level.material.Fluids;
// Glass Pane Block: a block that water can fill. WATERLOGGED is a block state property, true when the block holds water.public class GlassPaneBlock extends Block implements SimpleWaterloggedBlock { public static final MapCodec<GlassPaneBlock> CODEC = simpleCodec(GlassPaneBlock::new);
public GlassPaneBlock(BlockBehaviour.Properties properties) { super(properties); registerDefaultState(stateDefinition.any().setValue(BlockStateProperties.WATERLOGGED, false)); }
@Override protected MapCodec<? extends Block> codec() { return CODEC; }
@Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { builder.add(BlockStateProperties.WATERLOGGED); }
@Override public BlockState getStateForPlacement(BlockPlaceContext context) { FluidState fluid = context.getLevel().getFluidState(context.getClickedPos()); return defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, fluid.getType() == Fluids.WATER); }
@Override protected FluidState getFluidState(BlockState state) { return state.getValue(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); }
@Override protected BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess ticks, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, RandomSource random) { if (state.getValue(BlockStateProperties.WATERLOGGED)) { ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); } return super.updateShape(state, level, ticks, pos, direction, neighborPos, neighborState, random); }}It’s registered like any other block, as GlassPaneBlock: see a new block.
BlockBehaviour.Properties.of().setId(ResourceKey.create(Registries.BLOCK, Identifier.fromNamespaceAndPath("examplemod", "glass_pane_block"))).mapColor(MapColor.GLOW_LICHEN).strength(0.5F).noOcclusion()Fabric and NeoForge 26.3
Section titled “Fabric and NeoForge 26.3”Uses:
SimpleWaterloggedBlockBlockStateProperties.WATERLOGGEDBlockBehaviour.getFluidStateBlockBehaviour.updateShapeFluids.WATER
A block’s properties need its id set before the block is made (setId); register the block with the same id, or the game crashes at startup. Since 26.3 a Block no longer has a codec: there is no CODEC field and no codec() method to write.
src/main/java/com/example/examplemod/block/GlassPaneBlock.java
package com.example.examplemod.block;
import net.minecraft.core.BlockPos;import net.minecraft.core.Direction;import net.minecraft.world.item.context.BlockPlaceContext;import net.minecraft.util.RandomSource;import net.minecraft.world.level.LevelReader;import net.minecraft.world.level.ScheduledTickAccess;import net.minecraft.world.level.block.Block;import net.minecraft.world.level.block.SimpleWaterloggedBlock;import net.minecraft.world.level.block.state.BlockBehaviour;import net.minecraft.world.level.block.state.BlockState;import net.minecraft.world.level.block.state.StateDefinition;import net.minecraft.world.level.block.state.properties.BlockStateProperties;import net.minecraft.world.level.material.FluidState;import net.minecraft.world.level.material.Fluids;
// Glass Pane Block: a block that water can fill. WATERLOGGED is a block state property, true when the block holds water.public class GlassPaneBlock extends Block implements SimpleWaterloggedBlock { public GlassPaneBlock(BlockBehaviour.Properties properties) { super(properties); registerDefaultState(stateDefinition.any().setValue(BlockStateProperties.WATERLOGGED, false)); }
@Override protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { builder.add(BlockStateProperties.WATERLOGGED); }
@Override public BlockState getStateForPlacement(BlockPlaceContext context) { FluidState fluid = context.getLevel().getFluidState(context.getClickedPos()); return defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, fluid.getType() == Fluids.WATER); }
@Override protected FluidState getFluidState(BlockState state) { return state.getValue(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); }
@Override protected BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess ticks, BlockPos pos, Direction direction, BlockPos neighborPos, BlockState neighborState, RandomSource random) { if (state.getValue(BlockStateProperties.WATERLOGGED)) { ticks.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); } return super.updateShape(state, level, ticks, pos, direction, neighborPos, neighborState, random); }}It’s registered like any other block, as GlassPaneBlock: see a new block.
BlockBehaviour.Properties.of().setId(ResourceKey.create(Registries.BLOCK, Identifier.fromNamespaceAndPath("examplemod", "glass_pane_block"))).mapColor(MapColor.GLOW_LICHEN).strength(0.5F).noOcclusion()Forge 1.17.1, Fabric 1.16.5 to 1.17.1
Section titled “Forge 1.17.1, Fabric 1.16.5 to 1.17.1”Uses:
SimpleWaterloggedBlockBlockStateProperties.WATERLOGGEDBlockBehaviour.getFluidStateBlockBehaviour.updateShapeFluids.WATER
src/main/java/com/example/examplemod/block/GlassPaneBlock.java
package com.example.examplemod.block;
import net.minecraft.core.BlockPos;import net.minecraft.core.Direction;import net.minecraft.world.item.context.BlockPlaceContext;import net.minecraft.world.level.LevelAccessor;import net.minecraft.world.level.block.Block;import net.minecraft.world.level.block.SimpleWaterloggedBlock;import net.minecraft.world.level.block.state.BlockBehaviour;import net.minecraft.world.level.block.state.BlockState;import net.minecraft.world.level.block.state.StateDefinition;import net.minecraft.world.level.block.state.properties.BlockStateProperties;import net.minecraft.world.level.material.FluidState;import net.minecraft.world.level.material.Fluids;
// Glass Pane Block: a block that water can fill. WATERLOGGED is a block state property, true when the block holds water.public class GlassPaneBlock extends Block implements SimpleWaterloggedBlock { public GlassPaneBlock(BlockBehaviour.Properties properties) { super(properties); registerDefaultState(stateDefinition.any().setValue(BlockStateProperties.WATERLOGGED, false)); }
@Override public void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { builder.add(BlockStateProperties.WATERLOGGED); }
@Override public BlockState getStateForPlacement(BlockPlaceContext context) { FluidState fluid = context.getLevel().getFluidState(context.getClickedPos()); return defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, fluid.getType() == Fluids.WATER); }
@Override public FluidState getFluidState(BlockState state) { return state.getValue(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); }
@Override public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor level, BlockPos pos, BlockPos neighborPos) { if (state.getValue(BlockStateProperties.WATERLOGGED)) { level.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); } return super.updateShape(state, direction, neighborState, level, pos, neighborPos); }}It’s registered like any other block, as GlassPaneBlock: see a new block.
BlockBehaviour.Properties.of(Material.STONE).strength(0.5F).noOcclusion()Forge 1.18.2 to 1.19.4, Fabric 1.18 to 1.19.4
Section titled “Forge 1.18.2 to 1.19.4, Fabric 1.18 to 1.19.4”Uses:
SimpleWaterloggedBlockBlockStateProperties.WATERLOGGEDBlockBehaviour.getFluidStateBlockBehaviour.updateShapeFluids.WATER
src/main/java/com/example/examplemod/block/GlassPaneBlock.java
package com.example.examplemod.block;
import net.minecraft.core.BlockPos;import net.minecraft.core.Direction;import net.minecraft.world.item.context.BlockPlaceContext;import net.minecraft.world.level.LevelAccessor;import net.minecraft.world.level.block.Block;import net.minecraft.world.level.block.SimpleWaterloggedBlock;import net.minecraft.world.level.block.state.BlockBehaviour;import net.minecraft.world.level.block.state.BlockState;import net.minecraft.world.level.block.state.StateDefinition;import net.minecraft.world.level.block.state.properties.BlockStateProperties;import net.minecraft.world.level.material.FluidState;import net.minecraft.world.level.material.Fluids;
// Glass Pane Block: a block that water can fill. WATERLOGGED is a block state property, true when the block holds water.public class GlassPaneBlock extends Block implements SimpleWaterloggedBlock { public GlassPaneBlock(BlockBehaviour.Properties properties) { super(properties); registerDefaultState(stateDefinition.any().setValue(BlockStateProperties.WATERLOGGED, false)); }
@Override public void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { builder.add(BlockStateProperties.WATERLOGGED); }
@Override public BlockState getStateForPlacement(BlockPlaceContext context) { FluidState fluid = context.getLevel().getFluidState(context.getClickedPos()); return defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, fluid.getType() == Fluids.WATER); }
@Override public FluidState getFluidState(BlockState state) { return state.getValue(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); }
@Override public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor level, BlockPos pos, BlockPos neighborPos) { if (state.getValue(BlockStateProperties.WATERLOGGED)) { level.scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(level)); } return super.updateShape(state, direction, neighborState, level, pos, neighborPos); }}It’s registered like any other block, as GlassPaneBlock: see a new block.
BlockBehaviour.Properties.of(Material.STONE).strength(0.5F).noOcclusion()Forge 1.16.5
Section titled “Forge 1.16.5”Uses:
IWaterLoggableBlockStateProperties.WATERLOGGEDAbstractBlock.getFluidStateAbstractBlock.updateShapeFluids.WATER
In 1.16.5 the interface is IWaterLoggable.
src/main/java/com/example/examplemod/block/GlassPaneBlock.java
package com.example.examplemod.block;
import net.minecraft.util.math.BlockPos;import net.minecraft.util.Direction;import net.minecraft.item.BlockItemUseContext;import net.minecraft.world.IWorld;import net.minecraft.block.Block;import net.minecraft.block.IWaterLoggable;import net.minecraft.block.AbstractBlock;import net.minecraft.block.BlockState;import net.minecraft.state.StateContainer;import net.minecraft.state.properties.BlockStateProperties;import net.minecraft.fluid.FluidState;import net.minecraft.fluid.Fluids;
// Glass Pane Block: a block that water can fill. WATERLOGGED is a block state property, true when the block holds water.public class GlassPaneBlock extends Block implements IWaterLoggable { public GlassPaneBlock(AbstractBlock.Properties properties) { super(properties); registerDefaultState(stateDefinition.any().setValue(BlockStateProperties.WATERLOGGED, false)); }
@Override public void createBlockStateDefinition(StateContainer.Builder<Block, BlockState> builder) { builder.add(BlockStateProperties.WATERLOGGED); }
@Override public BlockState getStateForPlacement(BlockItemUseContext context) { FluidState fluid = context.getLevel().getFluidState(context.getClickedPos()); return defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, fluid.getType() == Fluids.WATER); }
@Override public FluidState getFluidState(BlockState state) { return state.getValue(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); }
@Override public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, IWorld world, BlockPos pos, BlockPos neighborPos) { if (state.getValue(BlockStateProperties.WATERLOGGED)) { world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world)); } return super.updateShape(state, direction, neighborState, world, pos, neighborPos); }}It’s registered like any other block, as GlassPaneBlock: see a new block.
AbstractBlock.Properties.of(Material.STONE).strength(0.5F).noOcclusion()Sources
Section titled “Sources”- https://docs.fabricmc.net/1.21.1/develop/blocks/blockstates
- https://docs.neoforged.net/docs/1.21.1/blocks/states
Related how-tos
Section titled “Related how-tos”- A block that faces the player
- A block that changes over time with random ticks
- A block that gives off light
- A block with the properties you choose
- A new block
In Linen
Section titled “In Linen”Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.