use of com.infinityraider.agricraft.api.v1.plant.IAgriPlantProvider in project AgriCraft by AgriCraft.
the class JsonFertilizer method applyFertilizer.
@Override
public ActionResultType applyFertilizer(World world, BlockPos pos, IAgriFertilizable target, ItemStack stack, Random random, @Nullable LivingEntity entity) {
if (target instanceof IAgriPlantProvider) {
IAgriCrop crop = ((IAgriCrop) target);
String type = "neutral";
for (int i = 0; i < this.potency; i++) {
if (fertilizerEffect.isNegativelyAffected(crop.getPlant().getId())) {
if (fertilizerEffect.canReduceGrowth() && random.nextBoolean()) {
type = "negative";
IAgriGrowthStage current = crop.getGrowthStage();
IAgriGrowthStage previous = current.getPreviousStage(crop, random);
if (current.equals(previous)) {
if (fertilizerEffect.canKillPlant()) {
crop.removeGenome();
}
} else {
crop.setGrowthStage(previous);
}
}
} else {
if (crop.hasPlant() && this.fertilizerEffect.canFertilize(crop.getPlant().getId())) {
target.applyGrowthTick();
type = "positive";
} else if (crop.isCrossCrop() && this.canTriggerMutation()) {
target.applyGrowthTick();
type = "positive";
} else if (this.canTriggerWeeds()) {
target.applyGrowthTick();
type = "positive";
}
}
}
this.spawnParticles(world, pos, type, random);
if ((entity instanceof PlayerEntity) && !(((PlayerEntity) entity).isCreative())) {
stack.shrink(1);
}
return ActionResultType.SUCCESS;
}
return ActionResultType.FAIL;
}
Aggregations