Search in sources :

Example 1 with JobDruid

use of com.minecolonies.coremod.colony.jobs.JobDruid in project minecolonies by Minecolonies.

the class DruidPotionEntity method applySplash.

@Override
public void applySplash(@NotNull List<EffectInstance> effects, @Nullable Entity entity) {
    final AbstractEntityCitizen citizen = this.getOwner();
    if (citizen != null && citizen.getCitizenData().getJob() instanceof JobDruid) {
        final AxisAlignedBB axisalignedbb = this.getBoundingBox().inflate(SPLASH_SIZE, SPLASH_HEIGTH, SPLASH_SIZE);
        final List<LivingEntity> list = this.level.getEntitiesOfClass(LivingEntity.class, axisalignedbb);
        if (!list.isEmpty()) {
            for (final LivingEntity livingentity : list) {
                if (livingentity.isAffectedByPotions()) {
                    final double distanceSq = this.distanceToSqr(livingentity);
                    if (distanceSq < MAX_DISTANCE) {
                        double d1 = 1.0D - Math.sqrt(distanceSq) / 4.0D;
                        if (livingentity == entity) {
                            d1 = 1.0D;
                        }
                        for (final EffectInstance effectinstance : effects) {
                            final Effect effect = effectinstance.getEffect();
                            if (entitySelectionPredicate == null || entitySelectionPredicate.test(livingentity, effect)) {
                                if (effect.isInstantenous()) {
                                    effect.applyInstantenousEffect(this, this.getOwner(), livingentity, effectinstance.getAmplifier(), d1);
                                } else {
                                    final int duration = (int) (d1 * (double) effectinstance.getDuration());
                                    livingentity.addEffect(new EffectInstance(effect, duration, effectinstance.getAmplifier(), effectinstance.isAmbient(), effectinstance.isVisible()));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) LivingEntity(net.minecraft.entity.LivingEntity) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) Effect(net.minecraft.potion.Effect) JobDruid(com.minecolonies.coremod.colony.jobs.JobDruid) EffectInstance(net.minecraft.potion.EffectInstance)

Example 2 with JobDruid

use of com.minecolonies.coremod.colony.jobs.JobDruid in project minecolonies by ldtteam.

the class DruidPotionEntity method applySplash.

@Override
public void applySplash(@NotNull List<EffectInstance> effects, @Nullable Entity entity) {
    final AbstractEntityCitizen citizen = this.getOwner();
    if (citizen != null && citizen.getCitizenData() != null && citizen.getCitizenData().getJob() instanceof JobDruid) {
        final AxisAlignedBB axisalignedbb = this.getBoundingBox().inflate(SPLASH_SIZE, SPLASH_HEIGTH, SPLASH_SIZE);
        final List<LivingEntity> list = this.level.getEntitiesOfClass(LivingEntity.class, axisalignedbb);
        if (!list.isEmpty()) {
            for (final LivingEntity livingentity : list) {
                if (livingentity.isAffectedByPotions()) {
                    final double distanceSq = this.distanceToSqr(livingentity);
                    if (distanceSq < MAX_DISTANCE) {
                        double d1 = 1.0D - Math.sqrt(distanceSq) / 4.0D;
                        if (livingentity == entity) {
                            d1 = 1.0D;
                        }
                        for (final EffectInstance effectinstance : effects) {
                            final Effect effect = effectinstance.getEffect();
                            if (entitySelectionPredicate == null || entitySelectionPredicate.test(livingentity, effect)) {
                                if (effect.isInstantenous()) {
                                    effect.applyInstantenousEffect(this, this.getOwner(), livingentity, effectinstance.getAmplifier(), d1);
                                } else {
                                    final int duration = (int) (d1 * (double) effectinstance.getDuration());
                                    livingentity.addEffect(new EffectInstance(effect, duration, effectinstance.getAmplifier(), effectinstance.isAmbient(), effectinstance.isVisible()));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) LivingEntity(net.minecraft.entity.LivingEntity) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) Effect(net.minecraft.potion.Effect) JobDruid(com.minecolonies.coremod.colony.jobs.JobDruid) EffectInstance(net.minecraft.potion.EffectInstance)

Aggregations

AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)2 JobDruid (com.minecolonies.coremod.colony.jobs.JobDruid)2 LivingEntity (net.minecraft.entity.LivingEntity)2 Effect (net.minecraft.potion.Effect)2 EffectInstance (net.minecraft.potion.EffectInstance)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2