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);
  }
  @Override
  public boolean isTriggerActive(Pipe pipe, ITriggerParameter parameter) {
    if (pipe.transport instanceof PipeTransportItems) {
      PipeTransportItems transportItems = (PipeTransportItems) pipe.transport;

      if (kind == Kind.Empty) return transportItems.travelingEntities.isEmpty();
      else if (kind == Kind.ContainsItems)
        if (parameter != null && parameter.getItem() != null) {
          for (EntityData data : transportItems.travelingEntities.values())
            if (data.item.getItemStack().itemID == parameter.getItem().itemID
                && data.item.getItemStack().getItemDamage() == parameter.getItem().getItemDamage())
              return true;
        } else return !transportItems.travelingEntities.isEmpty();
    } else if (pipe.transport instanceof PipeTransportLiquids) {
      PipeTransportLiquids transportLiquids = (PipeTransportLiquids) pipe.transport;

      LiquidStack searchedLiquid = null;

      if (parameter != null && parameter.getItem() != null)
        searchedLiquid = LiquidManager.getLiquidForFilledItem(parameter.getItem());

      if (kind == Kind.Empty) {
        for (ILiquidTank b : transportLiquids.getTanks())
          if (b.getLiquid() != null && b.getLiquid().amount != 0) return false;

        return true;
      } else {
        for (ILiquidTank b : transportLiquids.getTanks())
          if (b.getLiquid() != null && b.getLiquid().amount != 0)
            if (searchedLiquid == null || searchedLiquid.isLiquidEqual(b.getLiquid())) return true;

        return false;
      }
    } else if (pipe.transport instanceof PipeTransportPower) {
      PipeTransportPower transportPower = (PipeTransportPower) pipe.transport;

      if (kind == Kind.Empty) {
        for (short s : transportPower.displayPower) if (s != 0) return false;

        return true;
      } else {
        for (short s : transportPower.displayPower) if (s != 0) return true;

        return false;
      }
    }

    return false;
  }
Пример #3
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();
  }
Пример #4
0
 @Override
 public ItemStack getItemStack() {
   ITriggerParameter parameter = pipe.getTriggerParameter(slot);
   if (parameter != null) return parameter.getItem();
   else return null;
 }