use of crazypants.enderio.api.farm.IFertilizer in project EnderIO by SleepyTrousers.
the class TileFarmStation method executeBonemeal.
private void executeBonemeal(@Nonnull IFarmer farmer, @Nonnull BlockPos farmingPos, @Nonnull Block block) {
if (hasBonemeal() && bonemealCooldown-- <= 0 && random.nextFloat() <= FarmConfig.farmBonemealChance.get() && farmer.checkAction(FarmingAction.FERTILIZE, FarmingTool.HAND)) {
final ItemStack fertStack = getStackInSlot(minFirtSlot);
IFertilizer fertilizer = Fertilizer.getInstance(fertStack);
boolean doApply;
if (fertilizer.applyOnPlant() && fertilizer.applyOnAir()) {
doApply = !isOpen(farmingPos, block) || world.isAirBlock(farmingPos);
} else if (fertilizer.applyOnPlant()) {
doApply = !isOpen(farmingPos, block);
} else if (fertilizer.applyOnAir()) {
doApply = world.isAirBlock(farmingPos);
} else {
doApply = true;
}
if (doApply) {
FakePlayer farmerJoe = farmer.startUsingItem(Prep.getEmpty());
final IFertilizerResult result = fertilizer.apply(fertStack, farmerJoe, world, farmingPos);
if (result.wasApplied()) {
setInventorySlotContents(minFirtSlot, result.getStack());
PacketHandler.sendToAllAround(new PacketFarmAction(farmingPos), this);
bonemealCooldown = FarmConfig.farmBonemealDelaySuccess.get();
farmer.registerAction(FarmingAction.FERTILIZE, FarmingTool.HAND);
} else {
usePower(FarmConfig.farmBonemealEnergyUseFail.get());
bonemealCooldown = FarmConfig.farmBonemealDelayFail.get();
}
farmer.handleExtraItems(farmer.endUsingItem(false), farmingPos);
}
}
}
Aggregations