Skip to content

Commit

Permalink
Soul Surges and Soul Pipes can now be properly waterlogged
Browse files Browse the repository at this point in the history
  • Loading branch information
Buuz135 committed Jan 21, 2024
1 parent 59bf1ea commit 3ddf9c6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +40,7 @@
import java.util.Map;
import java.util.function.Function;

public class SoulPipeBlock extends BasicTileBlock<SoulPipeBlockEntity> implements INetworkDirectionalConnection {
public class SoulPipeBlock extends BasicTileBlock<SoulPipeBlockEntity> implements INetworkDirectionalConnection, SimpleWaterloggedBlock {

public static final Map<Direction, EnumProperty<PipeState>> DIRECTIONS = new HashMap<>();
public static final Map<Direction, VoxelShape> DIR_SHAPES = ImmutableMap.<Direction, VoxelShape>builder()
Expand All @@ -59,8 +62,9 @@ public class SoulPipeBlock extends BasicTileBlock<SoulPipeBlockEntity> 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
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +28,7 @@
import javax.annotation.Nullable;
import java.util.stream.Stream;

public class SoulSurgeBlock extends BasicTileBlock<SoulSurgeBlockEntity> implements INetworkDirectionalConnection {
public class SoulSurgeBlock extends BasicTileBlock<SoulSurgeBlockEntity> implements INetworkDirectionalConnection, SimpleWaterloggedBlock {

public static final BooleanProperty ENABLED = BooleanProperty.create("enabled");
public static final BooleanProperty TOP_CONN = BooleanProperty.create("top");
Expand Down Expand Up @@ -92,8 +93,8 @@ public class SoulSurgeBlock extends BasicTileBlock<SoulSurgeBlockEntity> 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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -268,6 +274,12 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
stateBuilder.add(DOWN_CONN);
stateBuilder.add(EAST_CONN);
stateBuilder.add(WEST_CONN);
stateBuilder.add(BlockStateProperties.WATERLOGGED);
}

@Override
public FluidState getFluidState(BlockState p_56969_) {
return p_56969_.getValue(BlockStateProperties.WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(p_56969_);
}

@Override
Expand Down

0 comments on commit 3ddf9c6

Please sign in to comment.