From ec3b6eafed8b9b21227baddf0d7d7fb89c41d542 Mon Sep 17 00:00:00 2001 From: William Bradford Larcombe Date: Fri, 22 Nov 2019 17:47:48 +0000 Subject: [PATCH] Add waterlogging support (#114) * Add waterlogging support to mob heads and the hand of fate Closes #101 --- .../common/block/BlockAnimalSkull.java | 15 ++++++++++++--- .../common/block/BlockHandOfFate.java | 15 ++++++++++++--- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/main/java/its_meow/betteranimalsplus/common/block/BlockAnimalSkull.java b/src/main/java/its_meow/betteranimalsplus/common/block/BlockAnimalSkull.java index 1d863ac3..fc298574 100644 --- a/src/main/java/its_meow/betteranimalsplus/common/block/BlockAnimalSkull.java +++ b/src/main/java/its_meow/betteranimalsplus/common/block/BlockAnimalSkull.java @@ -10,10 +10,14 @@ import net.minecraft.block.BlockState; import net.minecraft.block.ContainerBlock; import net.minecraft.block.SoundType; +import net.minecraft.block.IWaterLoggable; import net.minecraft.block.material.Material; +import net.minecraft.fluid.Fluids; +import net.minecraft.fluid.IFluidState; import net.minecraft.item.BlockItemUseContext; import net.minecraft.state.DirectionProperty; import net.minecraft.state.StateContainer; +import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.util.Mirror; @@ -25,7 +29,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -public class BlockAnimalSkull extends ContainerBlock { +public class BlockAnimalSkull extends ContainerBlock implements IWaterLoggable { public static final DirectionProperty FACING_EXCEPT_DOWN = DirectionProperty.create("facing", Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP); private static final Map SHAPES = Maps @@ -38,7 +42,7 @@ public class BlockAnimalSkull extends ContainerBlock { public BlockAnimalSkull() { super(Block.Properties.create(Material.WOOL).sound(SoundType.STONE).hardnessAndResistance(0.8F)); - this.setDefaultState(this.stateContainer.getBaseState().with(FACING_EXCEPT_DOWN, Direction.NORTH)); + this.setDefaultState(this.stateContainer.getBaseState().with(FACING_EXCEPT_DOWN, Direction.NORTH).with(BlockStateProperties.WATERLOGGED, false)); } @Override @@ -94,9 +98,14 @@ public BlockState getStateForPlacement(BlockItemUseContext context) { return null; } + @Override + public IFluidState getFluidState(BlockState state) { + return state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state); + } + @Override protected void fillStateContainer(StateContainer.Builder builder) { - builder.add(FACING_EXCEPT_DOWN); + builder.add(FACING_EXCEPT_DOWN, BlockStateProperties.WATERLOGGED); } @Override diff --git a/src/main/java/its_meow/betteranimalsplus/common/block/BlockHandOfFate.java b/src/main/java/its_meow/betteranimalsplus/common/block/BlockHandOfFate.java index 773d773e..3130cab4 100644 --- a/src/main/java/its_meow/betteranimalsplus/common/block/BlockHandOfFate.java +++ b/src/main/java/its_meow/betteranimalsplus/common/block/BlockHandOfFate.java @@ -7,12 +7,16 @@ import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.HorizontalBlock; +import net.minecraft.block.IWaterLoggable; import net.minecraft.block.material.Material; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.fluid.Fluids; +import net.minecraft.fluid.IFluidState; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.state.StateContainer.Builder; +import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.util.Hand; @@ -27,7 +31,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -public class BlockHandOfFate extends HorizontalBlock { +public class BlockHandOfFate extends HorizontalBlock implements IWaterLoggable { private static VoxelShape SHAPE; @@ -39,7 +43,7 @@ public class BlockHandOfFate extends HorizontalBlock { public BlockHandOfFate() { super(Properties.create(Material.IRON).hardnessAndResistance(3.0F, 2.0F)); this.setRegistryName("handoffate"); - this.setDefaultState(this.getDefaultState().with(HorizontalBlock.HORIZONTAL_FACING, Direction.NORTH)); + this.setDefaultState(this.getDefaultState().with(HorizontalBlock.HORIZONTAL_FACING, Direction.NORTH).with(BlockStateProperties.WATERLOGGED, false)); } @Override @@ -65,9 +69,14 @@ public int getLightValue(BlockState state, IEnviromentBlockReader world, BlockPo return super.getLightValue(state, world, pos); } + @Override + public IFluidState getFluidState(BlockState state) { + return state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state); + } + @Override protected void fillStateContainer(Builder builder) { - builder.add(HorizontalBlock.HORIZONTAL_FACING); + builder.add(HorizontalBlock.HORIZONTAL_FACING, BlockStateProperties.WATERLOGGED); } @Override