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