Search in sources :

Example 21 with IErrorLogic

use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.

the class TileCentrifuge method hasWork.

@Override
public boolean hasWork() {
    if (!pendingProducts.isEmpty()) {
        return true;
    }
    checkRecipe();
    boolean hasResource = !getStackInSlot(InventoryCentrifuge.SLOT_RESOURCE).isEmpty();
    IErrorLogic errorLogic = getErrorLogic();
    errorLogic.setCondition(!hasResource, EnumErrorCode.NO_RESOURCE);
    return hasResource;
}
Also used : IErrorLogic(forestry.api.core.IErrorLogic)

Example 22 with IErrorLogic

use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.

the class TileFermenter method hasWork.

@Override
public boolean hasWork() {
    checkRecipe();
    checkFuel();
    int fermented = Math.min(fermentationTime, fuelCurrentFerment);
    boolean hasRecipe = currentRecipe != null;
    boolean hasFuel = fuelBurnTime > 0;
    boolean hasResource = fermentationTime > 0 || !getStackInSlot(InventoryFermenter.SLOT_RESOURCE).isEmpty();
    FluidStack drained = resourceTank.drain(fermented, false);
    boolean hasFluidResource = drained != null && drained.amount == fermented;
    boolean hasFluidSpace = true;
    if (hasRecipe) {
        int productAmount = Math.round(fermented * currentRecipe.getModifier() * currentResourceModifier);
        Fluid output = currentRecipe.getOutput();
        FluidStack fluidStack = new FluidStack(output, productAmount);
        hasFluidSpace = productTank.fillInternal(fluidStack, false) == fluidStack.amount;
    }
    IErrorLogic errorLogic = getErrorLogic();
    errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE);
    errorLogic.setCondition(!hasFuel, EnumErrorCode.NO_FUEL);
    errorLogic.setCondition(!hasResource, EnumErrorCode.NO_RESOURCE);
    errorLogic.setCondition(!hasFluidResource, EnumErrorCode.NO_RESOURCE_LIQUID);
    errorLogic.setCondition(!hasFluidSpace, EnumErrorCode.NO_SPACE_TANK);
    return hasRecipe && hasFuel && hasResource && hasFluidResource && hasFluidSpace;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) IErrorLogic(forestry.api.core.IErrorLogic)

Example 23 with IErrorLogic

use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.

the class TileMoistener method rotateWorkingSlot.

private boolean rotateWorkingSlot() {
    IErrorLogic errorLogic = getErrorLogic();
    // Put working slot contents into inventory if space is available
    if (!getStackInSlot(InventoryMoistener.SLOT_WORKING).isEmpty()) {
        // Get the result of the consumed item in the working slot
        ItemStack deposit;
        if (FuelManager.moistenerResource.containsKey(getStackInSlot(InventoryMoistener.SLOT_WORKING))) {
            MoistenerFuel res = FuelManager.moistenerResource.get(getStackInSlot(InventoryMoistener.SLOT_WORKING));
            deposit = res.getProduct().copy();
        } else {
            deposit = getStackInSlot(InventoryMoistener.SLOT_WORKING).copy();
        }
        int targetSlot = getFreeReservoirSlot(deposit);
        // We stop the whole thing, if we don't have any room anymore.
        if (errorLogic.setCondition(targetSlot < 0, EnumErrorCode.NO_SPACE_INVENTORY)) {
            return false;
        }
        if (getStackInSlot(targetSlot).isEmpty()) {
            setInventorySlotContents(targetSlot, deposit);
        } else {
            getStackInSlot(targetSlot).grow(1);
        }
        decrStackSize(InventoryMoistener.SLOT_WORKING, 1);
    }
    if (!getStackInSlot(InventoryMoistener.SLOT_WORKING).isEmpty()) {
        return true;
    }
    // Let's look for a new resource to put into the working slot.
    int resourceSlot = getNextResourceSlot(InventoryMoistener.SLOT_RESERVOIR_1, InventoryMoistener.SLOT_RESERVOIR_1 + InventoryMoistener.SLOT_RESERVOIR_COUNT);
    // Nothing found, stop.
    if (errorLogic.setCondition(resourceSlot < 0, EnumErrorCode.NO_RESOURCE)) {
        return false;
    }
    setInventorySlotContents(InventoryMoistener.SLOT_WORKING, decrStackSize(resourceSlot, 1));
    return true;
}
Also used : MoistenerFuel(forestry.api.fuels.MoistenerFuel) ItemStack(net.minecraft.item.ItemStack) IErrorLogic(forestry.api.core.IErrorLogic)

Example 24 with IErrorLogic

use of forestry.api.core.IErrorLogic in project ForestryMC by ForestryMC.

the class TileBottler method hasWork.

@Override
public boolean hasWork() {
    FluidHelper.FillStatus emptyStatus;
    FluidHelper.FillStatus fillStatus;
    IErrorLogic errorLogic = getErrorLogic();
    errorLogic.clearErrors();
    checkEmptyRecipe();
    if (currentRecipe != null) {
        IFluidTankProperties properties = tankManager.getTankProperties()[0];
        if (properties != null) {
            emptyStatus = FluidHelper.drainContainers(tankManager, this, InventoryBottler.SLOT_EMPTYING_PROCESSING, InventoryBottler.SLOT_OUTPUT_EMPTY_CONTAINER, false);
        } else {
            emptyStatus = FillStatus.SUCCESS;
        }
    } else {
        emptyStatus = null;
    }
    if (emptyStatus == null || emptyStatus != FillStatus.SUCCESS) {
        checkFillRecipe();
        if (currentRecipe == null) {
            return false;
        } else {
            fillStatus = FluidHelper.fillContainers(tankManager, this, InventoryBottler.SLOT_FILLING_PROCESSING, InventoryBottler.SLOT_OUTPUT_FULL_CONTAINER, currentRecipe.fluid.getFluid(), false);
        }
    } else {
        return true;
    }
    if (fillStatus == FillStatus.SUCCESS) {
        return true;
    }
    errorLogic.setCondition(fillStatus == FluidHelper.FillStatus.NO_FLUID, EnumErrorCode.NO_RESOURCE_LIQUID);
    errorLogic.setCondition(fillStatus == FluidHelper.FillStatus.NO_SPACE, EnumErrorCode.NO_SPACE_INVENTORY);
    errorLogic.setCondition(emptyStatus == FluidHelper.FillStatus.NO_SPACE_FLUID, EnumErrorCode.NO_SPACE_TANK);
    if (emptyStatus == FillStatus.INVALID_INPUT || fillStatus == FillStatus.INVALID_INPUT || errorLogic.hasErrors()) {
        currentRecipe = null;
        return false;
    }
    return true;
}
Also used : FillStatus(forestry.core.fluids.FluidHelper.FillStatus) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) FluidHelper(forestry.core.fluids.FluidHelper) IErrorLogic(forestry.api.core.IErrorLogic)

Example 25 with IErrorLogic

use of forestry.api.core.IErrorLogic 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)25 ItemStack (net.minecraft.item.ItemStack)7 FluidStack (net.minecraftforge.fluids.FluidStack)6 IErrorState (forestry.api.core.IErrorState)2 FarmDirection (forestry.api.farming.FarmDirection)2 ICrop (forestry.api.farming.ICrop)2 IFarmLogic (forestry.api.farming.IFarmLogic)2 MoistenerFuel (forestry.api.fuels.MoistenerFuel)2 FarmWorkStatus (forestry.farming.FarmHelper.FarmWorkStatus)2 FarmTarget (forestry.farming.FarmTarget)2 BlockPos (net.minecraft.util.math.BlockPos)2 EnumBeeType (forestry.api.apiculture.EnumBeeType)1 IBee (forestry.api.apiculture.IBee)1 IBeeHousingInventory (forestry.api.apiculture.IBeeHousingInventory)1 IFarmListener (forestry.api.farming.IFarmListener)1 GeneratorFuel (forestry.api.fuels.GeneratorFuel)1 IClimateHousing (forestry.api.greenhouse.IClimateHousing)1 IGreenhouseController (forestry.api.multiblock.IGreenhouseController)1 IFabricatorRecipe (forestry.api.recipes.IFabricatorRecipe)1 FilteredTank (forestry.core.fluids.FilteredTank)1