Search in sources :

Example 1 with StatementMouseClick

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

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

Example 3 with StatementMouseClick

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

the class GuiFiller method mouseClicked.

@Override
protected void mouseClicked(int x, int y, int k) throws IOException {
    super.mouseClicked(x, y, k);
    AdvancedSlot slot = getSlotAtLocation(x, y);
    if (slot != null && !filler.isPatternLocked()) {
        int i = ((FillerParameterSlot) slot).slot;
        if (i < filler.patternParameters.length) {
            if (filler.patternParameters[i] != null) {
                filler.patternParameters[i].onClick(filler, filler.currentPattern, mc.thePlayer.inventory.getItemStack(), new StatementMouseClick(k, isShiftKeyDown()));
            } else {
                filler.patternParameters[i] = filler.currentPattern.createParameter(i);
            }
            filler.rpcSetParameter(i, filler.patternParameters[i]);
        }
    }
}
Also used : AdvancedSlot(buildcraft.core.lib.gui.AdvancedSlot) StatementMouseClick(buildcraft.api.statements.StatementMouseClick)

Aggregations

StatementMouseClick (buildcraft.api.statements.StatementMouseClick)3 IStatementParameter (buildcraft.api.statements.IStatementParameter)2 IStatement (buildcraft.api.statements.IStatement)1 AdvancedSlot (buildcraft.core.lib.gui.AdvancedSlot)1 StatementParameterSlot (buildcraft.core.lib.gui.StatementParameterSlot)1 StatementSlot (buildcraft.core.lib.gui.StatementSlot)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1