Search in sources :

Example 6 with IErrorLogic

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

the class BeekeepingLogic method canWork.

/* UPDATING */
@Override
public boolean canWork() {
    IErrorLogic errorLogic = housing.getErrorLogic();
    errorLogic.clearErrors();
    IBeeHousingInventory beeInventory = housing.getBeeInventory();
    boolean hasSpace = addPendingProducts(beeInventory, spawn);
    errorLogic.setCondition(!hasSpace, EnumErrorCode.NO_SPACE_INVENTORY);
    ItemStack queenStack = beeInventory.getQueen();
    EnumBeeType beeType = BeeManager.beeRoot.getType(queenStack);
    // check if we're breeding
    if (beeType == EnumBeeType.PRINCESS) {
        boolean hasDrone = BeeManager.beeRoot.isDrone(beeInventory.getDrone());
        errorLogic.setCondition(!hasDrone, EnumErrorCode.NO_DRONE);
        // not active (no bee FX) when we are breeding
        setActive(false);
        return !errorLogic.hasErrors();
    }
    if (beeType == EnumBeeType.QUEEN) {
        if (!isQueenAlive(queenStack)) {
            IBee dyingQueen = BeeManager.beeRoot.getMember(queenStack);
            Collection<ItemStack> spawned = killQueen(dyingQueen, housing, beeListener);
            spawn.addAll(spawned);
            queenStack = ItemStack.EMPTY;
        }
    } else {
        queenStack = ItemStack.EMPTY;
    }
    if (this.queenStack != queenStack) {
        if (!queenStack.isEmpty()) {
            this.queen = BeeManager.beeRoot.getMember(queenStack);
            if (this.queen != null) {
                hasFlowersCache.onNewQueen(queen, housing);
            }
        } else {
            this.queen = null;
        }
        this.queenStack = queenStack;
        queenCanWorkCache.clear();
    }
    if (errorLogic.setCondition(queen == null, EnumErrorCode.NO_QUEEN)) {
        setActive(false);
        beeProgress = 0;
        return false;
    }
    Set<IErrorState> queenErrors = queenCanWorkCache.queenCanWork(queen, housing);
    for (IErrorState errorState : queenErrors) {
        errorLogic.setCondition(true, errorState);
    }
    hasFlowersCache.update(queen, housing);
    boolean hasFlowers = hasFlowersCache.hasFlowers();
    boolean flowerCacheNeedsSync = hasFlowersCache.needsSync();
    errorLogic.setCondition(!hasFlowers, EnumErrorCode.NO_FLOWER);
    boolean canWork = !errorLogic.hasErrors();
    if (active != canWork) {
        setActive(canWork);
    } else if (flowerCacheNeedsSync) {
        syncToClient();
    }
    return canWork;
}
Also used : IBeeHousingInventory(forestry.api.apiculture.IBeeHousingInventory) IErrorState(forestry.api.core.IErrorState) IBee(forestry.api.apiculture.IBee) ItemStack(net.minecraft.item.ItemStack) IErrorLogic(forestry.api.core.IErrorLogic) EnumBeeType(forestry.api.apiculture.EnumBeeType)

Example 7 with IErrorLogic

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

the class TilePowered method updateServerSide.

@Override
protected void updateServerSide() {
    super.updateServerSide();
    if (!updateOnInterval(WORK_TICK_INTERVAL)) {
        return;
    }
    IErrorLogic errorLogic = getErrorLogic();
    boolean disabled = isRedstoneActivated();
    errorLogic.setCondition(disabled, EnumErrorCode.DISABLED_BY_REDSTONE);
    if (disabled) {
        return;
    }
    if (!hasWork()) {
        return;
    }
    int ticksPerWorkCycle = getTicksPerWorkCycle();
    if (workCounter < ticksPerWorkCycle) {
        int energyPerWorkCycle = getEnergyPerWorkCycle();
        boolean consumedEnergy = EnergyHelper.consumeEnergyToDoWork(energyManager, ticksPerWorkCycle, energyPerWorkCycle);
        if (consumedEnergy) {
            errorLogic.setCondition(false, EnumErrorCode.NO_POWER);
            workCounter++;
            noPowerTime = 0;
        } else {
            noPowerTime++;
            if (noPowerTime > 4) {
                errorLogic.setCondition(true, EnumErrorCode.NO_POWER);
            }
        }
    }
    if (workCounter >= ticksPerWorkCycle) {
        if (workCycle()) {
            workCounter = 0;
        }
    }
}
Also used : IErrorLogic(forestry.api.core.IErrorLogic)

Example 8 with IErrorLogic

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

the class ClimateSourceClimatiser method canWork.

@Override
public boolean canWork(IClimateState currentState, ClimateSourceType oppositeType) {
    IClimateHousing region = container.getParent();
    if (region instanceof IGreenhouseControllerInternal) {
        IGreenhouseControllerInternal controller = (IGreenhouseControllerInternal) region;
        IErrorLogic errorLogic = owner.getErrorLogic();
        EnergyManager energyManager = controller.getEnergyManager();
        if (energyManager.extractEnergy((int) (ENERGY_PER_OPERATION * getEnergyModifier(currentState, oppositeType)), true) > 0) {
            owner.setActive(true);
            errorLogic.setCondition(false, EnumErrorCode.NO_POWER);
            return true;
        } else {
            owner.setActive(false);
            errorLogic.setCondition(true, EnumErrorCode.NO_POWER);
            return false;
        }
    }
    if (owner.isActive()) {
        owner.setActive(false);
    }
    return false;
}
Also used : EnergyManager(forestry.energy.EnergyManager) IGreenhouseControllerInternal(forestry.greenhouse.multiblock.IGreenhouseControllerInternal) IErrorLogic(forestry.api.core.IErrorLogic) IClimateHousing(forestry.api.greenhouse.IClimateHousing)

Example 9 with IErrorLogic

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

the class ClimateSourceHygroregulator method canWork.

@Override
public boolean canWork(IClimateState currentState, ClimateSourceType oppositeType) {
    createRecipe();
    FilteredTank liquidTank = owner.getLiquidTank();
    IErrorLogic errorLogic = owner.getErrorLogic();
    if (currentRecipe != null && liquidTank.drainInternal(currentRecipe.liquid.amount, false) != null) {
        errorLogic.setCondition(false, EnumErrorCode.NO_RESOURCE_LIQUID);
        return true;
    }
    errorLogic.setCondition(true, EnumErrorCode.NO_RESOURCE_LIQUID);
    return false;
}
Also used : FilteredTank(forestry.core.fluids.FilteredTank) IErrorLogic(forestry.api.core.IErrorLogic)

Example 10 with IErrorLogic

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

the class TileFabricator method hasWork.

@Override
public boolean hasWork() {
    boolean hasRecipe = true;
    boolean hasLiquidResources = true;
    boolean hasResources = true;
    ItemStack plan = getStackInSlot(InventoryFabricator.SLOT_PLAN);
    RecipePair<IFabricatorRecipe> recipePair = FabricatorRecipeManager.findMatchingRecipe(plan, craftingInventory);
    if (!recipePair.isEmpty()) {
        IFabricatorRecipe recipe = recipePair.getRecipe();
        NonNullList<ItemStack> crafting = InventoryUtil.getStacks(craftingInventory, InventoryGhostCrafting.SLOT_CRAFTING_1, InventoryGhostCrafting.SLOT_CRAFTING_COUNT);
        hasResources = removeFromInventory(crafting, recipePair, false);
        FluidStack toDrain = recipe.getLiquid();
        FluidStack drained = moltenTank.drainInternal(toDrain, false);
        hasLiquidResources = drained != null && drained.isFluidStackIdentical(toDrain);
    } else {
        hasRecipe = false;
    }
    IErrorLogic errorLogic = getErrorLogic();
    errorLogic.setCondition(!hasRecipe, EnumErrorCode.NO_RECIPE);
    errorLogic.setCondition(!hasLiquidResources, EnumErrorCode.NO_RESOURCE_LIQUID);
    errorLogic.setCondition(!hasResources, EnumErrorCode.NO_RESOURCE_INVENTORY);
    return hasRecipe;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack) IFabricatorRecipe(forestry.api.recipes.IFabricatorRecipe) 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