Search in sources :

Example 1 with IFertilizer

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);
        }
    }
}
Also used : IFertilizerResult(crazypants.enderio.api.farm.IFertilizerResult) ItemStack(net.minecraft.item.ItemStack) IFertilizer(crazypants.enderio.api.farm.IFertilizer) FakePlayer(net.minecraftforge.common.util.FakePlayer)

Aggregations

IFertilizer (crazypants.enderio.api.farm.IFertilizer)1 IFertilizerResult (crazypants.enderio.api.farm.IFertilizerResult)1 ItemStack (net.minecraft.item.ItemStack)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1