Search in sources :

Example 1 with IAgriPlantProvider

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;
}
Also used : IAgriPlantProvider(com.infinityraider.agricraft.api.v1.plant.IAgriPlantProvider) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) IAgriGrowthStage(com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)1 IAgriGrowthStage (com.infinityraider.agricraft.api.v1.crop.IAgriGrowthStage)1 IAgriPlantProvider (com.infinityraider.agricraft.api.v1.plant.IAgriPlantProvider)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1