From 3ddf9c643b2fb8142e439522e092d43a944c80db Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Sun, 21 Jan 2024 18:45:13 +0100 Subject: [PATCH] Soul Surges and Soul Pipes can now be properly waterlogged --- .../block/SoulPipeBlock.java | 14 ++++++++-- .../block/SoulSurgeBlock.java | 28 +++++++++++++------ 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/buuz135/industrialforegoingsouls/block/SoulPipeBlock.java b/src/main/java/com/buuz135/industrialforegoingsouls/block/SoulPipeBlock.java index 1b370da..f08fd29 100644 --- a/src/main/java/com/buuz135/industrialforegoingsouls/block/SoulPipeBlock.java +++ b/src/main/java/com/buuz135/industrialforegoingsouls/block/SoulPipeBlock.java @@ -19,12 +19,15 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.block.state.properties.Property; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.material.Fluids; import net.minecraft.world.phys.shapes.BooleanOp; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; @@ -37,7 +40,7 @@ import java.util.Map; import java.util.function.Function; -public class SoulPipeBlock extends BasicTileBlock implements INetworkDirectionalConnection { +public class SoulPipeBlock extends BasicTileBlock implements INetworkDirectionalConnection, SimpleWaterloggedBlock { public static final Map> DIRECTIONS = new HashMap<>(); public static final Map DIR_SHAPES = ImmutableMap.builder() @@ -59,8 +62,9 @@ public class SoulPipeBlock extends BasicTileBlock implement } public SoulPipeBlock() { - super("soul_network_pipe", Properties.copy(Blocks.IRON_BLOCK), SoulPipeBlockEntity.class); + super("soul_network_pipe", Properties.copy(Blocks.IRON_BLOCK).forceSolidOn(), SoulPipeBlockEntity.class); setItemGroup(IndustrialForegoingSouls.TAB); + this.registerDefaultState(this.defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, false)); } @Override @@ -79,7 +83,6 @@ private BlockState createState(Level world, BlockPos pos, BlockState curr) { var fluid = world.getFluidState(pos); if (fluid.is(FluidTags.WATER) && fluid.getAmount() == 8) state = state.setValue(BlockStateProperties.WATERLOGGED, true); - for (var dir : Direction.values()) { var prop = DIRECTIONS.get(dir); var type = this.getConnectionType(world, pos, dir, state); @@ -187,6 +190,11 @@ public void animateTick(BlockState state, Level level, BlockPos pos, RandomSourc } } + @Override + public FluidState getFluidState(BlockState p_56969_) { + return p_56969_.getValue(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(p_56969_); + } + public enum PipeState implements StringRepresentable { NO, PIPE, diff --git a/src/main/java/com/buuz135/industrialforegoingsouls/block/SoulSurgeBlock.java b/src/main/java/com/buuz135/industrialforegoingsouls/block/SoulSurgeBlock.java index 3dcd185..dafa79f 100644 --- a/src/main/java/com/buuz135/industrialforegoingsouls/block/SoulSurgeBlock.java +++ b/src/main/java/com/buuz135/industrialforegoingsouls/block/SoulSurgeBlock.java @@ -8,17 +8,18 @@ import com.hrznstudio.titanium.util.FacingUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.tags.FluidTags; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.Mirror; -import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.level.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; +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.phys.shapes.BooleanOp; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.Shapes; @@ -27,7 +28,7 @@ import javax.annotation.Nullable; import java.util.stream.Stream; -public class SoulSurgeBlock extends BasicTileBlock implements INetworkDirectionalConnection { +public class SoulSurgeBlock extends BasicTileBlock implements INetworkDirectionalConnection, SimpleWaterloggedBlock { public static final BooleanProperty ENABLED = BooleanProperty.create("enabled"); public static final BooleanProperty TOP_CONN = BooleanProperty.create("top"); @@ -92,8 +93,8 @@ public class SoulSurgeBlock extends BasicTileBlock impleme public SoulSurgeBlock() { - super("soul_surge", Properties.copy(Blocks.IRON_BLOCK), SoulSurgeBlockEntity.class); - this.registerDefaultState(this.defaultBlockState().setValue(ENABLED, true).setValue(TOP_CONN, false)); + super("soul_surge", Properties.copy(Blocks.IRON_BLOCK).forceSolidOn(), SoulSurgeBlockEntity.class); + this.registerDefaultState(this.defaultBlockState().setValue(ENABLED, true).setValue(TOP_CONN, false).setValue(BlockStateProperties.WATERLOGGED, false)); } @Override @@ -190,7 +191,12 @@ public BlockState getStateForPlacement(BlockPlaceContext context) { var upConnection = checkSurgeConnection(Direction.SOUTH, FacingUtil.Sideness.TOP, context.getClickedFace(), context.getLevel(), context.getClickedPos()); var downConnection = checkSurgeConnection(Direction.NORTH, FacingUtil.Sideness.BOTTOM, context.getClickedFace(), context.getLevel(), context.getClickedPos()); - return this.defaultBlockState() + var state = this.defaultBlockState(); + var fluid = context.getLevel().getFluidState(context.getClickedPos()); + if (fluid.is(FluidTags.WATER) && fluid.getAmount() == 8) + state = state.setValue(BlockStateProperties.WATERLOGGED, true); + + return state .setValue(RotatableBlock.FACING_ALL, context.getClickedFace()) .setValue(TOP_CONN, pipeConnection) .setValue(EAST_CONN, eastConnection) @@ -268,6 +274,12 @@ protected void createBlockStateDefinition(StateDefinition.Builder