Search in sources :

Example 1 with IFertilizerResult

use of crazypants.enderio.api.farm.IFertilizerResult in project EnderIO by SleepyTrousers.

the class Bonemeal method apply.

@Override
public IFertilizerResult apply(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos bc) {
    ItemStack before = player.getHeldItem(EnumHand.MAIN_HAND);
    player.setHeldItem(EnumHand.MAIN_HAND, stack);
    EnumActionResult res = stack.getItem().onItemUse(player, world, bc, EnumHand.MAIN_HAND, EnumFacing.UP, 0.5f, 0.5f, 0.5f);
    ItemStack after = player.getHeldItem(EnumHand.MAIN_HAND);
    player.setHeldItem(EnumHand.MAIN_HAND, before);
    return new FertilizerResult(after, res != EnumActionResult.PASS);
}
Also used : EnumActionResult(net.minecraft.util.EnumActionResult) IFertilizerResult(crazypants.enderio.api.farm.IFertilizerResult) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IFertilizerResult

use of crazypants.enderio.api.farm.IFertilizerResult in project EnderIO by SleepyTrousers.

the class MagicalFertilizer method apply.

@Override
public IFertilizerResult apply(@Nonnull ItemStack stack, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos bc) {
    BlockPos below = bc.down();
    Block belowBlock = world.getBlockState(below).getBlock();
    if (belowBlock == Blocks.DIRT || belowBlock == Blocks.GRASS) {
        return super.apply(stack, player, world, below);
    }
    return new FertilizerResult(stack, false);
}
Also used : IFertilizerResult(crazypants.enderio.api.farm.IFertilizerResult) FertilizerResult(crazypants.enderio.base.farming.fertilizer.FertilizerResult) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with IFertilizerResult

use of crazypants.enderio.api.farm.IFertilizerResult 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

IFertilizerResult (crazypants.enderio.api.farm.IFertilizerResult)3 ItemStack (net.minecraft.item.ItemStack)2 IFertilizer (crazypants.enderio.api.farm.IFertilizer)1 FertilizerResult (crazypants.enderio.base.farming.fertilizer.FertilizerResult)1 Block (net.minecraft.block.Block)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 BlockPos (net.minecraft.util.math.BlockPos)1 FakePlayer (net.minecraftforge.common.util.FakePlayer)1