Search in sources :

Example 1 with IFarmListener

use of forestry.api.farming.IFarmListener in project ForestryMC by ForestryMC.

the class FarmController method collectWindfall.

private boolean collectWindfall(IFarmLogic logic) {
    NonNullList<ItemStack> collected = logic.collect(world, this);
    if (collected.isEmpty()) {
        return false;
    }
    // Let event handlers know.
    for (IFarmListener listener : farmListeners) {
        listener.hasCollected(collected, logic);
    }
    for (ItemStack produce : collected) {
        inventory.addProduce(produce);
        pendingProduce.push(produce);
    }
    return true;
}
Also used : IFarmListener(forestry.api.farming.IFarmListener) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IFarmListener

use of forestry.api.farming.IFarmListener 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 3 with IFarmListener

use of forestry.api.farming.IFarmListener in project ForestryMC by ForestryMC.

the class FarmHelper method harvestTarget.

public static Collection<ICrop> harvestTarget(World world, FarmTarget target, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
    BlockPos pos = target.getStart().add(0, target.getYOffset(), 0);
    Collection<ICrop> harvested = logic.harvest(world, pos, target.getDirection(), target.getExtent());
    if (!harvested.isEmpty()) {
        // Let event handlers know.
        for (IFarmListener listener : farmListeners) {
            listener.hasScheduledHarvest(harvested, logic, pos, target.getDirection(), target.getExtent());
        }
    }
    return harvested;
}
Also used : IFarmListener(forestry.api.farming.IFarmListener) BlockPos(net.minecraft.util.math.BlockPos) ICrop(forestry.api.farming.ICrop)

Aggregations

IFarmListener (forestry.api.farming.IFarmListener)3 ItemStack (net.minecraft.item.ItemStack)2 IErrorLogic (forestry.api.core.IErrorLogic)1 ICrop (forestry.api.farming.ICrop)1 BlockPos (net.minecraft.util.math.BlockPos)1 FluidStack (net.minecraftforge.fluids.FluidStack)1