Search in sources :

Example 1 with EntityPotionEffectEvent

use of org.bukkit.event.entity.EntityPotionEffectEvent in project Arclight by IzzelAliz.

the class LivingEntityMixin_1_14 method updatePotionEffects.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
protected void updatePotionEffects() {
    this.isTickingEffects = true;
    Iterator<Effect> iterator = this.activePotionsMap.keySet().iterator();
    try {
        while (iterator.hasNext()) {
            Effect effect = iterator.next();
            EffectInstance effectinstance = this.activePotionsMap.get(effect);
            if (!effectinstance.tick((LivingEntity) (Object) this)) {
                if (!this.world.isRemote && !MinecraftForge.EVENT_BUS.post(new PotionEvent.PotionExpiryEvent((LivingEntity) (Object) this, effectinstance))) {
                    EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent((LivingEntity) (Object) this, effectinstance, null, org.bukkit.event.entity.EntityPotionEffectEvent.Cause.EXPIRATION);
                    if (event.isCancelled()) {
                        continue;
                    }
                    iterator.remove();
                    this.onFinishedPotionEffect(effectinstance);
                }
            } else if (effectinstance.getDuration() % 600 == 0) {
                this.onChangedPotionEffect(effectinstance, false);
            }
        }
    } catch (ConcurrentModificationException ignored) {
    }
    isTickingEffects = false;
    for (Map.Entry<Either<EffectInstance, Effect>, EntityPotionEffectEvent.Cause> e : effectsToProcess) {
        Either<EffectInstance, Effect> either = e.getKey();
        EntityPotionEffectEvent.Cause cause = e.getValue();
        bridge$pushEffectCause(cause);
        if (either.left().isPresent()) {
            addPotionEffect(either.left().get());
        } else {
            removePotionEffect(either.right().get());
        }
    }
    effectsToProcess.clear();
    if (this.potionsNeedUpdate) {
        if (!this.world.isRemote) {
            this.updatePotionMetadata();
        }
        this.potionsNeedUpdate = false;
    }
    int i = this.dataManager.get(POTION_EFFECTS);
    boolean flag1 = this.dataManager.get(HIDE_PARTICLES);
    if (i > 0) {
        boolean flag;
        if (this.isInvisible()) {
            flag = this.rand.nextInt(15) == 0;
        } else {
            flag = this.rand.nextBoolean();
        }
        if (flag1) {
            flag &= this.rand.nextInt(5) == 0;
        }
        if (flag && i > 0) {
            double d0 = (double) (i >> 16 & 255) / 255.0D;
            double d1 = (double) (i >> 8 & 255) / 255.0D;
            double d2 = (double) (i >> 0 & 255) / 255.0D;
            this.world.addParticle(flag1 ? ParticleTypes.AMBIENT_ENTITY_EFFECT : ParticleTypes.ENTITY_EFFECT, this.posX + (this.rand.nextDouble() - 0.5D) * (double) this.getWidth(), this.posY + this.rand.nextDouble() * (double) this.getHeight(), this.posZ + (this.rand.nextDouble() - 0.5D) * (double) this.getWidth(), d0, d1, d2);
        }
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) LivingEntity(net.minecraft.entity.LivingEntity) EntityPotionEffectEvent(org.bukkit.event.entity.EntityPotionEffectEvent) Either(com.mojang.datafixers.util.Either) Effect(net.minecraft.potion.Effect) Map(java.util.Map) EffectInstance(net.minecraft.potion.EffectInstance) PotionEvent(net.minecraftforge.event.entity.living.PotionEvent) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with EntityPotionEffectEvent

use of org.bukkit.event.entity.EntityPotionEffectEvent in project Arclight by IzzelAliz.

the class LivingEntityMixin_1_15 method updatePotionEffects.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
protected void updatePotionEffects() {
    this.isTickingEffects = true;
    Iterator<Effect> iterator = this.activePotionsMap.keySet().iterator();
    try {
        while (iterator.hasNext()) {
            Effect effect = iterator.next();
            EffectInstance effectinstance = this.activePotionsMap.get(effect);
            if (!effectinstance.tick((LivingEntity) (Object) this, () -> {
                onChangedPotionEffect(effectinstance, true);
            })) {
                if (!this.world.isRemote && !MinecraftForge.EVENT_BUS.post(new PotionEvent.PotionExpiryEvent((LivingEntity) (Object) this, effectinstance))) {
                    EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent((LivingEntity) (Object) this, effectinstance, null, EntityPotionEffectEvent.Cause.EXPIRATION);
                    if (event.isCancelled()) {
                        continue;
                    }
                    iterator.remove();
                    this.onFinishedPotionEffect(effectinstance);
                }
            } else if (effectinstance.getDuration() % 600 == 0) {
                this.onChangedPotionEffect(effectinstance, false);
            }
        }
    } catch (ConcurrentModificationException ignored) {
    }
    isTickingEffects = false;
    for (Map.Entry<Either<EffectInstance, Effect>, EntityPotionEffectEvent.Cause> e : effectsToProcess) {
        Either<EffectInstance, Effect> either = e.getKey();
        EntityPotionEffectEvent.Cause cause = e.getValue();
        bridge$pushEffectCause(cause);
        if (either.left().isPresent()) {
            addPotionEffect(either.left().get());
        } else {
            removePotionEffect(either.right().get());
        }
    }
    effectsToProcess.clear();
    if (this.potionsNeedUpdate) {
        if (!this.world.isRemote) {
            this.updatePotionMetadata();
        }
        this.potionsNeedUpdate = false;
    }
    int i = this.dataManager.get(POTION_EFFECTS);
    boolean flag1 = this.dataManager.get(HIDE_PARTICLES);
    if (i > 0) {
        boolean flag;
        if (this.isInvisible()) {
            flag = this.rand.nextInt(15) == 0;
        } else {
            flag = this.rand.nextBoolean();
        }
        if (flag1) {
            flag &= this.rand.nextInt(5) == 0;
        }
        if (flag && i > 0) {
            double d0 = (double) (i >> 16 & 255) / 255.0D;
            double d1 = (double) (i >> 8 & 255) / 255.0D;
            double d2 = (double) (i >> 0 & 255) / 255.0D;
            this.world.addParticle(flag1 ? ParticleTypes.AMBIENT_ENTITY_EFFECT : ParticleTypes.ENTITY_EFFECT, this.getPosX() + (this.rand.nextDouble() - 0.5D) * (double) this.getWidth(), this.getPosY() + this.rand.nextDouble() * (double) this.getHeight(), this.getPosZ() + (this.rand.nextDouble() - 0.5D) * (double) this.getWidth(), d0, d1, d2);
        }
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) LivingEntity(net.minecraft.entity.LivingEntity) EntityPotionEffectEvent(org.bukkit.event.entity.EntityPotionEffectEvent) Either(com.mojang.datafixers.util.Either) Effect(net.minecraft.potion.Effect) Map(java.util.Map) EffectInstance(net.minecraft.potion.EffectInstance) PotionEvent(net.minecraftforge.event.entity.living.PotionEvent) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 3 with EntityPotionEffectEvent

use of org.bukkit.event.entity.EntityPotionEffectEvent in project Arclight by IzzelAliz.

the class LivingEntityMixin_1_15 method addPotionEffect.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public boolean addPotionEffect(EffectInstance effectInstanceIn) {
    EntityPotionEffectEvent.Cause cause = bridge$getEffectCause().orElse(EntityPotionEffectEvent.Cause.UNKNOWN);
    if (isTickingEffects) {
        effectsToProcess.add(Maps.immutableEntry(Either.left(effectInstanceIn), cause));
        return true;
    }
    if (!this.isPotionApplicable(effectInstanceIn)) {
        return false;
    } else {
        EffectInstance effectinstance = this.activePotionsMap.get(effectInstanceIn.getPotion());
        boolean override = false;
        if (effectinstance != null) {
            override = new EffectInstance(effectinstance).combine(effectInstanceIn);
        }
        EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent((LivingEntity) (Object) this, effectinstance, effectInstanceIn, cause, override);
        if (event.isCancelled()) {
            return false;
        }
        MinecraftForge.EVENT_BUS.post(new PotionEvent.PotionAddedEvent((LivingEntity) (Object) this, effectinstance, effectInstanceIn));
        if (effectinstance == null) {
            this.activePotionsMap.put(effectInstanceIn.getPotion(), effectInstanceIn);
            this.onNewPotionEffect(effectInstanceIn);
            return true;
        } else if (event.isOverride()) {
            effectinstance.combine(effectInstanceIn);
            this.onChangedPotionEffect(effectinstance, true);
            return true;
        } else {
            return false;
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) EntityPotionEffectEvent(org.bukkit.event.entity.EntityPotionEffectEvent) EffectInstance(net.minecraft.potion.EffectInstance) PotionEvent(net.minecraftforge.event.entity.living.PotionEvent) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with EntityPotionEffectEvent

use of org.bukkit.event.entity.EntityPotionEffectEvent in project Arclight by IzzelAliz.

the class LivingEntityMixin_1_14 method arclight$clearActive.

@Inject(method = "removeActivePotionEffect", cancellable = true, at = @At("HEAD"))
public void arclight$clearActive(Effect effect, CallbackInfoReturnable<EffectInstance> cir) {
    EntityPotionEffectEvent.Cause cause = bridge$getEffectCause().orElse(EntityPotionEffectEvent.Cause.UNKNOWN);
    if (isTickingEffects) {
        effectsToProcess.add(Maps.immutableEntry(Either.right(effect), cause));
        cir.setReturnValue(null);
        return;
    }
    EffectInstance effectInstance = this.activePotionsMap.get(effect);
    if (effectInstance == null) {
        cir.setReturnValue(null);
        return;
    }
    EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent((LivingEntity) (Object) this, effectInstance, null, cause);
    if (event.isCancelled()) {
        cir.setReturnValue(null);
    }
}
Also used : EntityPotionEffectEvent(org.bukkit.event.entity.EntityPotionEffectEvent) EffectInstance(net.minecraft.potion.EffectInstance) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with EntityPotionEffectEvent

use of org.bukkit.event.entity.EntityPotionEffectEvent in project Arclight by IzzelAliz.

the class LivingEntityMixin_1_14 method addPotionEffect.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public boolean addPotionEffect(EffectInstance effectInstanceIn) {
    EntityPotionEffectEvent.Cause cause = bridge$getEffectCause().orElse(EntityPotionEffectEvent.Cause.UNKNOWN);
    if (isTickingEffects) {
        effectsToProcess.add(Maps.immutableEntry(Either.left(effectInstanceIn), cause));
        return true;
    }
    if (!this.isPotionApplicable(effectInstanceIn)) {
        return false;
    } else {
        EffectInstance effectinstance = this.activePotionsMap.get(effectInstanceIn.getPotion());
        boolean override = false;
        if (effectinstance != null) {
            override = new EffectInstance(effectinstance).combine(effectInstanceIn);
        }
        EntityPotionEffectEvent event = CraftEventFactory.callEntityPotionEffectChangeEvent((LivingEntity) (Object) this, effectinstance, effectInstanceIn, cause, override);
        if (event.isCancelled()) {
            return false;
        }
        MinecraftForge.EVENT_BUS.post(new PotionEvent.PotionAddedEvent((LivingEntity) (Object) this, effectinstance, effectInstanceIn));
        if (effectinstance == null) {
            this.activePotionsMap.put(effectInstanceIn.getPotion(), effectInstanceIn);
            this.onNewPotionEffect(effectInstanceIn);
            return true;
        } else if (event.isOverride()) {
            effectinstance.combine(effectInstanceIn);
            this.onChangedPotionEffect(effectinstance, true);
            return true;
        } else {
            return false;
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) EntityPotionEffectEvent(org.bukkit.event.entity.EntityPotionEffectEvent) EffectInstance(net.minecraft.potion.EffectInstance) PotionEvent(net.minecraftforge.event.entity.living.PotionEvent) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

EntityPotionEffectEvent (org.bukkit.event.entity.EntityPotionEffectEvent)7 EffectInstance (net.minecraft.potion.EffectInstance)6 LivingEntity (net.minecraft.entity.LivingEntity)4 PotionEvent (net.minecraftforge.event.entity.living.PotionEvent)4 Overwrite (org.spongepowered.asm.mixin.Overwrite)4 Either (com.mojang.datafixers.util.Either)2 ConcurrentModificationException (java.util.ConcurrentModificationException)2 Map (java.util.Map)2 Effect (net.minecraft.potion.Effect)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 LivingEntityBridge (io.izzel.arclight.common.bridge.entity.LivingEntityBridge)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1