From a398d64df65ff4a34ac83292ba888da66478eda8 Mon Sep 17 00:00:00 2001 From: MoarDm Date: Sat, 17 Sep 2022 17:12:39 +0300 Subject: [PATCH] Fix: Fluid valve isn't waterloggable #3744 --- .../fluids/pipes/FluidValveBlock.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveBlock.java index a9bed692f..988e2b18e 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidValveBlock.java @@ -9,6 +9,7 @@ import com.simibubi.create.AllTileEntities; import com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock; import com.simibubi.create.content.contraptions.fluids.FluidPropagator; import com.simibubi.create.foundation.block.ITE; +import com.simibubi.create.foundation.block.ProperWaterloggedBlock; import com.simibubi.create.foundation.utility.Iterate; import net.minecraft.core.BlockPos; @@ -16,26 +17,33 @@ import net.minecraft.core.Direction; import net.minecraft.core.Direction.Axis; import net.minecraft.network.protocol.game.DebugPackets; import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition.Builder; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.pathfinder.PathComputationType; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.ticks.TickPriority; -public class FluidValveBlock extends DirectionalAxisKineticBlock implements IAxisPipe, ITE { +public class FluidValveBlock extends DirectionalAxisKineticBlock + implements IAxisPipe, ITE, ProperWaterloggedBlock { public static final BooleanProperty ENABLED = BooleanProperty.create("enabled"); public FluidValveBlock(Properties properties) { super(properties); registerDefaultState(defaultBlockState().setValue(ENABLED, false)); + registerDefaultState(defaultBlockState().setValue(WATERLOGGED, false)); } @Override @@ -46,7 +54,7 @@ public class FluidValveBlock extends DirectionalAxisKineticBlock implements IAxi @Override protected void createBlockStateDefinition(Builder builder) { - super.createBlockStateDefinition(builder.add(ENABLED)); + super.createBlockStateDefinition(builder.add(ENABLED, WATERLOGGED)); } @Override @@ -125,7 +133,7 @@ public class FluidValveBlock extends DirectionalAxisKineticBlock implements IAxi public void tick(BlockState state, ServerLevel world, BlockPos pos, Random r) { FluidPropagator.propagateChangedPipe(world, pos, state); } - + @Override public boolean isPathfindable(BlockState state, BlockGetter reader, BlockPos pos, PathComputationType type) { return false; @@ -141,4 +149,22 @@ public class FluidValveBlock extends DirectionalAxisKineticBlock implements IAxi return AllTileEntities.FLUID_VALVE.get(); } + @Override + public BlockState getStateForPlacement(BlockPlaceContext context) { + return withWater(super.getStateForPlacement(context), context); + } + + @Override + public BlockState updateShape(BlockState state, Direction direction, BlockState neighbourState, LevelAccessor world, + BlockPos pos, BlockPos neighbourPos) { + updateWater(world, state, pos); + return state; + } + @Override + public FluidState getFluidState(BlockState state) { + return state.getValue(BlockStateProperties.WATERLOGGED) + ? Fluids.WATER.getSource(false) + : Fluids.EMPTY.defaultFluidState(); + } + }