Search in sources :

Example 1 with EnumPipePart

use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.

the class BehaviourWood method selectNewDirection.

private void selectNewDirection() {
    if (pipe.getWorld().isRemote) {
        return;
    }
    EnumPipePart part = extractionFace;
    if (part == EnumPipePart.CENTER)
        part = part.next();
    int left = 6;
    while (left > 0) {
        part = part.next();
        left--;
        IConnection_BC8 connection = pipe.getConnections().get(part.face);
        if (isValidExtraction(connection)) {
            extractionFace = part;
            pipe.sendClientUpdate(this);
            pipe.sendRenderUpdate();
            return;
        }
    }
    extractionFace = EnumPipePart.CENTER;
    pipe.sendClientUpdate(this);
    pipe.sendRenderUpdate();
}
Also used : EnumPipePart(buildcraft.api.core.EnumPipePart) IConnection_BC8(buildcraft.api.transport.pipe_bc8.IConnection_BC8)

Example 2 with EnumPipePart

use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.

the class PipeFlowFluids method readPayload.

@Override
public void readPayload(int id, PacketBuffer buf, Side side) throws IOException {
    PacketBufferBC buffer = PacketBufferBC.asPacketBufferBc(buf);
    if (side == Side.CLIENT) {
        if (id == NET_FLUID_AMOUNTS || id == NET_ID_FULL_STATE) {
            boolean full = id == NET_ID_FULL_STATE;
            if (buffer.readBoolean()) {
                int fluidId = buffer.readInt();
                clientFluid = BuildCraftObjectCaches.CACHE_FLUIDS.client().retrieve(fluidId);
            }
            for (EnumPipePart part : EnumPipePart.VALUES) {
                Section section = sections.get(part);
                if (full || buffer.readBoolean()) {
                    section.target = buffer.readShort();
                    if (full) {
                        section.clientAmountLast = section.clientAmountThis = section.target;
                    }
                }
                Dir dir = buffer.readEnumValue(Dir.class);
                section.ticksInDirection = dir == Dir.NONE ? 0 : dir == Dir.IN ? COOLDOWN_INPUT : COOLDOWN_OUTPUT;
            }
            lastMessageMinus1 = lastMessage;
            lastMessage = pipe.getHolder().getPipeWorld().getTotalWorldTime();
        }
    }
}
Also used : PacketBufferBC(buildcraft.lib.net.PacketBufferBC) EnumPipePart(buildcraft.api.core.EnumPipePart)

Example 3 with EnumPipePart

use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.

the class PipeFlowFluids method moveFromPipe.

private void moveFromPipe() {
    for (EnumPipePart part : EnumPipePart.FACES) {
        Section section = sections.get(part);
        if (section.getCurrentDirection().canOutput()) {
            PipeEventFluid.SideCheck sideCheck = new PipeEventFluid.SideCheck(pipe.getHolder(), this, currentFluid);
            sideCheck.disallowAllExcept(part.face);
            pipe.getHolder().fireEvent(sideCheck);
            if (sideCheck.getOrder().size() == 1) {
                IFluidHandler fluidHandler = pipe.getHolder().getCapabilityFromPipe(part.face, CapUtil.CAP_FLUIDS);
                if (fluidHandler == null)
                    continue;
                FluidStack fluidToPush = new FluidStack(currentFluid, section.drainInternal(fluidTransferInfo.transferPerTick, false));
                if (fluidToPush.amount > 0) {
                    int filled = fluidHandler.fill(fluidToPush, true);
                    if (filled > 0) {
                        section.drainInternal(filled, true);
                        section.ticksInDirection = COOLDOWN_OUTPUT;
                    }
                }
            }
        }
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) PipeEventFluid(buildcraft.api.transport.pipe.PipeEventFluid) EnumPipePart(buildcraft.api.core.EnumPipePart) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 4 with EnumPipePart

use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.

the class PipeFlowFluids method getAmountsForRender.

@SideOnly(Side.CLIENT)
public double[] getAmountsForRender(float partialTicks) {
    double[] arr = new double[7];
    for (EnumPipePart part : EnumPipePart.VALUES) {
        Section s = sections.get(part);
        arr[part.getIndex()] = s.clientAmountLast * (1 - partialTicks) + s.clientAmountThis * (partialTicks);
    }
    return arr;
}
Also used : EnumPipePart(buildcraft.api.core.EnumPipePart) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with EnumPipePart

use of buildcraft.api.core.EnumPipePart in project BuildCraft by BuildCraft.

the class PipeFlowFluids method moveToCenter.

private void moveToCenter() {
    int transferInCount = 0;
    Section center = sections.get(EnumPipePart.CENTER);
    int spaceAvailable = capacity - center.amount;
    int flowRate = fluidTransferInfo.transferPerTick;
    List<EnumPipePart> faces = new ArrayList<>();
    Collections.addAll(faces, EnumPipePart.FACES);
    Collections.shuffle(faces);
    int[] inputPerTick = new int[6];
    for (EnumPipePart part : faces) {
        Section section = sections.get(part);
        inputPerTick[part.getIndex()] = 0;
        if (section.getCurrentDirection().canInput()) {
            inputPerTick[part.getIndex()] = section.drainInternal(flowRate, false);
            if (inputPerTick[part.getIndex()] > 0) {
                transferInCount++;
            }
        }
    }
    int[] totalOffered = Arrays.copyOf(inputPerTick, 6);
    PreMoveToCentre preMove = new PreMoveToCentre(pipe.getHolder(), this, currentFluid, Math.min(flowRate, spaceAvailable), totalOffered, inputPerTick);
    // Event handlers edit the array in-place
    pipe.getHolder().fireEvent(preMove);
    int[] fluidLeavingSide = new int[6];
    // Work out how much fluid should leave
    int left = Math.min(flowRate, spaceAvailable);
    float min = Math.min(flowRate * transferInCount, spaceAvailable) / (float) flowRate / transferInCount;
    for (EnumPipePart part : EnumPipePart.FACES) {
        Section section = sections.get(part);
        // Move liquid from input sides to the centre
        int i = part.getIndex();
        if (inputPerTick[i] > 0) {
            int amountToDrain = (int) (inputPerTick[i] * min);
            if (amountToDrain < 1) {
                amountToDrain++;
            }
            if (amountToDrain > left) {
                amountToDrain = left;
            }
            int amountToPush = section.drainInternal(amountToDrain, false);
            if (amountToPush > 0) {
                fluidLeavingSide[i] = amountToPush;
                left -= amountToPush;
            }
        }
    }
    int[] fluidEnteringCentre = Arrays.copyOf(fluidLeavingSide, 6);
    OnMoveToCentre move = new OnMoveToCentre(pipe.getHolder(), this, currentFluid, fluidLeavingSide, fluidEnteringCentre);
    pipe.getHolder().fireEvent(move);
    for (EnumPipePart part : EnumPipePart.FACES) {
        Section section = sections.get(part);
        int i = part.getIndex();
        int leaving = fluidLeavingSide[i];
        if (leaving > 0) {
            int actuallyDrained = section.drainInternal(leaving, true);
            if (actuallyDrained != leaving) {
                throw new IllegalStateException("Couldn't drain " + leaving + " from " + part + ", only drained " + actuallyDrained);
            }
            if (actuallyDrained > 0) {
                section.ticksInDirection = COOLDOWN_INPUT;
            }
            int entering = fluidEnteringCentre[i];
            if (entering > 0) {
                int actuallyFilled = center.fill(entering, true);
                if (actuallyFilled != entering) {
                    throw new IllegalStateException("Couldn't fill " + entering + " from " + part + ", only filled " + actuallyFilled);
                }
            }
        }
    }
}
Also used : EnumPipePart(buildcraft.api.core.EnumPipePart) ArrayList(java.util.ArrayList) OnMoveToCentre(buildcraft.api.transport.pipe.PipeEventFluid.OnMoveToCentre) PreMoveToCentre(buildcraft.api.transport.pipe.PipeEventFluid.PreMoveToCentre)

Aggregations

EnumPipePart (buildcraft.api.core.EnumPipePart)24 IStatement (buildcraft.api.statements.IStatement)6 PacketBufferBC (buildcraft.lib.net.PacketBufferBC)3 StatementWrapper (buildcraft.lib.statement.StatementWrapper)3 ArrayList (java.util.ArrayList)3 InvalidInputDataException (buildcraft.api.core.InvalidInputDataException)2 ISprite (buildcraft.api.core.render.ISprite)2 IAction (buildcraft.api.statements.IAction)2 IStatementParameter (buildcraft.api.statements.IStatementParameter)2 ITrigger (buildcraft.api.statements.ITrigger)2 GuiIcon (buildcraft.lib.gui.GuiIcon)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 ITriggerExternalOverride (buildcraft.api.statements.ITriggerExternalOverride)1 StatementManager (buildcraft.api.statements.StatementManager)1 EnumWirePart (buildcraft.api.transport.EnumWirePart)1 IItemPluggable (buildcraft.api.transport.IItemPluggable)1 IStripesHandler (buildcraft.api.transport.IStripesHandler)1 WireNode (buildcraft.api.transport.WireNode)1 PipeEventFluid (buildcraft.api.transport.pipe.PipeEventFluid)1 OnMoveToCentre (buildcraft.api.transport.pipe.PipeEventFluid.OnMoveToCentre)1