Search in sources :

Example 1 with TradeStation

use of forestry.mail.TradeStation in project ForestryMC by ForestryMC.

the class TileTrader method updateServerSide.

/* UPDATING */
/**
 * The trade station should show errors for missing stamps and paper first.
 * Once it is able to send letters, it should display other error states.
 */
@Override
public void updateServerSide() {
    if (!isLinked() || !updateOnInterval(10)) {
        return;
    }
    IErrorLogic errorLogic = getErrorLogic();
    errorLogic.setCondition(!hasPostageMin(3), EnumErrorCode.NO_STAMPS);
    errorLogic.setCondition(!hasPaperMin(2), EnumErrorCode.NO_PAPER);
    IInventory inventory = getInternalInventory();
    ItemStack tradeGood = inventory.getStackInSlot(TradeStation.SLOT_TRADEGOOD);
    errorLogic.setCondition(tradeGood.isEmpty(), EnumErrorCode.NO_TRADE);
    boolean hasRequest = hasItemCount(TradeStation.SLOT_EXCHANGE_1, TradeStation.SLOT_EXCHANGE_COUNT, ItemStack.EMPTY, 1);
    errorLogic.setCondition(!hasRequest, EnumErrorCode.NO_TRADE);
    if (!tradeGood.isEmpty()) {
        boolean hasSupplies = hasItemCount(TradeStation.SLOT_SEND_BUFFER, TradeStation.SLOT_SEND_BUFFER_COUNT, tradeGood, tradeGood.getCount());
        errorLogic.setCondition(!hasSupplies, EnumErrorCode.NO_SUPPLIES);
    }
    if (inventory instanceof TradeStation && updateOnInterval(200)) {
        boolean canReceivePayment = ((TradeStation) inventory).canReceivePayment();
        errorLogic.setCondition(!canReceivePayment, EnumErrorCode.NO_SPACE_INVENTORY);
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemStack(net.minecraft.item.ItemStack) TradeStation(forestry.mail.TradeStation) InventoryTradeStation(forestry.mail.inventory.InventoryTradeStation) IErrorLogic(forestry.api.core.IErrorLogic)

Aggregations

IErrorLogic (forestry.api.core.IErrorLogic)1 TradeStation (forestry.mail.TradeStation)1 InventoryTradeStation (forestry.mail.inventory.InventoryTradeStation)1 IInventory (net.minecraft.inventory.IInventory)1 ItemStack (net.minecraft.item.ItemStack)1