Waterlogged glass pipes
This commit is contained in:
parent
5b3e1e8c38
commit
0182316d36
2 changed files with 31 additions and 6 deletions
|
@ -66,7 +66,7 @@ public class FluidPipeBlock extends SixWayBlock implements IWaterLoggable, IWren
|
||||||
return ActionResultType.PASS;
|
return ActionResultType.PASS;
|
||||||
if (!world.isRemote)
|
if (!world.isRemote)
|
||||||
world.setBlockState(pos, AllBlocks.GLASS_FLUID_PIPE.getDefaultState()
|
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;
|
return ActionResultType.SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,29 +2,40 @@ package com.simibubi.create.content.contraptions.fluids.pipes;
|
||||||
|
|
||||||
import com.simibubi.create.AllTileEntities;
|
import com.simibubi.create.AllTileEntities;
|
||||||
|
|
||||||
|
import mcp.MethodsReturnNonnullByDefault;
|
||||||
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.fluid.Fluids;
|
||||||
|
import net.minecraft.fluid.IFluidState;
|
||||||
|
import net.minecraft.item.BlockItemUseContext;
|
||||||
import net.minecraft.item.ItemUseContext;
|
import net.minecraft.item.ItemUseContext;
|
||||||
import net.minecraft.state.BooleanProperty;
|
import net.minecraft.state.BooleanProperty;
|
||||||
import net.minecraft.state.StateContainer.Builder;
|
import net.minecraft.state.StateContainer.Builder;
|
||||||
|
import net.minecraft.state.properties.BlockStateProperties;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.ActionResultType;
|
import net.minecraft.util.ActionResultType;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.World;
|
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 static final BooleanProperty ALT = BooleanProperty.create("alt");
|
||||||
|
|
||||||
public GlassFluidPipeBlock(Properties p_i48339_1_) {
|
public GlassFluidPipeBlock(Properties p_i48339_1_) {
|
||||||
super(p_i48339_1_);
|
super(p_i48339_1_);
|
||||||
setDefaultState(getDefaultState().with(ALT, false));
|
setDefaultState(getDefaultState().with(ALT, false).with(BlockStateProperties.WATERLOGGED, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void fillStateContainer(Builder<Block, BlockState> p_206840_1_) {
|
protected void fillStateContainer(Builder<Block, BlockState> p_206840_1_) {
|
||||||
super.fillStateContainer(p_206840_1_.add(ALT));
|
super.fillStateContainer(p_206840_1_.add(ALT, BlockStateProperties.WATERLOGGED));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,12 +52,26 @@ public class GlassFluidPipeBlock extends AxisPipeBlock {
|
||||||
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
public ActionResultType onWrenched(BlockState state, ItemUseContext context) {
|
||||||
if (tryRemoveBracket(context))
|
if (tryRemoveBracket(context))
|
||||||
return ActionResultType.SUCCESS;
|
return ActionResultType.SUCCESS;
|
||||||
BlockState newState = state;
|
BlockState newState;
|
||||||
World world = context.getWorld();
|
World world = context.getWorld();
|
||||||
BlockPos pos = context.getPos();
|
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);
|
world.setBlockState(pos, newState, 3);
|
||||||
return ActionResultType.SUCCESS;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue