Merge pull request #3793 from MoarDm/mc1.18/fix-3744

Fix: Fluid valve isn't waterloggable
This commit is contained in:
simibubi 2022-09-22 19:46:36 +02:00 committed by GitHub
commit f6f3a82025
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<FluidValveTileEntity> {
public class FluidValveBlock extends DirectionalAxisKineticBlock
implements IAxisPipe, ITE<FluidValveTileEntity>, 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<Block, BlockState> 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();
}
}