Search in sources :

Example 1 with IPipe

use of buildcraft.api.transport.pipe.IPipe in project BuildCraft by BuildCraft.

the class PipeFlowPower method onTick.

@Override
public void onTick() {
    if (pipe.getHolder().getPipeWorld().isRemote) {
        return;
    }
    if (maxPower == -1) {
        reconfigure();
    }
    step();
    init();
    for (EnumFacing face : EnumFacing.VALUES) {
        Section s = sections.get(face);
        if (s.internalPower > 0) {
            long totalPowerQuery = 0;
            for (EnumFacing face2 : EnumFacing.VALUES) {
                if (face != face2) {
                    totalPowerQuery += sections.get(face2).powerQuery;
                }
            }
            if (totalPowerQuery > 0) {
                long unusedPowerQuery = totalPowerQuery;
                for (EnumFacing face2 : EnumFacing.VALUES) {
                    if (face == face2) {
                        continue;
                    }
                    Section s2 = sections.get(face2);
                    if (s2.powerQuery > 0) {
                        long watts = Math.min(BigInteger.valueOf(s.internalPower).multiply(BigInteger.valueOf(s2.powerQuery)).divide(BigInteger.valueOf(unusedPowerQuery)).longValue(), s.internalPower);
                        unusedPowerQuery -= s2.powerQuery;
                        IPipe neighbour = pipe.getConnectedPipe(face2);
                        long leftover = watts;
                        if (neighbour != null && neighbour.getFlow() instanceof PipeFlowPower && neighbour.isConnected(face2.getOpposite())) {
                            PipeFlowPower oFlow = (PipeFlowPower) neighbour.getFlow();
                            leftover = oFlow.sections.get(face2.getOpposite()).receivePowerInternal(watts);
                        } else {
                            IMjReceiver receiver = pipe.getHolder().getCapabilityFromPipe(face2, MjAPI.CAP_RECEIVER);
                            if (receiver != null && receiver.canReceive()) {
                                leftover = receiver.receivePower(watts, false);
                            }
                        }
                        long used = watts - leftover;
                        s.internalPower -= used;
                        s2.debugPowerOutput += used;
                        s.powerAverage.push((int) used);
                        s2.powerAverage.push((int) used);
                    }
                }
            }
        }
    }
    // Render compute goes here
    for (Section s : sections.values()) {
        s.powerAverage.tick();
        long value = (long) s.powerAverage.getAverage();
        long temp = Math.min(value * MjAPI.MJ / maxPower, 1 * MjAPI.MJ);
        s.displayPower = (int) (temp);
    }
    // Compute the tiles requesting power that are not power pipes
    for (EnumFacing face : EnumFacing.VALUES) {
        if (pipe.getConnectedType(face) != ConnectedType.TILE) {
            continue;
        }
        IMjReceiver recv = pipe.getHolder().getCapabilityFromPipe(face, MjAPI.CAP_RECEIVER);
        if (recv != null && recv.canReceive()) {
            long requested = recv.getPowerRequested();
            if (requested > 0) {
                requestPower(face, requested);
            }
        }
    }
    // Sum the amount of power requested on each side
    long[] transferQueryTemp = new long[6];
    for (EnumFacing face : EnumFacing.VALUES) {
        if (!pipe.isConnected(face)) {
            continue;
        }
        long query = 0;
        for (EnumFacing face2 : EnumFacing.VALUES) {
            if (face != face2) {
                query += sections.get(face2).powerQuery;
            }
        }
        transferQueryTemp[face.ordinal()] = query;
    }
    // Transfer requested power to neighbouring pipes
    for (EnumFacing face : EnumFacing.VALUES) {
        if (transferQueryTemp[face.ordinal()] <= 0 || !pipe.isConnected(face)) {
            continue;
        }
        IPipe oPipe = pipe.getHolder().getNeighbourPipe(face);
        if (oPipe == null || !(oPipe.getFlow() instanceof PipeFlowPower)) {
            continue;
        }
        PipeFlowPower oFlow = (PipeFlowPower) oPipe.getFlow();
        oFlow.requestPower(face.getOpposite(), transferQueryTemp[face.ordinal()]);
    }
    // if (tracker.markTimeIfDelay(pipe.getHolder().getPipeWorld())) {
    if (!Arrays.equals(transferQuery, transferQueryTemp)) {
        sendPayload(NET_POWER_AMOUNTS);
    }
    transferQuery = transferQueryTemp;
// }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) IPipe(buildcraft.api.transport.pipe.IPipe) IMjReceiver(buildcraft.api.mj.IMjReceiver)

Example 2 with IPipe

use of buildcraft.api.transport.pipe.IPipe in project BuildCraft by BuildCraft.

the class ItemPluggableLens method onPlace.

@Override
public PipePluggable onPlace(@Nonnull ItemStack stack, IPipeHolder holder, EnumFacing side, EntityPlayer player, EnumHand hand) {
    IPipe pipe = holder.getPipe();
    if (pipe == null || !(pipe.getFlow() instanceof IFlowItems)) {
        return null;
    }
    LensData data = getData(stack);
    SoundUtil.playBlockPlace(holder.getPipeWorld(), holder.getPipePos(), Blocks.STONE.getDefaultState());
    PluggableDefinition def = BCTransportPlugs.lens;
    return new PluggableLens(def, holder, side, data.colour, data.isFilter);
}
Also used : PluggableLens(buildcraft.transport.plug.PluggableLens) PluggableDefinition(buildcraft.api.transport.pluggable.PluggableDefinition) IFlowItems(buildcraft.api.transport.pipe.IFlowItems) IPipe(buildcraft.api.transport.pipe.IPipe)

Example 3 with IPipe

use of buildcraft.api.transport.pipe.IPipe in project BuildCraft by BuildCraft.

the class BCTransportProxy method getServerGuiElement.

@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
    BCTransportGuis gui = BCTransportGuis.get(id);
    if (gui == null)
        return null;
    TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
    switch(gui) {
        case FILTERED_BUFFER:
            {
                if (tile instanceof TileFilteredBuffer) {
                    TileFilteredBuffer filteredBuffer = (TileFilteredBuffer) tile;
                    return new ContainerFilteredBuffer_BC8(player, filteredBuffer);
                }
                break;
            }
        case PIPE_DIAMOND:
            {
                if (tile instanceof IPipeHolder) {
                    IPipeHolder holder = (IPipeHolder) tile;
                    IPipe pipe = holder.getPipe();
                    if (pipe == null)
                        return null;
                    PipeBehaviour behaviour = pipe.getBehaviour();
                    if (behaviour instanceof PipeBehaviourDiamond) {
                        PipeBehaviourDiamond diaPipe = (PipeBehaviourDiamond) behaviour;
                        return new ContainerDiamondPipe(player, diaPipe);
                    }
                }
                break;
            }
        case PIPE_DIAMOND_WOOD:
            {
                if (tile instanceof IPipeHolder) {
                    IPipeHolder holder = (IPipeHolder) tile;
                    IPipe pipe = holder.getPipe();
                    if (pipe == null)
                        return null;
                    PipeBehaviour behaviour = pipe.getBehaviour();
                    if (behaviour instanceof PipeBehaviourWoodDiamond) {
                        PipeBehaviourWoodDiamond diaPipe = (PipeBehaviourWoodDiamond) behaviour;
                        return new ContainerDiamondWoodPipe(player, diaPipe);
                    }
                }
                break;
            }
        case PIPE_EMZULI:
            {
                if (tile instanceof IPipeHolder) {
                    IPipeHolder holder = (IPipeHolder) tile;
                    IPipe pipe = holder.getPipe();
                    if (pipe == null)
                        return null;
                    PipeBehaviour behaviour = pipe.getBehaviour();
                    if (behaviour instanceof PipeBehaviourEmzuli) {
                        PipeBehaviourEmzuli emPipe = (PipeBehaviourEmzuli) behaviour;
                        return new ContainerEmzuliPipe_BC8(player, emPipe);
                    }
                }
                break;
            }
        case GATE:
            {
                int ry = y >> 3;
                EnumFacing gateSide = EnumFacing.getFront(y & 0x7);
                tile = world.getTileEntity(new BlockPos(x, ry, z));
                if (tile instanceof IPipeHolder) {
                    IPipeHolder holder = (IPipeHolder) tile;
                    PipePluggable plug = holder.getPluggable(gateSide);
                    if (plug instanceof PluggableGate) {
                        return new ContainerGate(player, ((PluggableGate) plug).logic);
                    }
                }
                break;
            }
    }
    return null;
}
Also used : IPipeHolder(buildcraft.api.transport.pipe.IPipeHolder) PipeBehaviourEmzuli(buildcraft.transport.pipe.behaviour.PipeBehaviourEmzuli) EnumFacing(net.minecraft.util.EnumFacing) PipePluggable(buildcraft.api.transport.pluggable.PipePluggable) PipeBehaviourWoodDiamond(buildcraft.transport.pipe.behaviour.PipeBehaviourWoodDiamond) PipeBehaviourDiamond(buildcraft.transport.pipe.behaviour.PipeBehaviourDiamond) TileEntity(net.minecraft.tileentity.TileEntity) ContainerFilteredBuffer_BC8(buildcraft.transport.container.ContainerFilteredBuffer_BC8) PluggableGate(buildcraft.transport.plug.PluggableGate) TileFilteredBuffer(buildcraft.transport.tile.TileFilteredBuffer) BlockPos(net.minecraft.util.math.BlockPos) ContainerEmzuliPipe_BC8(buildcraft.transport.container.ContainerEmzuliPipe_BC8) ContainerGate(buildcraft.transport.container.ContainerGate) ContainerDiamondPipe(buildcraft.transport.container.ContainerDiamondPipe) IPipe(buildcraft.api.transport.pipe.IPipe) ContainerDiamondWoodPipe(buildcraft.transport.container.ContainerDiamondWoodPipe) PipeBehaviour(buildcraft.api.transport.pipe.PipeBehaviour)

Example 4 with IPipe

use of buildcraft.api.transport.pipe.IPipe in project BuildCraft by BuildCraft.

the class ItemPluggablePulsar method onPlace.

@Override
public PipePluggable onPlace(@Nonnull ItemStack stack, IPipeHolder holder, EnumFacing side, EntityPlayer player, EnumHand hand) {
    IPipe pipe = holder.getPipe();
    if (pipe == null) {
        return null;
    }
    PipeBehaviour behaviour = pipe.getBehaviour();
    if (behaviour instanceof IMjRedstoneReceiver) {
        SoundUtil.playBlockPlace(holder.getPipeWorld(), holder.getPipePos());
        return new PluggablePulsar(BCTransportPlugs.pulsar, holder, side);
    } else {
        return null;
    }
}
Also used : PluggablePulsar(buildcraft.transport.plug.PluggablePulsar) IMjRedstoneReceiver(buildcraft.api.mj.IMjRedstoneReceiver) IPipe(buildcraft.api.transport.pipe.IPipe) PipeBehaviour(buildcraft.api.transport.pipe.PipeBehaviour)

Example 5 with IPipe

use of buildcraft.api.transport.pipe.IPipe in project BuildCraft by BuildCraft.

the class WireManager method updateBetweens.

@Override
public void updateBetweens(boolean recursive) {
    betweens.clear();
    parts.forEach((part, color) -> {
        for (EnumWireBetween between : EnumWireBetween.VALUES) {
            EnumWirePart[] betweenParts = between.parts;
            if (between.to == null) {
                if ((betweenParts[0] == part && getColorOfPart(betweenParts[1]) == color) || (betweenParts[1] == part && getColorOfPart(betweenParts[0]) == color)) {
                    betweens.put(between, color);
                }
            } else if (WireSystem.canWireConnect(holder, between.to)) {
                IPipe pipe = holder.getNeighbourPipe(between.to);
                if (pipe != null) {
                    IWireManager wireManager = pipe.getHolder().getWireManager();
                    if (betweenParts[0] == part && wireManager.getColorOfPart(betweenParts[1]) == color) {
                        betweens.put(between, color);
                    }
                }
            }
        }
    });
    if (!recursive) {
        for (EnumFacing side : EnumFacing.VALUES) {
            TileEntity tile = holder.getPipeWorld().getTileEntity(holder.getPipePos().offset(side));
            if (tile instanceof IPipeHolder) {
                ((IPipeHolder) tile).getWireManager().updateBetweens(true);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IPipeHolder(buildcraft.api.transport.pipe.IPipeHolder) EnumWirePart(buildcraft.api.transport.EnumWirePart) EnumFacing(net.minecraft.util.EnumFacing) IPipe(buildcraft.api.transport.pipe.IPipe) IWireManager(buildcraft.api.transport.IWireManager)

Aggregations

IPipe (buildcraft.api.transport.pipe.IPipe)9 EnumFacing (net.minecraft.util.EnumFacing)6 TileEntity (net.minecraft.tileentity.TileEntity)4 IPipeHolder (buildcraft.api.transport.pipe.IPipeHolder)3 PipeBehaviour (buildcraft.api.transport.pipe.PipeBehaviour)3 PipePluggable (buildcraft.api.transport.pluggable.PipePluggable)3 IFlowItems (buildcraft.api.transport.pipe.IFlowItems)2 BlockPos (net.minecraft.util.math.BlockPos)2 IItemTransactor (buildcraft.api.inventory.IItemTransactor)1 IMjReceiver (buildcraft.api.mj.IMjReceiver)1 IMjRedstoneReceiver (buildcraft.api.mj.IMjRedstoneReceiver)1 EnumWirePart (buildcraft.api.transport.EnumWirePart)1 IInjectable (buildcraft.api.transport.IInjectable)1 IWireManager (buildcraft.api.transport.IWireManager)1 ICustomPipeConnection (buildcraft.api.transport.pipe.ICustomPipeConnection)1 ConnectedType (buildcraft.api.transport.pipe.IPipe.ConnectedType)1 PipeEventHandler (buildcraft.api.transport.pipe.PipeEventHandler)1 PipeEventItem (buildcraft.api.transport.pipe.PipeEventItem)1 PipeFlow (buildcraft.api.transport.pipe.PipeFlow)1 PluggableDefinition (buildcraft.api.transport.pluggable.PluggableDefinition)1