Package forestry.api.mail

Examples of forestry.api.mail.ILetter


  @Override
  public void onContainerClosed(EntityPlayer entityplayer) {

    if (Proxies.common.isSimulating(entityplayer.worldObj)) {
      ILetter letter = letterInventory.getLetter();
      if (!letter.isProcessed()) {
        IMailAddress sender = PostManager.postRegistry.getMailAddress(entityplayer.getGameProfile());
        letter.setSender(sender);
      }
    }

    super.onContainerClosed(entityplayer);
  }
View Full Code Here


    IMailAddress address = PostManager.postRegistry.getMailAddress(playerProfile);
    return PostRegistry.getOrCreatePOBox(worldObj, address);
  }

  private IPostalState tryDispatchLetter(ItemStack letterstack, boolean dispatchLetter) {
    ILetter letter = PostManager.postRegistry.getLetter(letterstack);
    IPostalState result;

    if (letter != null)
      result = PostManager.postRegistry.getPostOffice(worldObj).lodgeLetter(worldObj, letterstack, dispatchLetter);
    else
View Full Code Here

    if (nbttagcompound == null) {
      list.add("<" + StringUtil.localize("gui.blank") + ">");
      return;
    }

    ILetter letter = new Letter(nbttagcompound);
    letter.addTooltip(list);
  }
View Full Code Here

    }
    letters.writeToNBT(nbttagcompound);
  }

  public boolean storeLetter(ItemStack letterstack) {
    ILetter letter = PostManager.postRegistry.getLetter(letterstack);

    // Mark letter as processed
    letter.setProcessed(true);
    letter.invalidatePostage();
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    letter.writeToNBT(nbttagcompound);
    letterstack.setTagCompound(nbttagcompound);

    this.markDirty();
    return this.letters.tryAddStack(letterstack, true);
  }
View Full Code Here

    int playerLetters = 0;
    int tradeLetters = 0;
    for (int i = 0; i < letters.getSizeInventory(); i++) {
      if (letters.getStackInSlot(i) == null)
        continue;
      ILetter letter = new Letter(letters.getStackInSlot(i).getTagCompound());
      if (letter.getSender().isPlayer())
        playerLetters++;
      else
        tradeLetters++;
    }
View Full Code Here

  @Override
  public IPostalState handleLetter(World world, IMailAddress recipient, ItemStack letterstack, boolean doLodge) {
   
    boolean sendOwnerNotice = doLodge && owner != null;
   
    ILetter letter = PostManager.postRegistry.getLetter(letterstack);

    if (!isVirtual() && !hasPaper(sendOwnerNotice ? 2 : 1))
      return EnumStationState.INSUFFICIENT_PAPER;

    int ordersToFill = StackUtils.containsSets(inventory.getStacks(SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT), letter.getAttachments());

    // Not a single match.
    if (ordersToFill <= 0)
      return EnumStationState.INSUFFICIENT_OFFER;

    if (!isVirtual()) {
      int fillable = countFillableOrders(ordersToFill, inventory.getStackInSlot(SLOT_TRADEGOOD));

      // Nothing can be filled.
      if (fillable <= 0)
        return EnumStationState.INSUFFICIENT_TRADE_GOOD;

      if (fillable < ordersToFill)
        ordersToFill = fillable;

      // Check for sufficient output buffer
      int storable = countStorablePayment(ordersToFill, inventory.getStacks(SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT));

      if (storable <= 0)
        return EnumStationState.INSUFFICIENT_BUFFER;

      if (storable < ordersToFill)
        ordersToFill = storable;
    }

    // Prepare the letter
    ILetter mail = new Letter(this.address, letter.getSender());
    mail.setText("Please find your order attached.");
    for (int i = 0; i < ordersToFill; i++) {
      mail.addAttachment(inventory.getStackInSlot(SLOT_TRADEGOOD).copy());
    }
    mail.addAttachments(getSurplusAttachments(ordersToFill, letter.getAttachments()));

    // Check for necessary postage
    int requiredPostage = mail.requiredPostage();
    if (!isVirtual())
      if (!canPayPostage(requiredPostage + (sendOwnerNotice ? 1 : 0)))
        return EnumStationState.INSUFFICIENT_STAMPS;

    // Attach necessary postage
    int[] stampCount = getPostage(requiredPostage, isVirtual());
    for (int i = 0; i < stampCount.length; i++) {
      if (stampCount[i] > 0)
        mail.addStamps(ForestryItem.stamps.getItemStack(stampCount[i], EnumPostage.values()[i].ordinal() - 1));
    }

    // Send the letter
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    mail.writeToNBT(nbttagcompound);

    ItemStack mailstack = ForestryItem.letters.getItemStack(1, ItemLetter.encodeMeta(1, ItemLetter.getType(mail)));
    mailstack.setTagCompound(nbttagcompound);

    IPostalState responseState = PostManager.postRegistry.getPostOffice(world).lodgeLetter(world, mailstack, doLodge);
   
    if (!responseState.isOk()) {
      return EnumDeliveryState.RESPONSE_NOT_MAILABLE;
    }

    // Store received items
    for (int i = 0; i < ordersToFill; i++) {
      for (ItemStack stack : inventory.getStacks(SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT)) {
        if (stack == null)
          continue;
       
        inventory.tryAddStack(stack.copy(), SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, false);
      }
    }

    // Remove resources
    removePaper();
    removeStamps(stampCount);
    removeTradegood(ordersToFill);

    // Send confirmation message to seller
    if (sendOwnerNotice) {
      nbttagcompound = new NBTTagCompound();

      ILetter confirm = new Letter(this.address, new MailAddress(this.owner));
      confirm.setText(ordersToFill + " order(s) from " + letter.getSender().getName() + " were filled.");
      confirm.addStamps(ForestryItem.stamps.getItemStack(1, EnumPostage.P_1.ordinal() - 1));
      confirm.writeToNBT(nbttagcompound);
         
      ItemStack confirmstack = ForestryItem.letters.getItemStack(1, ItemLetter.encodeMeta(1, ItemLetter.getType(confirm)));
      confirmstack.setTagCompound(nbttagcompound);

      PostManager.postRegistry.getPostOffice(world).lodgeLetter(world, confirmstack, doLodge);
View Full Code Here

  }

  // / DELIVERY
  @Override
  public IPostalState lodgeLetter(World world, ItemStack itemstack, boolean doLodge) {
    ILetter letter = PostManager.postRegistry.getLetter(itemstack);

    if (letter.isProcessed())
      return EnumDeliveryState.ALREADY_MAILED;

    if (!letter.isPostPaid())
      return EnumDeliveryState.NOT_POSTPAID;

    if (!letter.isMailable())
      return EnumDeliveryState.NOT_MAILABLE;

    IPostalState state = EnumDeliveryState.NOT_MAILABLE;
    for (IMailAddress address : letter.getRecipients()) {
      IPostalCarrier carrier = PostManager.postRegistry.getCarrier(address.getType());
      if (carrier == null)
        continue;
      state = carrier.deliverLetter(world, this, address, itemstack, doLodge);
      if (!state.isOk())
        break;
    }

    if (!state.isOk())
      return state;

    collectPostage(letter.getPostage());

    markDirty();
    return EnumDeliveryState.OK;

  }
View Full Code Here

TOP

Related Classes of forestry.api.mail.ILetter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.