From 0182316d36297a09099778e7438aabafc05cf5e5 Mon Sep 17 00:00:00 2001 From: grimmauld Date: Sat, 19 Dec 2020 11:59:56 +0100 Subject: [PATCH] Waterlogged glass pipes --- .../fluids/pipes/FluidPipeBlock.java | 2 +- .../fluids/pipes/GlassFluidPipeBlock.java | 35 ++++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java index 2ed24acca..67eb4c6e2 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/FluidPipeBlock.java @@ -66,7 +66,7 @@ public class FluidPipeBlock extends SixWayBlock implements IWaterLoggable, IWren return ActionResultType.PASS; if (!world.isRemote) world.setBlockState(pos, AllBlocks.GLASS_FLUID_PIPE.getDefaultState() - .with(GlassFluidPipeBlock.AXIS, axis)); + .with(GlassFluidPipeBlock.AXIS, axis).with(BlockStateProperties.WATERLOGGED, state.get(BlockStateProperties.WATERLOGGED))); return ActionResultType.SUCCESS; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/GlassFluidPipeBlock.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/GlassFluidPipeBlock.java index 6acc3541a..2dbe5debb 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/GlassFluidPipeBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/pipes/GlassFluidPipeBlock.java @@ -2,29 +2,40 @@ package com.simibubi.create.content.contraptions.fluids.pipes; import com.simibubi.create.AllTileEntities; +import mcp.MethodsReturnNonnullByDefault; import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.block.IWaterLoggable; +import net.minecraft.fluid.Fluids; +import net.minecraft.fluid.IFluidState; +import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemUseContext; import net.minecraft.state.BooleanProperty; import net.minecraft.state.StateContainer.Builder; +import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResultType; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; -public class GlassFluidPipeBlock extends AxisPipeBlock { +import javax.annotation.ParametersAreNonnullByDefault; + + +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +public class GlassFluidPipeBlock extends AxisPipeBlock implements IWaterLoggable { public static final BooleanProperty ALT = BooleanProperty.create("alt"); public GlassFluidPipeBlock(Properties p_i48339_1_) { super(p_i48339_1_); - setDefaultState(getDefaultState().with(ALT, false)); + setDefaultState(getDefaultState().with(ALT, false).with(BlockStateProperties.WATERLOGGED, false)); } @Override protected void fillStateContainer(Builder p_206840_1_) { - super.fillStateContainer(p_206840_1_.add(ALT)); + super.fillStateContainer(p_206840_1_.add(ALT, BlockStateProperties.WATERLOGGED)); } @Override @@ -41,12 +52,26 @@ public class GlassFluidPipeBlock extends AxisPipeBlock { public ActionResultType onWrenched(BlockState state, ItemUseContext context) { if (tryRemoveBracket(context)) return ActionResultType.SUCCESS; - BlockState newState = state; + BlockState newState; World world = context.getWorld(); BlockPos pos = context.getPos(); - newState = toRegularPipe(world, pos, state); + newState = toRegularPipe(world, pos, state).with(BlockStateProperties.WATERLOGGED, state.get(BlockStateProperties.WATERLOGGED)); world.setBlockState(pos, newState, 3); return ActionResultType.SUCCESS; } + @Override + public BlockState getStateForPlacement(BlockItemUseContext context) { + IFluidState ifluidstate = context.getWorld() + .getFluidState(context.getPos()); + BlockState state = super.getStateForPlacement(context); + return state == null ? null : state.with(BlockStateProperties.WATERLOGGED, + ifluidstate.getFluid() == Fluids.WATER); + } + + @Override + public IFluidState getFluidState(BlockState state) { + return state.get(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) + : Fluids.EMPTY.getDefaultState(); + } }