Skip to content

Commit

Permalink
Make pipes waterloggable
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSpen210 committed Dec 24, 2019
1 parent d47254b commit 5ff4cff
Showing 1 changed file with 17 additions and 3 deletions.
Expand Up @@ -8,11 +8,14 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.DropperBlock;
import net.minecraft.block.HopperBlock;
import net.minecraft.block.IWaterLoggable;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.fluid.Fluids;
import net.minecraft.fluid.IFluidState;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.inventory.container.INamedContainerProvider;
Expand Down Expand Up @@ -44,7 +47,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class PipeBlock extends InventoryBlock implements IHidable {
public class PipeBlock extends InventoryBlock implements IHidable, IWaterLoggable {
// Facing is the direction we output to.
public static final DirectionProperty FACING = BlockStateProperties.FACING;
// These six values specify if another pipe/hopper is in this direction for us
Expand All @@ -59,6 +62,8 @@ public class PipeBlock extends InventoryBlock implements IHidable {
// We then render a longer pipe to connect with the spout model.
public static final BooleanProperty HOPPER = BooleanProperty.create("hopper");

public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;

// Direction.getIndex() -> Property. Order is D-U-N-S-W-E
public static final BooleanProperty[] DIR_ENABLED = new BooleanProperty[] {
DOWN, UP, NORTH, SOUTH, WEST, EAST
Expand All @@ -78,7 +83,9 @@ public PipeBlock() {
.with(WEST, false)
.with(UP, false)
.with(DOWN, false)
.with(HOPPER, false));
.with(HOPPER, false)
.with(WATERLOGGED, false)
);
}

/* IHidable */
Expand All @@ -99,7 +106,7 @@ public void fillItemGroup(@Nonnull ItemGroup group, NonNullList<ItemStack> stack

@Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
builder.add(FACING, NORTH, EAST, SOUTH, WEST, UP, DOWN, HOPPER);
builder.add(WATERLOGGED, FACING, NORTH, EAST, SOUTH, WEST, UP, DOWN, HOPPER);
}

@Deprecated
Expand Down Expand Up @@ -153,6 +160,7 @@ public BlockState getStateForPlacement(BlockItemUseContext context) {
return this.getDefaultState()
.with(FACING, facing)
.with(HOPPER, offsetState.getBlock() instanceof HopperBlock && offsetState.get(HopperBlock.FACING) != facing.getOpposite())
.with(WATERLOGGED, context.getWorld().getFluidState(context.getPos()).getFluid() == Fluids.WATER)
.with(UP, canConnectTo(world, pos, facing, Direction.UP))
.with(DOWN, canConnectTo(world, pos, facing, Direction.DOWN))
.with(NORTH, canConnectTo(world, pos, facing, Direction.NORTH))
Expand All @@ -161,6 +169,12 @@ public BlockState getStateForPlacement(BlockItemUseContext context) {
.with(WEST, canConnectTo(world, pos, facing, Direction.WEST));
}

@Override
@Nonnull
public IFluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state);
}

@Override
public boolean onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult trace) {
// return false if holding a pipe to make easier to place
Expand Down

0 comments on commit 5ff4cff

Please sign in to comment.