Search in sources :

Example 1 with IStatementParameter

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

the class GuiElementStatementParam method onMouseClicked.

// IInteractionElement
@Override
public void onMouseClicked(int button) {
    if (ref.canInteract && contains(gui.mouse) && button == 0) {
        IStatementParameter param = get();
        if (param == null) {
            return;
        }
        StatementMouseClick clickEvent = new StatementMouseClick(0, false);
        final ItemStack heldStack;
        EntityPlayer currentPlayer = Minecraft.getMinecraft().player;
        if (currentPlayer == null) {
            heldStack = ItemStack.EMPTY;
        } else {
            heldStack = currentPlayer.inventory.getItemStack();
        }
        IStatementParameter pNew = param.onClick(container, ref.get(), heldStack, clickEvent);
        if (pNew != null) {
            set(pNew);
        } else {
            IStatementParameter[] possible = param.getPossible(container);
            if (!param.isPossibleOrdered()) {
                List<IStatementParameter> list = new ArrayList<>();
                for (IStatementParameter p2 : possible) {
                    if (p2 != null) {
                        list.add(p2);
                    }
                }
                possible = list.toArray(new IStatementParameter[0]);
            }
            gui.currentMenu = GuiElementStatementVariant.create(gui, this, this, possible);
        }
    }
}
Also used : StatementMouseClick(buildcraft.api.statements.StatementMouseClick) ArrayList(java.util.ArrayList) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IStatementParameter(buildcraft.api.statements.IStatementParameter) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IStatementParameter

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

the class GuiElementStatementParam method drawBackground.

// IGuiElement
@Override
public void drawBackground(float partialTicks) {
    if (draw) {
        IStatement slot = ref.get();
        int max = slot == null ? 0 : slot.maxParameters();
        double x = getX();
        double y = getY();
        if (paramIndex >= max) {
            GuiElementStatement.SLOT_COLOUR.drawAt(x, y);
            GuiElementStatement.ICON_SLOT_BLOCKED.drawAt(x, y);
            return;
        }
        IStatementParameter statementParameter = get();
        GuiElementStatementSource.drawGuiSlot(statementParameter, x, y);
    }
}
Also used : IStatementParameter(buildcraft.api.statements.IStatementParameter) IStatement(buildcraft.api.statements.IStatement)

Example 3 with IStatementParameter

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

the class ActionParameterSignal method getPossible.

@Override
public IStatementParameter[] getPossible(IStatementContainer source) {
    if (!(source instanceof IGate)) {
        return null;
    }
    IGate gate = (IGate) source;
    List<IStatementParameter> poss = new ArrayList<>(1 + ColourUtil.COLOURS.length);
    poss.add(EMPTY);
    for (EnumDyeColor c : ColourUtil.COLOURS) {
        if (TriggerPipeSignal.doesGateHaveColour(gate, c)) {
            poss.add(get(c));
        }
    }
    return poss.toArray(new IStatementParameter[poss.size()]);
}
Also used : IGate(buildcraft.api.gates.IGate) ArrayList(java.util.ArrayList) IStatementParameter(buildcraft.api.statements.IStatementParameter) EnumDyeColor(net.minecraft.item.EnumDyeColor)

Example 4 with IStatementParameter

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

the class ContainerGateInterface method receiveCommand.

@Override
public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
    if (side.isServer()) {
        EntityPlayer player = (EntityPlayer) sender;
        if ("initRequest".equals(command)) {
            final String[] triggerStrings = statementsToStrings(potentialTriggers);
            final String[] actionStrings = statementsToStrings(potentialActions);
            BuildCraftCore.instance.sendToPlayer(player, new PacketCommand(this, "init", new CommandWriter() {

                @Override
                public void write(ByteBuf data) {
                    data.writeByte(gate.getDirection().ordinal());
                    data.writeShort(triggerStrings.length);
                    data.writeShort(actionStrings.length);
                    for (String trigger : triggerStrings) {
                        NetworkUtils.writeUTF(data, trigger);
                    }
                    for (String action : actionStrings) {
                        NetworkUtils.writeUTF(data, action);
                    }
                }
            }));
        } else if ("selectionRequest".equals(command)) {
            for (int position = 0; position < gate.material.numSlots; position++) {
                IStatement action = gate.getAction(position);
                IStatement trigger = gate.getTrigger(position);
                BuildCraftCore.instance.sendToPlayer(player, getStatementPacket("setAction", position, action));
                BuildCraftCore.instance.sendToPlayer(player, getStatementPacket("setTrigger", position, trigger));
                for (int p = 0; p < gate.material.numActionParameters; ++p) {
                    BuildCraftCore.instance.sendToPlayer(player, getStatementParameterPacket("setActionParameter", position, p, gate.getActionParameter(position, p)));
                }
                for (int q = 0; q < gate.material.numTriggerParameters; ++q) {
                    BuildCraftCore.instance.sendToPlayer(player, getStatementParameterPacket("setTriggerParameter", position, q, gate.getTriggerParameter(position, q)));
                }
            }
        }
    } else if (side.isClient()) {
        if ("init".equals(command)) {
            setGate(stream.readByte());
            String[] triggerStrings = new String[stream.readShort()];
            String[] actionStrings = new String[stream.readShort()];
            for (int i = 0; i < triggerStrings.length; i++) {
                triggerStrings[i] = NetworkUtils.readUTF(stream);
            }
            for (int i = 0; i < actionStrings.length; i++) {
                actionStrings[i] = NetworkUtils.readUTF(stream);
            }
            stringsToStatements(this.potentialTriggers, triggerStrings);
            stringsToStatements(this.potentialActions, actionStrings);
        }
    }
    if ("setAction".equals(command)) {
        setAction(stream.readUnsignedByte(), NetworkUtils.readUTF(stream), false);
    } else if ("setTrigger".equals(command)) {
        setTrigger(stream.readUnsignedByte(), NetworkUtils.readUTF(stream), false);
    } else if ("setActionParameter".equals(command) || "setTriggerParameter".equals(command)) {
        int slot = stream.readUnsignedByte();
        int param = stream.readUnsignedByte();
        String parameterName = NetworkUtils.readUTF(stream);
        NBTTagCompound parameterData = NetworkUtils.readNBT(stream);
        IStatementParameter parameter = null;
        if (parameterName != null && parameterName.length() > 0) {
            parameter = StatementManager.createParameter(parameterName);
        }
        if (parameter != null) {
            parameter.readFromNBT(parameterData);
            if ("setActionParameter".equals(command)) {
                setActionParameter(slot, param, parameter, false);
            } else {
                setTriggerParameter(slot, param, parameter, false);
            }
        }
    }
}
Also used : PacketCommand(buildcraft.core.lib.network.command.PacketCommand) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IStatementParameter(buildcraft.api.statements.IStatementParameter) CommandWriter(buildcraft.core.lib.network.command.CommandWriter) ByteBuf(io.netty.buffer.ByteBuf) IStatement(buildcraft.api.statements.IStatement)

Example 5 with IStatementParameter

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

the class GuiGateInterface method doSlotClick.

private void doSlotClick(AdvancedSlot slot, int k) {
    if (slot instanceof TriggerSlot && container.hasTriggers()) {
        TriggerSlot triggerSlot = (TriggerSlot) slot;
        IStatement changed = null;
        if (!isShiftKeyDown()) {
            if (triggerSlot.getStatement() == null) {
                if (k == 0) {
                    changed = container.getFirstTrigger();
                } else {
                    changed = container.getLastTrigger();
                }
            } else {
                Iterator<IStatement> it = container.getTriggerIterator(k != 0);
                for (; it.hasNext(); ) {
                    IStatement trigger = it.next();
                    if (!it.hasNext()) {
                        break;
                    }
                    if (trigger == triggerSlot.getStatement()) {
                        changed = it.next();
                        break;
                    }
                }
            }
        }
        if (changed == null) {
            container.setTrigger(triggerSlot.slot, null, true);
        } else {
            container.setTrigger(triggerSlot.slot, changed.getUniqueTag(), true);
        }
        for (StatementParameterSlot p : triggerSlot.parameters) {
            IStatementParameter parameter = null;
            if (changed != null && p.slot < changed.minParameters()) {
                parameter = changed.createParameter(p.slot);
            }
            container.setTriggerParameter(triggerSlot.slot, p.slot, parameter, true);
        }
    } else if (slot instanceof ActionSlot) {
        ActionSlot actionSlot = (ActionSlot) slot;
        IStatement changed = null;
        if (!isShiftKeyDown()) {
            if (actionSlot.getStatement() == null) {
                if (k == 0) {
                    changed = container.getFirstAction();
                } else {
                    changed = container.getLastAction();
                }
            } else {
                Iterator<IStatement> it = container.getActionIterator(k != 0);
                for (; it.hasNext(); ) {
                    IStatement action = it.next();
                    if (!it.hasNext()) {
                        break;
                    }
                    if (action == actionSlot.getStatement()) {
                        changed = it.next();
                        break;
                    }
                }
            }
        }
        if (changed == null) {
            container.setAction(actionSlot.slot, null, true);
        } else {
            container.setAction(actionSlot.slot, changed.getUniqueTag(), true);
        }
        for (StatementParameterSlot p : actionSlot.parameters) {
            IStatementParameter parameter = null;
            if (changed != null && p.slot < changed.minParameters()) {
                parameter = changed.createParameter(p.slot);
            }
            container.setActionParameter(actionSlot.slot, p.slot, parameter, true);
        }
    } else if (slot instanceof StatementParameterSlot) {
        StatementParameterSlot paramSlot = (StatementParameterSlot) slot;
        StatementSlot statement = paramSlot.statementSlot;
        if (statement.isDefined() && statement.getStatement().maxParameters() > paramSlot.slot) {
            IStatementParameter param = paramSlot.getParameter();
            if (param == null) {
                param = statement.getStatement().createParameter(paramSlot.slot);
            }
            if (param != null) {
                param.onClick(gate, statement.getStatement(), mc.thePlayer.inventory.getItemStack(), new StatementMouseClick(k, isShiftKeyDown()));
                paramSlot.setParameter(param, true);
            }
        }
    }
    container.markDirty();
}
Also used : StatementSlot(buildcraft.core.lib.gui.StatementSlot) Iterator(java.util.Iterator) StatementMouseClick(buildcraft.api.statements.StatementMouseClick) IStatementParameter(buildcraft.api.statements.IStatementParameter) IStatement(buildcraft.api.statements.IStatement) StatementParameterSlot(buildcraft.core.lib.gui.StatementParameterSlot)

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