Search in sources :

Example 16 with IStatementParameter

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

Example 17 with IStatementParameter

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

the class ActionPipeSignal method actionActivate.

@Override
public void actionActivate(IStatementContainer container, IStatementParameter[] parameters) {
    if (!(container instanceof IWireEmitter)) {
        return;
    }
    IWireEmitter emitter = (IWireEmitter) container;
    emitter.emitWire(colour);
    for (IStatementParameter param : parameters) {
        if (param != null && param instanceof ActionParameterSignal) {
            ActionParameterSignal signal = (ActionParameterSignal) param;
            if (signal.getColor() != null) {
                emitter.emitWire(signal.getColor());
            }
        }
    }
}
Also used : IStatementParameter(buildcraft.api.statements.IStatementParameter) IWireEmitter(buildcraft.transport.wire.IWireEmitter)

Example 18 with IStatementParameter

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

the class FullStatement method writeToBuffer.

public void writeToBuffer(PacketBufferBC buffer) {
    if (statement == null) {
        buffer.writeBoolean(false);
    } else {
        buffer.writeBoolean(true);
        type.writeToBuffer(buffer, statement);
        for (int p = 0; p < params.length; p++) {
            IStatementParameter param = params[p];
            StatementTypeParam.INSTANCE.writeToBuffer(buffer, param);
        }
    }
}
Also used : IStatementParameter(buildcraft.api.statements.IStatementParameter)

Example 19 with IStatementParameter

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

the class GuiGateInterface method mouseReleased.

@Override
protected void mouseReleased(int mouseX, int mouseY, int eventType) {
    super.mouseReleased(mouseX, mouseY, eventType);
    if (index >= 0) {
        int i = index;
        index = -1;
        IStatement changeTo;
        Iterator<IStatement> it;
        if (trigger)
            it = container.getTriggerIterator(false);
        else
            it = container.getActionIterator(false);
        do {
            changeTo = it.next();
            i--;
        } while (i >= 0);
        AdvancedSlot slot = getSlotAtLocation(mouseX, mouseY);
        if (slot == null)
            return;
        if (trigger && slot instanceof TriggerSlot) {
            TriggerSlot trig = (TriggerSlot) slot;
            container.setTrigger(trig.slot, changeTo.getUniqueTag(), true);
            for (StatementParameterSlot p : trig.parameters) {
                IStatementParameter parameter = null;
                if (p.slot < changeTo.minParameters()) {
                    parameter = changeTo.createParameter(p.slot);
                }
                container.setTriggerParameter(trig.slot, p.slot, parameter, true);
            }
        }
        if (!trigger && slot instanceof ActionSlot) {
            ActionSlot trig = (ActionSlot) slot;
            container.setAction(trig.slot, changeTo.getUniqueTag(), true);
            for (StatementParameterSlot p : trig.parameters) {
                IStatementParameter parameter = null;
                if (p.slot < changeTo.minParameters()) {
                    parameter = changeTo.createParameter(p.slot);
                }
                container.setActionParameter(trig.slot, p.slot, parameter, true);
            }
        }
    }
}
Also used : AdvancedSlot(buildcraft.core.lib.gui.AdvancedSlot) IStatementParameter(buildcraft.api.statements.IStatementParameter) IStatement(buildcraft.api.statements.IStatement) StatementParameterSlot(buildcraft.core.lib.gui.StatementParameterSlot)

Example 20 with IStatementParameter

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

the class ActionRobotFilter method getGateFilterStacks.

public static Collection<ItemStack> getGateFilterStacks(DockingStation station) {
    ArrayList<ItemStack> result = new ArrayList<>();
    for (StatementSlot slot : station.getActiveActions()) {
        if (slot.statement instanceof ActionRobotFilter) {
            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)

Aggregations

IStatementParameter (buildcraft.api.statements.IStatementParameter)21 IStatement (buildcraft.api.statements.IStatement)5 StatementSlot (buildcraft.api.statements.StatementSlot)4 ArrayList (java.util.ArrayList)4 ItemStack (net.minecraft.item.ItemStack)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 StatementParameterItemStack (buildcraft.api.statements.StatementParameterItemStack)3 EnumPipePart (buildcraft.api.core.EnumPipePart)2 ISprite (buildcraft.api.core.render.ISprite)2 IFilledTemplate (buildcraft.api.filler.IFilledTemplate)2 IGate (buildcraft.api.gates.IGate)2 StatementMouseClick (buildcraft.api.statements.StatementMouseClick)2 IWireManager (buildcraft.api.transport.IWireManager)2 StatementParameterSlot (buildcraft.core.lib.gui.StatementParameterSlot)2 GuiIcon (buildcraft.lib.gui.GuiIcon)2 StatementWrapper (buildcraft.lib.statement.StatementWrapper)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EnumDyeColor (net.minecraft.item.EnumDyeColor)2 EnumFacing (net.minecraft.util.EnumFacing)2 Theory (org.junit.experimental.theories.Theory)2