Search in sources :

Example 11 with IStatementParameter

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

the class TileFiller method readParametersFromNBT.

private void readParametersFromNBT(NBTTagCompound nbt) {
    IStatementParameter[] patternParameters = new IStatementParameter[nbt.getByte("length")];
    for (int i = 0; i < patternParameters.length; i++) {
        if (nbt.hasKey("p" + i)) {
            NBTTagCompound patternData = nbt.getCompoundTag("p" + i);
            patternParameters[i] = StatementManager.createParameter(patternData.getString("kind"));
            patternParameters[i].readFromNBT(patternData);
        }
    }
    this.patternParameters = patternParameters;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IStatementParameter(buildcraft.api.statements.IStatementParameter)

Example 12 with IStatementParameter

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

the class TileFiller method writeParametersToNBT.

private void writeParametersToNBT(NBTTagCompound nbt) {
    IStatementParameter[] patternParameters = this.patternParameters;
    nbt.setByte("length", (byte) (patternParameters != null ? patternParameters.length : 0));
    if (patternParameters != null) {
        for (int i = 0; i < patternParameters.length; i++) {
            if (patternParameters[i] != null) {
                NBTTagCompound patternData = new NBTTagCompound();
                patternData.setString("kind", patternParameters[i].getUniqueTag());
                // ArrayIndexOutOfBounds
                patternParameters[i].writeToNBT(patternData);
                nbt.setTag("p" + i, patternData);
            }
        }
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IStatementParameter(buildcraft.api.statements.IStatementParameter)

Example 13 with IStatementParameter

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

the class LPBCTileGenericPipe method statementEquals.

private boolean statementEquals(StatementSlot slot1, StatementSlot slot2) {
    if (slot1.statement != slot2.statement || slot1.parameters.length != slot2.parameters.length) {
        return false;
    }
    for (int i = 0; i < slot1.parameters.length; i++) {
        IStatementParameter p1 = slot1.parameters[i];
        IStatementParameter p2 = slot2.parameters[i];
        if ((p1 != null && !(p1.equals(p2))) || (p1 == null && p2 != null)) {
            return false;
        }
    }
    return true;
}
Also used : IStatementParameter(buildcraft.api.statements.IStatementParameter)

Example 14 with IStatementParameter

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

the class SchematicPipe method rotateGateLeft.

private void rotateGateLeft(NBTTagCompound gateNBT) {
    for (int i = 0; i < Gate.MAX_STATEMENTS; ++i) {
        if (gateNBT.hasKey("trigger[" + i + "]")) {
            IStatement t = StatementManager.statements.get(gateNBT.getString("trigger[" + i + "]"));
            t = t.rotateLeft();
            gateNBT.setString("trigger[" + i + "]", t.getUniqueTag());
        }
        if (gateNBT.hasKey("action[" + i + "]")) {
            IStatement a = StatementManager.statements.get(gateNBT.getString("action[" + i + "]"));
            a = a.rotateLeft();
            gateNBT.setString("action[" + i + "]", a.getUniqueTag());
        }
        for (int j = 0; j < Gate.MAX_PARAMETERS; ++j) {
            if (gateNBT.hasKey("triggerParameters[" + i + "][" + j + "]")) {
                NBTTagCompound cpt = gateNBT.getCompoundTag("triggerParameters[" + i + "][" + j + "]");
                IStatementParameter parameter = StatementManager.createParameter(cpt.getString("kind"));
                parameter.readFromNBT(cpt);
                parameter = parameter.rotateLeft();
                parameter.writeToNBT(cpt);
                gateNBT.setTag("triggerParameters[" + i + "][" + j + "]", cpt);
            }
            if (gateNBT.hasKey("actionParameters[" + i + "][" + j + "]")) {
                NBTTagCompound cpt = gateNBT.getCompoundTag("actionParameters[" + i + "][" + j + "]");
                IStatementParameter parameter = StatementManager.createParameter(cpt.getString("kind"));
                parameter.readFromNBT(cpt);
                parameter = parameter.rotateLeft();
                parameter.writeToNBT(cpt);
                gateNBT.setTag("actionParameters[" + i + "][" + j + "]", cpt);
            }
        }
    }
    if (gateNBT.hasKey("direction")) {
        EnumFacing face = EnumFacing.VALUES[gateNBT.getInteger("direction")];
        if (face.getAxis() != Axis.Y) {
            face = face.rotateY();
        }
        gateNBT.setInteger("direction", face.ordinal());
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IStatementParameter(buildcraft.api.statements.IStatementParameter) IStatement(buildcraft.api.statements.IStatement)

Example 15 with IStatementParameter

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

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