Search in sources :

Example 1 with StatementSlot

use of buildcraft.api.statements.StatementSlot in project BuildCraft by BuildCraft.

the class DockingStationPipe method getRequest.

@Override
public ItemStack getRequest(int slot) {
    int facing = (slot & 0x70) >> 4;
    int action = (slot & 0xc) >> 2;
    int param = slot & 0x3;
    if (facing >= 6) {
        return null;
    }
    EnumFacing side = EnumFacing.getFront(facing);
    IGate gate = getPipe().getPipe().getGate(side);
    if (gate == null) {
        return null;
    }
    List<IStatement> actions = gate.getActions();
    if (actions.size() <= action) {
        return null;
    }
    if (actions.get(action) != BuildCraftRobotics.actionStationRequestItems) {
        return null;
    }
    List<StatementSlot> activeActions = gate.getActiveActions();
    StatementSlot slotStmt = null;
    for (StatementSlot stmt : activeActions) {
        if (stmt.statement == actions.get(action)) {
            slotStmt = stmt;
            break;
        }
    }
    if (slotStmt == null) {
        return null;
    }
    if (slotStmt.parameters.length <= param) {
        return null;
    }
    if (slotStmt.parameters[param] == null) {
        return null;
    }
    return slotStmt.parameters[param].getItemStack();
}
Also used : StatementSlot(buildcraft.api.statements.StatementSlot) IGate(buildcraft.api.gates.IGate) EnumFacing(net.minecraft.util.EnumFacing) IStatement(buildcraft.api.statements.IStatement)

Example 2 with StatementSlot

use of buildcraft.api.statements.StatementSlot in project BuildCraft by BuildCraft.

the class ActionRobotFilterTool method getGateFilterStacks.

public static Collection<ItemStack> getGateFilterStacks(DockingStation station) {
    ArrayList<ItemStack> result = new ArrayList<>();
    for (StatementSlot slot : station.getActiveActions()) {
        if (slot.statement instanceof ActionRobotFilterTool) {
            for (IStatementParameter p : slot.parameters) {
                if (p != null && p instanceof StatementParameterItemStack) {
                    StatementParameterItemStack param = (StatementParameterItemStack) p;
                    ItemStack stack = param.getItemStack();
                    if (stack != null) {
                        result.add(stack);
                    }
                }
            }
        }
    }
    return result;
}
Also used : StatementSlot(buildcraft.api.statements.StatementSlot) ArrayList(java.util.ArrayList) IStatementParameter(buildcraft.api.statements.IStatementParameter) StatementParameterItemStack(buildcraft.api.statements.StatementParameterItemStack) StatementParameterItemStack(buildcraft.api.statements.StatementParameterItemStack) ItemStack(net.minecraft.item.ItemStack)

Example 3 with StatementSlot

use of buildcraft.api.statements.StatementSlot in project LogisticsPipes by RS485.

the class LPBCTileGenericPipe method listEquals.

private boolean listEquals(List<StatementSlot> list1, List<StatementSlot> list2) {
    ListIterator<StatementSlot> e1 = list1.listIterator();
    ListIterator<StatementSlot> e2 = list2.listIterator();
    while (e1.hasNext() && e2.hasNext()) {
        StatementSlot o1 = e1.next();
        StatementSlot o2 = e2.next();
        if (!(o1 == null ? o2 == null : statementEquals(o1, o2))) {
            return false;
        }
    }
    return !(e1.hasNext() || e2.hasNext());
}
Also used : StatementSlot(buildcraft.api.statements.StatementSlot)

Example 4 with StatementSlot

use of buildcraft.api.statements.StatementSlot in project BuildCraft by BuildCraft.

the class PipeItemsStripes method actionsActivated.

@Override
protected void actionsActivated(Collection<StatementSlot> actions) {
    super.actionsActivated(actions);
    actionDir = EnumPipePart.CENTER;
    for (StatementSlot action : actions) {
        if (action.statement instanceof ActionPipeDirection) {
            actionDir = EnumPipePart.fromFacing(((ActionPipeDirection) action.statement).direction);
            break;
        }
    }
}
Also used : StatementSlot(buildcraft.api.statements.StatementSlot) ActionPipeDirection(buildcraft.transport.statements.ActionPipeDirection)

Example 5 with StatementSlot

use of buildcraft.api.statements.StatementSlot 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

StatementSlot (buildcraft.api.statements.StatementSlot)8 IStatementParameter (buildcraft.api.statements.IStatementParameter)4 StatementParameterItemStack (buildcraft.api.statements.StatementParameterItemStack)3 ItemStack (net.minecraft.item.ItemStack)3 ArrayList (java.util.ArrayList)2 IGate (buildcraft.api.gates.IGate)1 IStatement (buildcraft.api.statements.IStatement)1 IWireManager (buildcraft.api.transport.IWireManager)1 PipeEvent (buildcraft.api.transport.pipe.PipeEvent)1 PipeEventActionActivate (buildcraft.api.transport.pipe.PipeEventActionActivate)1 ActionRobotFilter (buildcraft.robotics.statements.ActionRobotFilter)1 ActionExtractionPreset (buildcraft.transport.statements.ActionExtractionPreset)1 ActionPipeDirection (buildcraft.transport.statements.ActionPipeDirection)1 EnumDyeColor (net.minecraft.item.EnumDyeColor)1 ItemBlock (net.minecraft.item.ItemBlock)1 EnumFacing (net.minecraft.util.EnumFacing)1