Search in sources :

Example 16 with IStatement

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

the class ActionType method readFromNbt.

@Override
public ActionWrapper readFromNbt(NBTTagCompound nbt) {
    if (nbt == null) {
        return null;
    }
    String kind = nbt.getString("kind");
    if (kind == null || kind.isEmpty()) {
        return null;
    }
    EnumPipePart side = EnumPipePart.fromMeta(nbt.getByte("side"));
    IStatement statement = StatementManager.statements.get(kind);
    if (statement instanceof IAction) {
        return ActionWrapper.wrap(statement, side.face);
    }
    BCLog.logger.warn("[gate.trigger] Couldn't find an action called '{}'! (found {})", kind, statement);
    return null;
}
Also used : IAction(buildcraft.api.statements.IAction) EnumPipePart(buildcraft.api.core.EnumPipePart) IStatement(buildcraft.api.statements.IStatement)

Example 17 with IStatement

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

the class TriggerType method readFromNbt.

@Override
public TriggerWrapper readFromNbt(NBTTagCompound nbt) {
    if (nbt == null) {
        return null;
    }
    String kind = nbt.getString("kind");
    if (kind == null || kind.isEmpty()) {
        return null;
    }
    EnumPipePart side = EnumPipePart.fromMeta(nbt.getByte("side"));
    IStatement statement = StatementManager.statements.get(kind);
    if (statement instanceof ITrigger) {
        return TriggerWrapper.wrap(statement, side.face);
    }
    BCLog.logger.warn("[gate.trigger] Couldn't find a trigger called '{}'! (found {})", kind, statement);
    return null;
}
Also used : EnumPipePart(buildcraft.api.core.EnumPipePart) IStatement(buildcraft.api.statements.IStatement) ITrigger(buildcraft.api.statements.ITrigger)

Example 18 with IStatement

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

the class ContainerGateInterface method statementsToStrings.

private static String[] statementsToStrings(Collection<IStatement> statements) {
    final int size = statements.size();
    String[] array = new String[size];
    int pos = 0;
    for (IStatement statement : statements) {
        array[pos++] = statement.getUniqueTag();
    }
    return array;
}
Also used : IStatement(buildcraft.api.statements.IStatement)

Example 19 with IStatement

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

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

the class GuiGateInterface method mouseClicked.

@Override
protected void mouseClicked(int x, int y, int type) throws IOException {
    if (gate == null) {
        return;
    }
    super.mouseClicked(x, y, type);
    AdvancedSlot slot = getSlotAtLocation(x, y);
    if (slot != null) {
        doSlotClick(slot, type);
        return;
    }
    int sX = 18;
    int sY = 6;
    Collection<IStatement> collect = container.getTriggerCollection(false);
    for (int i = 0; i < collect.size(); i++) {
        int pX = this.guiLeft - sX;
        int pY = this.guiTop + sY;
        if (x > pX & x < pX + 16 && y > pY && y < pY + 16) {
            trigger = true;
            index = i;
            return;
        }
        if (sX > 18 * 5) {
            sX = 18;
            sY += 18;
        } else
            sX += 18;
    }
    sX = 0;
    sY = 6;
    collect = container.getActionCollection(false);
    for (int i = 0; i < collect.size(); i++) {
        int pX = this.guiLeft + this.xSize() + sX;
        int pY = this.guiTop + sY;
        if (x > pX & x < pX + 16 && y > pY && y < pY + 16) {
            trigger = false;
            index = i;
            return;
        }
        if (sX > 18 * 4) {
            sX = 0;
            sY += 18;
        } else
            sX += 18;
    }
}
Also used : AdvancedSlot(buildcraft.core.lib.gui.AdvancedSlot) IStatement(buildcraft.api.statements.IStatement)

Aggregations

IStatement (buildcraft.api.statements.IStatement)20 EnumPipePart (buildcraft.api.core.EnumPipePart)6 IStatementParameter (buildcraft.api.statements.IStatementParameter)5 IAction (buildcraft.api.statements.IAction)3 ITrigger (buildcraft.api.statements.ITrigger)3 AdvancedSlot (buildcraft.core.lib.gui.AdvancedSlot)3 StatementParameterSlot (buildcraft.core.lib.gui.StatementParameterSlot)3 InvalidInputDataException (buildcraft.api.core.InvalidInputDataException)2 StatementSlot (buildcraft.core.lib.gui.StatementSlot)2 ArrayList (java.util.ArrayList)2 IGate (buildcraft.api.gates.IGate)1 ITriggerExternalOverride (buildcraft.api.statements.ITriggerExternalOverride)1 StatementManager (buildcraft.api.statements.StatementManager)1 StatementMouseClick (buildcraft.api.statements.StatementMouseClick)1 StatementSlot (buildcraft.api.statements.StatementSlot)1 CommandWriter (buildcraft.core.lib.network.command.CommandWriter)1 PacketCommand (buildcraft.core.lib.network.command.PacketCommand)1 BCLib (buildcraft.lib.BCLib)1 GuiGuide (buildcraft.lib.client.guide.GuiGuide)1 GuideManager (buildcraft.lib.client.guide.GuideManager)1