public void handleSelectionChange(PacketUpdate packet) {
    PacketPayload payload = packet.payload;
    int position = payload.intPayload[0];

    if (payload.intPayload[1] >= 0 && payload.intPayload[1] < ActionManager.triggers.length) {
      setTrigger(position, ActionManager.triggers[payload.intPayload[1]], true);
      // System.out.println("Trigger["+ position + "]: " +
      // pipe.activatedTriggers[position].getDescription());
    } else {
      setTrigger(position, null, true);
      // System.out.println("Trigger["+ position + "] clear!");
    }

    if (payload.intPayload[2] >= 0 && payload.intPayload[2] < ActionManager.actions.length) {
      setAction(position, ActionManager.actions[payload.intPayload[2]], true);
      // System.out.println("Action["+ position + "]: " +
      // pipe.activatedActions[position].getDescription());
    } else {
      setAction(position, null, true);
      // System.out.println("Action["+ position + "] clear!");
    }

    int itemID = payload.intPayload[3];
    if (itemID <= 0) {
      setTriggerParameter(position, null, true);
      return;
    }

    ITriggerParameter param = new TriggerParameter();
    param.set(new ItemStack(itemID, payload.intPayload[4], payload.intPayload[5]));
    setTriggerParameter(position, param, true);
  }
示例#2
0
  @Override
  protected void mouseClicked(int i, int j, int k) {
    super.mouseClicked(i, j, k);

    int cornerX = (width - xSize) / 2;
    int cornerY = (height - ySize) / 2;

    int position = getSlotAtLocation(i - cornerX, j - cornerY);

    AdvancedSlot slot = null;

    if (position < 0) return;

    slot = slots[position];

    if (slot instanceof TriggerSlot && _container.hasTriggers()) {
      TriggerSlot triggerSlot = (TriggerSlot) slot;

      ITrigger changed = null;
      if (triggerSlot.getTrigger() == null) {

        if (k == 0) {
          changed = _container.getFirstTrigger();
        } else {
          changed = _container.getLastTrigger();
        }

      } else {
        Iterator<ITrigger> it = _container.getTriggerIterator(k != 0);

        for (; it.hasNext(); ) {
          ITrigger trigger = it.next();

          if (!it.hasNext()) {
            changed = null;
            break;
          }

          if (trigger == triggerSlot.getTrigger()) {
            changed = it.next();
            break;
          }
        }
      }

      _container.setTrigger(position, changed, true);

      if (_container.getGateOrdinal() >= GateKind.AND_3.ordinal()) {
        _container.setTriggerParameter(position, null, true);
      }
    } else if (slot instanceof ActionSlot) {
      ActionSlot actionSlot = (ActionSlot) slot;

      IAction changed = null;
      if (actionSlot.getAction() == null) {

        if (k == 0) {
          changed = _container.getFirstAction();
        } else {
          changed = _container.getLastAction();
        }

      } else {
        Iterator<IAction> it = _container.getActionIterator(k != 0);

        for (; it.hasNext(); ) {
          IAction action = it.next();

          if (!it.hasNext()) {
            changed = null;
            break;
          }

          if (action == actionSlot.getAction()) {
            changed = it.next();
            break;
          }
        }
      }

      _container.setAction(position - nbEntries, changed, true);
    } else if (slot instanceof TriggerParameterSlot) {
      TriggerSlot trigger = (TriggerSlot) slots[position - nbEntries * 2];

      if (trigger.isDefined() && trigger.getTrigger().hasParameter()) {
        ITriggerParameter param = trigger.getTrigger().createParameter();

        if (param != null) {
          param.set(mc.thePlayer.inventory.getItemStack());
          _container.setTriggerParameter(position - nbEntries * 2, param, true);
        }
      }
    }

    _container.markDirty();
  }