Search in sources :

Example 1 with FluidTransportBehaviour

use of com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour in project Create by Creators-of-Create.

the class TransparentStraightPipeRenderer method renderSafe.

@Override
protected void renderSafe(StraightPipeTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    FluidTransportBehaviour pipe = te.getBehaviour(FluidTransportBehaviour.TYPE);
    if (pipe == null)
        return;
    for (Direction side : Iterate.directions) {
        Flow flow = pipe.getFlow(side);
        if (flow == null)
            continue;
        FluidStack fluidStack = flow.fluid;
        if (fluidStack.isEmpty())
            continue;
        LerpedFloat progress = flow.progress;
        if (progress == null)
            continue;
        float value = progress.getValue(partialTicks);
        boolean inbound = flow.inbound;
        if (value == 1) {
            if (inbound) {
                Flow opposite = pipe.getFlow(side.getOpposite());
                if (opposite == null)
                    value -= 1e-6f;
            } else {
                FluidTransportBehaviour adjacent = TileEntityBehaviour.get(te.getLevel(), te.getBlockPos().relative(side), FluidTransportBehaviour.TYPE);
                if (adjacent == null)
                    value -= 1e-6f;
                else {
                    Flow other = adjacent.getFlow(side.getOpposite());
                    if (other == null || !other.inbound && !other.complete)
                        value -= 1e-6f;
                }
            }
        }
        FluidRenderer.renderFluidStream(fluidStack, side, 3 / 16f, value, inbound, buffer, ms, light);
    }
}
Also used : LerpedFloat(com.simibubi.create.foundation.utility.animation.LerpedFloat) FluidStack(net.minecraftforge.fluids.FluidStack) FluidTransportBehaviour(com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour) Direction(net.minecraft.core.Direction) Flow(com.simibubi.create.content.contraptions.fluids.PipeConnection.Flow)

Example 2 with FluidTransportBehaviour

use of com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour in project Create by Creators-of-Create.

the class ContentObserverTileEntity method tick.

@Override
public void tick() {
    super.tick();
    BlockState state = getBlockState();
    if (turnOffTicks > 0) {
        turnOffTicks--;
        if (turnOffTicks == 0)
            level.scheduleTick(worldPosition, state.getBlock(), 1);
    }
    if (!isActive())
        return;
    Direction facing = state.getValue(ContentObserverBlock.FACING);
    BlockPos targetPos = worldPosition.relative(facing);
    // Detect items on belt
    TransportedItemStackHandlerBehaviour behaviour = TileEntityBehaviour.get(level, targetPos, TransportedItemStackHandlerBehaviour.TYPE);
    if (behaviour != null) {
        behaviour.handleCenteredProcessingOnAllItems(.45f, stack -> {
            if (!filtering.test(stack.stack) || turnOffTicks == 6)
                return TransportedResult.doNothing();
            activate();
            return TransportedResult.doNothing();
        });
        return;
    }
    // Detect fluids in pipe
    FluidTransportBehaviour fluidBehaviour = TileEntityBehaviour.get(level, targetPos, FluidTransportBehaviour.TYPE);
    if (fluidBehaviour != null) {
        for (Direction side : Iterate.directions) {
            Flow flow = fluidBehaviour.getFlow(side);
            if (flow == null || !flow.inbound || !flow.complete)
                continue;
            if (!filtering.test(flow.fluid))
                continue;
            activate();
            return;
        }
        return;
    }
    if (!observedInventory.simulate().extract().isEmpty()) {
        activate();
        return;
    }
    if (!observedTank.simulate().extractAny().isEmpty()) {
        activate();
        return;
    }
}
Also used : BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) FluidTransportBehaviour(com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour) Direction(net.minecraft.core.Direction) TransportedItemStackHandlerBehaviour(com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour) Flow(com.simibubi.create.content.contraptions.fluids.PipeConnection.Flow)

Example 3 with FluidTransportBehaviour

use of com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour in project Create by Creators-of-Create.

the class FluidPipeBlock method canConnectTo.

public static boolean canConnectTo(BlockAndTintGetter world, BlockPos neighbourPos, BlockState neighbour, Direction direction) {
    if (FluidPropagator.hasFluidCapability(world, neighbourPos, direction.getOpposite()))
        return true;
    if (VanillaFluidTargets.shouldPipesConnectTo(neighbour))
        return true;
    FluidTransportBehaviour transport = TileEntityBehaviour.get(world, neighbourPos, FluidTransportBehaviour.TYPE);
    BracketedTileEntityBehaviour bracket = TileEntityBehaviour.get(world, neighbourPos, BracketedTileEntityBehaviour.TYPE);
    if (isPipe(neighbour))
        return bracket == null || !bracket.isBracketPresent() || FluidPropagator.getStraightPipeAxis(neighbour) == direction.getAxis();
    if (transport == null)
        return false;
    return transport.canHaveFlowToward(neighbour, direction.getOpposite());
}
Also used : BracketedTileEntityBehaviour(com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour) FluidTransportBehaviour(com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour)

Aggregations

FluidTransportBehaviour (com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour)3 Flow (com.simibubi.create.content.contraptions.fluids.PipeConnection.Flow)2 Direction (net.minecraft.core.Direction)2 BracketedTileEntityBehaviour (com.simibubi.create.content.contraptions.relays.elementary.BracketedTileEntityBehaviour)1 TransportedItemStackHandlerBehaviour (com.simibubi.create.foundation.tileEntity.behaviour.belt.TransportedItemStackHandlerBehaviour)1 LerpedFloat (com.simibubi.create.foundation.utility.animation.LerpedFloat)1 BlockPos (net.minecraft.core.BlockPos)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 FluidStack (net.minecraftforge.fluids.FluidStack)1