Search in sources :

Example 1 with IErrorLogic

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

the class TilePlanter method cullCrop.

private boolean cullCrop(ICrop crop) {
    final int fertilizerConsumption = Math.round(logic.getFertilizerConsumption() * Config.fertilizerModifier * 2);
    IErrorLogic errorLogic = getErrorLogic();
    // Check fertilizer
    Boolean hasFertilizer = fertilizerManager.hasFertilizer(inventory, fertilizerConsumption);
    if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NO_FERTILIZER)) {
        return false;
    }
    // Check water
    float hydrationModifier = hydrationManager.getHydrationModifier();
    int waterConsumption = logic.getWaterConsumption(hydrationModifier);
    FluidStack requiredLiquid = new FluidStack(FluidRegistry.WATER, waterConsumption);
    boolean hasLiquid = requiredLiquid.amount == 0 || hasLiquid(requiredLiquid);
    if (errorLogic.setCondition(!hasLiquid, EnumErrorCode.NO_LIQUID_FARM)) {
        return false;
    }
    NonNullList<ItemStack> harvested = crop.harvest();
    if (harvested != null) {
        // Remove fertilizer and water
        fertilizerManager.removeFertilizer(inventory, fertilizerConsumption);
        removeLiquid(requiredLiquid);
        inventory.stowHarvest(harvested, pendingProduce);
    }
    return true;
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack) IErrorLogic(forestry.api.core.IErrorLogic)

Example 2 with IErrorLogic

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

the class TileTrader method setAddress.

private void setAddress(IMailAddress address) {
    Preconditions.checkNotNull(address, "address must not be null");
    if (this.address.isValid() && this.address.equals(address)) {
        return;
    }
    if (!world.isRemote) {
        IErrorLogic errorLogic = getErrorLogic();
        boolean hasValidTradeAddress = PostManager.postRegistry.isValidTradeAddress(world, address);
        errorLogic.setCondition(!hasValidTradeAddress, EnumErrorCode.NOT_ALPHANUMERIC);
        boolean hasUniqueTradeAddress = PostManager.postRegistry.isAvailableTradeAddress(world, address);
        errorLogic.setCondition(!hasUniqueTradeAddress, EnumErrorCode.NOT_UNIQUE);
        if (hasValidTradeAddress & hasUniqueTradeAddress) {
            this.address = address;
            PostManager.postRegistry.getOrCreateTradeStation(world, getOwnerHandler().getOwner(), address);
        }
    } else {
        this.address = address;
    }
}
Also used : IErrorLogic(forestry.api.core.IErrorLogic)

Example 3 with IErrorLogic

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

the class TileEngineElectric method updateServerSide.

// / WORK
@Override
public void updateServerSide() {
    IErrorLogic errorLogic = getErrorLogic();
    // No work to be done if IC2 is unavailable.
    if (errorLogic.setCondition(ic2EnergySink == null, EnumErrorCode.NO_ENERGY_NET)) {
        return;
    }
    ic2EnergySink.update();
    super.updateServerSide();
    if (forceCooldown) {
        return;
    }
    if (getStackInSlot(InventoryEngineElectric.SLOT_BATTERY) != null) {
        replenishFromBattery(InventoryEngineElectric.SLOT_BATTERY);
    }
    // Updating of gui delayed to prevent it from going crazy
    if (!updateOnInterval(80)) {
        return;
    }
    boolean canUseEnergy = ic2EnergySink.canUseEnergy(euConfig.euForCycle);
    errorLogic.setCondition(!canUseEnergy, EnumErrorCode.NO_FUEL);
}
Also used : IErrorLogic(forestry.api.core.IErrorLogic)

Example 4 with IErrorLogic

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

the class FarmController method cullCrop.

private boolean cullCrop(ICrop crop, IFarmLogic provider) {
    // Let event handlers handle the harvest first.
    for (IFarmListener listener : farmListeners) {
        if (listener.beforeCropHarvest(crop)) {
            return true;
        }
    }
    final int fertilizerConsumption = Math.round(provider.getFertilizerConsumption() * Config.fertilizerModifier);
    IErrorLogic errorLogic = getErrorLogic();
    // Check fertilizer
    Boolean hasFertilizer = fertilizerManager.hasFertilizer(inventory, fertilizerConsumption);
    if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NO_FERTILIZER)) {
        return false;
    }
    // Check water
    float hydrationModifier = hydrationManager.getHydrationModifier();
    int waterConsumption = provider.getWaterConsumption(hydrationModifier);
    FluidStack requiredLiquid = new FluidStack(FluidRegistry.WATER, waterConsumption);
    boolean hasLiquid = requiredLiquid.amount == 0 || hasLiquid(requiredLiquid);
    if (errorLogic.setCondition(!hasLiquid, EnumErrorCode.NO_LIQUID_FARM)) {
        return false;
    }
    NonNullList<ItemStack> harvested = crop.harvest();
    if (harvested != null) {
        // Remove fertilizer and water
        fertilizerManager.removeFertilizer(inventory, fertilizerConsumption);
        removeLiquid(requiredLiquid);
        // Let event handlers handle the harvest first.
        for (IFarmListener listener : farmListeners) {
            listener.afterCropHarvest(harvested, crop);
        }
        inventory.stowHarvest(harvested, pendingProduce);
    }
    return true;
}
Also used : IFarmListener(forestry.api.farming.IFarmListener) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack) IErrorLogic(forestry.api.core.IErrorLogic)

Example 5 with IErrorLogic

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

the class FarmController method doWork.

@Override
public boolean doWork() {
    farmWorkTicks++;
    if (targets.isEmpty() || farmWorkTicks % 20 == 0) {
        setUpFarmlandTargets();
    }
    IErrorLogic errorLogic = getErrorLogic();
    if (!pendingProduce.isEmpty()) {
        boolean added = inventory.tryAddPendingProduce(pendingProduce);
        errorLogic.setCondition(!added, EnumErrorCode.NO_SPACE_INVENTORY);
        return added;
    }
    boolean hasFertilizer = fertilizerManager.maintainFertilizer(inventory);
    if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NO_FERTILIZER)) {
        return false;
    }
    // Cull queued crops.
    if (!pendingCrops.isEmpty() && harvestProvider != null) {
        ICrop first = pendingCrops.get(0);
        if (cullCrop(first, harvestProvider)) {
            pendingCrops.remove(0);
            return true;
        } else {
            return false;
        }
    }
    // Cultivation and collection
    FarmWorkStatus farmWorkStatus = new FarmWorkStatus();
    List<FarmDirection> farmDirections = Arrays.asList(FarmDirection.values());
    Collections.shuffle(farmDirections, world.rand);
    for (FarmDirection farmSide : farmDirections) {
        IFarmLogic logic = getFarmLogic(farmSide);
        // Always try to collect windfall.
        if (collectWindfall(logic)) {
            farmWorkStatus.didWork = true;
        }
        List<FarmTarget> farmTargets = targets.get(farmSide);
        if (stage == Stage.HARVEST) {
            Collection<ICrop> harvested = FarmHelper.harvestTargets(world, farmTargets, logic, farmListeners);
            farmWorkStatus.didWork = !harvested.isEmpty();
            if (!harvested.isEmpty()) {
                pendingCrops.addAll(harvested);
                pendingCrops.sort(FarmHelper.TopDownICropComparator.INSTANCE);
                harvestProvider = logic;
            }
        } else if (stage == Stage.CULTIVATE) {
            farmWorkStatus = cultivateTargets(farmWorkStatus, farmTargets, logic, farmSide);
        }
        if (farmWorkStatus.didWork) {
            break;
        }
    }
    if (stage == Stage.CULTIVATE) {
        errorLogic.setCondition(!farmWorkStatus.hasFarmland, EnumErrorCode.NO_FARMLAND);
        errorLogic.setCondition(!farmWorkStatus.hasFertilizer, EnumErrorCode.NO_FERTILIZER);
        errorLogic.setCondition(!farmWorkStatus.hasLiquid, EnumErrorCode.NO_LIQUID_FARM);
    }
    // alternate between cultivation and harvest.
    stage = stage.next();
    return farmWorkStatus.didWork;
}
Also used : FarmWorkStatus(forestry.farming.FarmHelper.FarmWorkStatus) FarmTarget(forestry.farming.FarmTarget) FarmDirection(forestry.api.farming.FarmDirection) IFarmLogic(forestry.api.farming.IFarmLogic) ICrop(forestry.api.farming.ICrop) 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