Search in sources :

Example 1 with IWireManager

use of buildcraft.api.transport.IWireManager 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)

Example 2 with IWireManager

use of buildcraft.api.transport.IWireManager in project BuildCraft by BuildCraft.

the class TriggerPipeSignal method isTriggerActive.

@Override
public boolean isTriggerActive(IStatementContainer container, IStatementParameter[] parameters) {
    if (!(container instanceof IGate)) {
        return false;
    }
    IGate gate = (IGate) container;
    IWireManager wires = gate.getPipeHolder().getWireManager();
    if (active) {
        if (!wires.isAnyPowered(colour)) {
            return false;
        }
    } else if (wires.isAnyPowered(colour)) {
        return false;
    }
    for (IStatementParameter param : parameters) {
        if (param != null && param instanceof TriggerParameterSignal) {
            TriggerParameterSignal signal = (TriggerParameterSignal) param;
            if (signal.colour != null) {
                if (!wires.isAnyPowered(signal.colour)) {
                    return false;
                }
            } else if (wires.isAnyPowered(signal.colour)) {
                return false;
            }
        }
    }
    return true;
}
Also used : IGate(buildcraft.api.gates.IGate) IStatementParameter(buildcraft.api.statements.IStatementParameter) IWireManager(buildcraft.api.transport.IWireManager)

Example 3 with IWireManager

use of buildcraft.api.transport.IWireManager in project BuildCraft by BuildCraft.

the class GateLogic method resolveActions.

public void resolveActions() {
    int groupCount = 0;
    int groupActive = 0;
    boolean[] prevTriggers = Arrays.copyOf(triggerOn, triggerOn.length);
    boolean[] prevActions = Arrays.copyOf(actionOn, actionOn.length);
    Arrays.fill(triggerOn, false);
    Arrays.fill(actionOn, false);
    activeActions.clear();
    EnumSet<EnumDyeColor> previousBroadcasts = EnumSet.copyOf(wireBroadcasts);
    wireBroadcasts.clear();
    for (int triggerIndex = 0; triggerIndex < statements.length; triggerIndex++) {
        StatementPair pair = statements[triggerIndex];
        TriggerWrapper trigger = pair.trigger.get();
        groupCount++;
        if (trigger != null) {
            IStatementParameter[] params = new IStatementParameter[pair.trigger.getParamCount()];
            for (int p = 0; p < pair.trigger.getParamCount(); p++) {
                params[p] = pair.trigger.getParamRef(p).get();
            }
            if (trigger.isTriggerActive(this, params)) {
                groupActive++;
                triggerOn[triggerIndex] = true;
            }
        }
        if (connections.length == triggerIndex || !connections[triggerIndex]) {
            boolean allActionsActive;
            if (variant.logic == EnumGateLogic.AND) {
                allActionsActive = groupActive == groupCount;
            } else {
                allActionsActive = groupActive > 0;
            }
            for (int i = groupCount - 1; i >= 0; i--) {
                int actionIndex = triggerIndex - i;
                StatementPair fullAction = statements[actionIndex];
                ActionWrapper action = fullAction.action.get();
                actionOn[actionIndex] = allActionsActive;
                if (action != null) {
                    if (allActionsActive) {
                        StatementSlot slot = new StatementSlot();
                        slot.statement = action.delegate;
                        slot.parameters = fullAction.action.getParameters().clone();
                        slot.part = action.sourcePart;
                        activeActions.add(slot);
                        action.actionActivate(this, slot.parameters);
                        PipeEvent evt = new PipeEventActionActivate(getPipeHolder(), action.getDelegate(), slot.parameters, action.sourcePart);
                        getPipeHolder().fireEvent(evt);
                    } else {
                        action.actionDeactivated(this, fullAction.action.getParameters());
                    }
                }
            }
            groupActive = 0;
            groupCount = 0;
        }
    }
    if (!previousBroadcasts.equals(wireBroadcasts)) {
        IWireManager wires = getPipeHolder().getWireManager();
        EnumSet<EnumDyeColor> turnedOff = EnumSet.copyOf(previousBroadcasts);
        turnedOff.removeAll(wireBroadcasts);
        // FIXME: add call to "wires.stopEmittingColour(turnedOff)"
        EnumSet<EnumDyeColor> turnedOn = EnumSet.copyOf(wireBroadcasts);
        turnedOn.removeAll(previousBroadcasts);
        if (!getPipeHolder().getPipeWorld().isRemote) {
            WorldSavedDataWireSystems.get(getPipeHolder().getPipeWorld()).gatesChanged = true;
        }
    }
    if (!Arrays.equals(prevTriggers, triggerOn) || !Arrays.equals(prevActions, actionOn)) {
        sendResolveData();
    }
}
Also used : PipeEventActionActivate(buildcraft.api.transport.pipe.PipeEventActionActivate) IStatementParameter(buildcraft.api.statements.IStatementParameter) EnumDyeColor(net.minecraft.item.EnumDyeColor) IWireManager(buildcraft.api.transport.IWireManager) StatementSlot(buildcraft.api.statements.StatementSlot) PipeEvent(buildcraft.api.transport.pipe.PipeEvent)

Aggregations

IWireManager (buildcraft.api.transport.IWireManager)3 IStatementParameter (buildcraft.api.statements.IStatementParameter)2 IGate (buildcraft.api.gates.IGate)1 StatementSlot (buildcraft.api.statements.StatementSlot)1 EnumWirePart (buildcraft.api.transport.EnumWirePart)1 IPipe (buildcraft.api.transport.pipe.IPipe)1 IPipeHolder (buildcraft.api.transport.pipe.IPipeHolder)1 PipeEvent (buildcraft.api.transport.pipe.PipeEvent)1 PipeEventActionActivate (buildcraft.api.transport.pipe.PipeEventActionActivate)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1