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;
}
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;
}
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;
}
Aggregations