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