pipe water logging

This commit is contained in:
LordGrimmauld 2020-06-17 16:53:36 +02:00
parent 80e680eb9c
commit dc43f10451

View file

@ -3,9 +3,13 @@ package com.simibubi.create.content.contraptions.fluids;
import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.IWaterLoggable;
import net.minecraft.block.SixWayBlock; import net.minecraft.block.SixWayBlock;
import net.minecraft.fluid.Fluids;
import net.minecraft.fluid.IFluidState;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.BlockItemUseContext;
import net.minecraft.state.StateContainer.Builder; import net.minecraft.state.StateContainer.Builder;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.Direction.Axis; import net.minecraft.util.Direction.Axis;
import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.Direction.AxisDirection;
@ -17,10 +21,11 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class FluidPipeBlock extends SixWayBlock { public class FluidPipeBlock extends SixWayBlock implements IWaterLoggable {
public FluidPipeBlock(Properties properties) { public FluidPipeBlock(Properties properties) {
super(4 / 16f, properties); super(4 / 16f, properties);
this.setDefaultState(super.getDefaultState().with(BlockStateProperties.WATERLOGGED, false));
} }
public static boolean isPipe(BlockState state) { public static boolean isPipe(BlockState state) {
@ -98,18 +103,22 @@ public class FluidPipeBlock extends SixWayBlock {
@Override @Override
protected void fillStateContainer(Builder<Block, BlockState> builder) { protected void fillStateContainer(Builder<Block, BlockState> builder) {
builder.add(NORTH, EAST, SOUTH, WEST, UP, DOWN); builder.add(NORTH, EAST, SOUTH, WEST, UP, DOWN, BlockStateProperties.WATERLOGGED);
} }
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockItemUseContext context) {
IFluidState ifluidstate = context.getWorld().getFluidState(context.getPos());
return updateBlockState(getDefaultState(), context.getNearestLookingDirection(), null, context.getWorld(), return updateBlockState(getDefaultState(), context.getNearestLookingDirection(), null, context.getWorld(),
context.getPos()); context.getPos()).with(BlockStateProperties.WATERLOGGED, Boolean.valueOf(ifluidstate.getFluid() == Fluids.WATER));
} }
@Override @Override
public BlockState updatePostPlacement(BlockState state, Direction direction, BlockState neighbourState, public BlockState updatePostPlacement(BlockState state, Direction direction, BlockState neighbourState,
IWorld world, BlockPos pos, BlockPos neighbourPos) { IWorld world, BlockPos pos, BlockPos neighbourPos) {
if (state.get(BlockStateProperties.WATERLOGGED)) {
world.getPendingFluidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
return updateBlockState(state, direction, direction.getOpposite(), world, pos); return updateBlockState(state, direction, direction.getOpposite(), world, pos);
} }
@ -139,4 +148,9 @@ public class FluidPipeBlock extends SixWayBlock {
return state.with(FACING_TO_PROPERTY_MAP.get(preferredDirection), true) return state.with(FACING_TO_PROPERTY_MAP.get(preferredDirection), true)
.with(FACING_TO_PROPERTY_MAP.get(preferredDirection.getOpposite()), true); .with(FACING_TO_PROPERTY_MAP.get(preferredDirection.getOpposite()), true);
} }
@Override
public IFluidState getFluidState(BlockState state) {
return state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : Fluids.EMPTY.getDefaultState();
}
} }