Search in sources :

Example 1 with IStamps

use of forestry.api.mail.IStamps in project ForestryMC by ForestryMC.

the class PostOffice method collectPostage.

@Override
public void collectPostage(NonNullList<ItemStack> stamps) {
    for (ItemStack stamp : stamps) {
        if (stamp == null) {
            continue;
        }
        if (stamp.getItem() instanceof IStamps) {
            EnumPostage postage = ((IStamps) stamp.getItem()).getPostage(stamp);
            collectedPostage[postage.ordinal()] += stamp.getCount();
        }
    }
}
Also used : IStamps(forestry.api.mail.IStamps) ItemStack(net.minecraft.item.ItemStack) EnumPostage(forestry.api.mail.EnumPostage)

Example 2 with IStamps

use of forestry.api.mail.IStamps in project ForestryMC by ForestryMC.

the class TileTrader method hasPostageMin.

public boolean hasPostageMin(int postage) {
    int posted = 0;
    IInventory tradeInventory = this.getInternalInventory();
    for (int i = TradeStation.SLOT_STAMPS_1; i < TradeStation.SLOT_STAMPS_1 + TradeStation.SLOT_STAMPS_COUNT; i++) {
        ItemStack stamp = tradeInventory.getStackInSlot(i);
        if (!stamp.isEmpty()) {
            if (stamp.getItem() instanceof IStamps) {
                posted += ((IStamps) stamp.getItem()).getPostage(stamp).getValue() * stamp.getCount();
                if (posted >= postage) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : IInventory(net.minecraft.inventory.IInventory) IStamps(forestry.api.mail.IStamps) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IStamps

use of forestry.api.mail.IStamps in project ForestryMC by ForestryMC.

the class TradeStation method removeStamps.

private void removeStamps(int[] stampCount) {
    for (int i = 1; i < stampCount.length; i++) {
        if (stampCount[i] <= 0) {
            continue;
        }
        for (int j = SLOT_STAMPS_1; j < SLOT_STAMPS_1 + SLOT_STAMPS_COUNT; j++) {
            if (stampCount[i] <= 0) {
                continue;
            }
            ItemStack stamp = inventory.getStackInSlot(j);
            if (stamp.isEmpty()) {
                continue;
            }
            if (!(stamp.getItem() instanceof IStamps)) {
                continue;
            }
            if (((IStamps) stamp.getItem()).getPostage(stamp) == EnumPostage.values()[i]) {
                ItemStack decrease = inventory.decrStackSize(j, stampCount[i]);
                stampCount[i] -= decrease.getCount();
            }
        }
    }
}
Also used : IStamps(forestry.api.mail.IStamps) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IStamps

use of forestry.api.mail.IStamps in project ForestryMC by ForestryMC.

the class TileStampCollector method updateServerSide.

@Override
public void updateServerSide() {
    if (!updateOnInterval(20)) {
        return;
    }
    ItemStack stamp = null;
    IInventoryAdapter inventory = getInternalInventory();
    if (inventory.getStackInSlot(InventoryStampCollector.SLOT_FILTER).isEmpty()) {
        stamp = PostManager.postRegistry.getPostOffice(world).getAnyStamp(1);
    } else {
        ItemStack filter = inventory.getStackInSlot(InventoryStampCollector.SLOT_FILTER);
        if (filter.getItem() instanceof IStamps) {
            stamp = PostManager.postRegistry.getPostOffice(world).getAnyStamp(((IStamps) filter.getItem()).getPostage(filter), 1);
        }
    }
    if (stamp == null) {
        return;
    }
    // Store it.
    InventoryUtil.stowInInventory(stamp, inventory, true, InventoryStampCollector.SLOT_BUFFER_1, InventoryStampCollector.SLOT_BUFFER_COUNT);
}
Also used : IStamps(forestry.api.mail.IStamps) IInventoryAdapter(forestry.core.inventory.IInventoryAdapter) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IStamps (forestry.api.mail.IStamps)4 ItemStack (net.minecraft.item.ItemStack)4 EnumPostage (forestry.api.mail.EnumPostage)1 IInventoryAdapter (forestry.core.inventory.IInventoryAdapter)1 IInventory (net.minecraft.inventory.IInventory)1