Search in sources :

Example 1 with EnumStampDefinition

use of forestry.mail.items.EnumStampDefinition in project ForestryMC by ForestryMC.

the class PostOffice method getAnyStamp.

@Override
public ItemStack getAnyStamp(EnumPostage[] postages, int max) {
    for (EnumPostage postage : postages) {
        int collected = Math.min(max, collectedPostage[postage.ordinal()]);
        collectedPostage[postage.ordinal()] -= collected;
        if (collected > 0) {
            EnumStampDefinition stampDefinition = EnumStampDefinition.getFromPostage(postage);
            return ModuleMail.getItems().stamps.get(stampDefinition, collected);
        }
    }
    return ItemStack.EMPTY;
}
Also used : EnumStampDefinition(forestry.mail.items.EnumStampDefinition) EnumPostage(forestry.api.mail.EnumPostage)

Example 2 with EnumStampDefinition

use of forestry.mail.items.EnumStampDefinition in project ForestryMC by ForestryMC.

the class ModuleMail method registerRecipes.

@Override
public void registerRecipes() {
    ItemRegistryCore coreItems = ModuleCore.getItems();
    ItemRegistryMail items = getItems();
    BlockRegistryMail blocks = getBlocks();
    ItemStack stampGlue;
    ItemStack letterGlue;
    if (ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.APICULTURE))) {
        ItemRegistryApiculture beeItems = ModuleApiculture.getItems();
        stampGlue = beeItems.honeyDrop.getItemStack();
        letterGlue = beeItems.propolis.getWildcard();
    } else {
        stampGlue = new ItemStack(Items.SLIME_BALL);
        letterGlue = new ItemStack(Items.SLIME_BALL);
    }
    RecipeUtil.addShapelessRecipe("letter", items.letters.getItemStack(), Items.PAPER, letterGlue);
    if (Config.craftingStampsEnabled) {
        for (EnumStampDefinition stampDefinition : EnumStampDefinition.VALUES) {
            if (Config.collectorStamps.contains(stampDefinition.getUid())) {
                continue;
            }
            ItemStack stamps = items.stamps.get(stampDefinition, 9);
            RecipeUtil.addRecipe("stamps", stamps, "XXX", "###", "ZZZ", 'X', stampDefinition.getCraftingIngredient(), '#', Items.PAPER, 'Z', stampGlue);
            RecipeManagers.carpenterManager.addRecipe(10, Fluids.SEED_OIL.getFluid(300), ItemStack.EMPTY, stamps, "XXX", "###", 'X', stampDefinition.getCraftingIngredient(), '#', Items.PAPER);
        }
    }
    // Recycling
    RecipeUtil.addRecipe("letter_recycling", new ItemStack(Items.PAPER), "###", '#', OreDictUtil.EMPTIED_LETTER_ORE_DICT);
    // Carpenter
    RecipeManagers.carpenterManager.addRecipe(10, new FluidStack(FluidRegistry.WATER, 250), ItemStack.EMPTY, items.letters.getItemStack(), "###", "###", '#', coreItems.woodPulp);
    RecipeUtil.addShapelessRecipe("catalogue", items.catalogue.getItemStack(), items.stamps.getWildcard(), new ItemStack(Items.BOOK));
    RecipeUtil.addRecipe("mailbox", new ItemStack(blocks.mailbox), " # ", "#Y#", "XXX", '#', "ingotTin", 'X', "chestWood", 'Y', coreItems.sturdyCasing);
    RecipeUtil.addRecipe("trade_station", new ItemStack(blocks.tradeStation), "Z#Z", "#Y#", "XWX", '#', coreItems.tubes.get(EnumElectronTube.BRONZE, 1), 'X', "chestWood", 'Y', coreItems.sturdyCasing, 'Z', coreItems.tubes.get(EnumElectronTube.IRON, 1), 'W', ItemCircuitBoard.createCircuitboard(EnumCircuitBoardType.REFINED, null, new ICircuit[] {}));
}
Also used : BlockRegistryMail(forestry.mail.blocks.BlockRegistryMail) ItemRegistryCore(forestry.core.items.ItemRegistryCore) FluidStack(net.minecraftforge.fluids.FluidStack) ResourceLocation(net.minecraft.util.ResourceLocation) ItemRegistryApiculture(forestry.apiculture.items.ItemRegistryApiculture) ItemRegistryMail(forestry.mail.items.ItemRegistryMail) ICircuit(forestry.api.circuits.ICircuit) EnumStampDefinition(forestry.mail.items.EnumStampDefinition) ItemStack(net.minecraft.item.ItemStack)

Example 3 with EnumStampDefinition

use of forestry.mail.items.EnumStampDefinition in project ForestryMC by ForestryMC.

the class TradeStation method handleLetter.

/* ILETTERHANDLER */
@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 EnumTradeStationState.INSUFFICIENT_PAPER;
    }
    int ordersToFillCount = ItemStackUtil.containsSets(InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT), letter.getAttachments());
    // Not a single match.
    if (ordersToFillCount <= 0) {
        return EnumTradeStationState.INSUFFICIENT_OFFER;
    }
    if (!isVirtual()) {
        int fillable = countFillableOrders(ordersToFillCount, inventory.getStackInSlot(SLOT_TRADEGOOD));
        // Nothing can be filled.
        if (fillable <= 0) {
            return EnumTradeStationState.INSUFFICIENT_TRADE_GOOD;
        }
        if (fillable < ordersToFillCount) {
            ordersToFillCount = fillable;
        }
        // Check for sufficient output buffer
        int storable = countStorablePayment(ordersToFillCount, InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT));
        if (storable <= 0) {
            return EnumTradeStationState.INSUFFICIENT_BUFFER;
        }
        if (storable < ordersToFillCount) {
            ordersToFillCount = storable;
        }
    }
    // Prepare the letter
    ILetter mail = new Letter(this.address, letter.getSender());
    mail.setText(Translator.translateToLocal("for.gui.mail.order.attached"));
    for (int i = 0; i < ordersToFillCount; i++) {
        mail.addAttachment(inventory.getStackInSlot(SLOT_TRADEGOOD).copy());
    }
    mail.addAttachments(getSurplusAttachments(ordersToFillCount, letter.getAttachments()));
    // Check for necessary postage
    int requiredPostage = mail.requiredPostage();
    if (!isVirtual()) {
        if (!canPayPostage(requiredPostage + (sendOwnerNotice ? 1 : 0))) {
            return EnumTradeStationState.INSUFFICIENT_STAMPS;
        }
    }
    // Attach necessary postage
    int[] stampCount = getPostage(requiredPostage, isVirtual());
    for (int i = 0; i < stampCount.length; i++) {
        int count = stampCount[i];
        if (count > 0) {
            EnumPostage postage = EnumPostage.values()[i];
            EnumStampDefinition stampDefinition = EnumStampDefinition.getFromPostage(postage);
            mail.addStamps(ModuleMail.getItems().stamps.get(stampDefinition, count));
        }
    }
    // Send the letter
    NBTTagCompound nbttagcompound = new NBTTagCompound();
    mail.writeToNBT(nbttagcompound);
    ItemStack mailstack = LetterProperties.createStampedLetterStack(mail);
    mailstack.setTagCompound(nbttagcompound);
    IPostalState responseState = PostManager.postRegistry.getPostOffice(world).lodgeLetter(world, mailstack, doLodge);
    if (!responseState.isOk()) {
        return new ResponseNotMailable(responseState);
    }
    // Store received items
    for (int i = 0; i < ordersToFillCount; i++) {
        for (ItemStack stack : InventoryUtil.getStacks(inventory, SLOT_EXCHANGE_1, SLOT_EXCHANGE_COUNT)) {
            if (stack == null) {
                continue;
            }
            InventoryUtil.tryAddStack(inventory, stack.copy(), SLOT_RECEIVE_BUFFER, SLOT_RECEIVE_BUFFER_COUNT, false);
        }
    }
    // Remove resources
    removePaper();
    removeStamps(stampCount);
    removeTradegood(ordersToFillCount);
    // Send confirmation message to seller
    if (sendOwnerNotice) {
        nbttagcompound = new NBTTagCompound();
        ILetter confirm = new Letter(this.address, new MailAddress(this.owner));
        String orderFilledMessage;
        if (ordersToFillCount == 1) {
            orderFilledMessage = Translator.translateToLocal("for.gui.mail.order.filled.one");
        } else {
            orderFilledMessage = Translator.translateToLocal("for.gui.mail.order.filled.multiple");
            orderFilledMessage = orderFilledMessage.replace("%COUNT", Integer.toString(ordersToFillCount));
        }
        orderFilledMessage = orderFilledMessage.replace("%SENDER", letter.getSender().getName());
        confirm.setText(orderFilledMessage);
        confirm.addStamps(ModuleMail.getItems().stamps.get(EnumStampDefinition.P_1, 1));
        confirm.writeToNBT(nbttagcompound);
        ItemStack confirmstack = LetterProperties.createStampedLetterStack(confirm);
        confirmstack.setTagCompound(nbttagcompound);
        PostManager.postRegistry.getPostOffice(world).lodgeLetter(world, confirmstack, doLodge);
        removePaper();
        removeStamps(new int[] { 0, 1 });
    }
    markDirty();
    return EnumDeliveryState.OK;
}
Also used : IMailAddress(forestry.api.mail.IMailAddress) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ILetter(forestry.api.mail.ILetter) IPostalState(forestry.api.mail.IPostalState) ILetter(forestry.api.mail.ILetter) EnumStampDefinition(forestry.mail.items.EnumStampDefinition) ItemStack(net.minecraft.item.ItemStack) EnumPostage(forestry.api.mail.EnumPostage)

Aggregations

EnumStampDefinition (forestry.mail.items.EnumStampDefinition)3 EnumPostage (forestry.api.mail.EnumPostage)2 ItemStack (net.minecraft.item.ItemStack)2 ICircuit (forestry.api.circuits.ICircuit)1 ILetter (forestry.api.mail.ILetter)1 IMailAddress (forestry.api.mail.IMailAddress)1 IPostalState (forestry.api.mail.IPostalState)1 ItemRegistryApiculture (forestry.apiculture.items.ItemRegistryApiculture)1 ItemRegistryCore (forestry.core.items.ItemRegistryCore)1 BlockRegistryMail (forestry.mail.blocks.BlockRegistryMail)1 ItemRegistryMail (forestry.mail.items.ItemRegistryMail)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 FluidStack (net.minecraftforge.fluids.FluidStack)1