use of org.bukkit.craftbukkit.v.entity.CraftLivingEntity in project Arclight by IzzelAliz.
the class AreaEffectCloudEntityMixin method tick.
// @formatter:on
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void tick() {
super.tick();
boolean flag = this.shouldIgnoreRadius();
float f = this.getRadius();
if (this.world.isRemote) {
IParticleData iparticledata = this.getParticleData();
if (flag) {
if (this.rand.nextBoolean()) {
for (int i = 0; i < 2; ++i) {
float f1 = this.rand.nextFloat() * ((float) Math.PI * 2F);
float f2 = MathHelper.sqrt(this.rand.nextFloat()) * 0.2F;
float f3 = MathHelper.cos(f1) * f2;
float f4 = MathHelper.sin(f1) * f2;
if (iparticledata.getType() == ParticleTypes.ENTITY_EFFECT) {
int j = this.rand.nextBoolean() ? 16777215 : this.getColor();
int k = j >> 16 & 255;
int l = j >> 8 & 255;
int i1 = j & 255;
this.world.addOptionalParticle(iparticledata, this.posX + (double) f3, this.posY, this.posZ + (double) f4, (double) ((float) k / 255.0F), (double) ((float) l / 255.0F), (double) ((float) i1 / 255.0F));
} else {
this.world.addOptionalParticle(iparticledata, this.posX + (double) f3, this.posY, this.posZ + (double) f4, 0.0D, 0.0D, 0.0D);
}
}
}
} else {
float f5 = (float) Math.PI * f * f;
for (int k1 = 0; (float) k1 < f5; ++k1) {
float f6 = this.rand.nextFloat() * ((float) Math.PI * 2F);
float f7 = MathHelper.sqrt(this.rand.nextFloat()) * f;
float f8 = MathHelper.cos(f6) * f7;
float f9 = MathHelper.sin(f6) * f7;
if (iparticledata.getType() == ParticleTypes.ENTITY_EFFECT) {
int l1 = this.getColor();
int i2 = l1 >> 16 & 255;
int j2 = l1 >> 8 & 255;
int j1 = l1 & 255;
this.world.addOptionalParticle(iparticledata, this.posX + (double) f8, this.posY, this.posZ + (double) f9, (double) ((float) i2 / 255.0F), (double) ((float) j2 / 255.0F), (double) ((float) j1 / 255.0F));
} else {
this.world.addOptionalParticle(iparticledata, this.posX + (double) f8, this.posY, this.posZ + (double) f9, (0.5D - this.rand.nextDouble()) * 0.15D, (double) 0.01F, (0.5D - this.rand.nextDouble()) * 0.15D);
}
}
}
} else {
if (this.ticksExisted >= this.waitTime + this.duration) {
this.remove();
return;
}
boolean flag1 = this.ticksExisted < this.waitTime;
if (flag != flag1) {
this.setIgnoreRadius(flag1);
}
if (flag1) {
return;
}
if (this.radiusPerTick != 0.0F) {
f += this.radiusPerTick;
if (f < 0.5F) {
this.remove();
return;
}
this.setRadius(f);
}
if (this.ticksExisted % 5 == 0) {
Iterator<Map.Entry<Entity, Integer>> iterator = this.reapplicationDelayMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Entity, Integer> entry = iterator.next();
if (this.ticksExisted >= entry.getValue()) {
iterator.remove();
}
}
List<EffectInstance> effects = Lists.newArrayList();
for (EffectInstance effectinstance1 : this.potion.getEffects()) {
effects.add(new EffectInstance(effectinstance1.getPotion(), effectinstance1.getDuration() / 4, effectinstance1.getAmplifier(), effectinstance1.isAmbient(), effectinstance1.doesShowParticles()));
}
effects.addAll(this.effects);
if (effects.isEmpty()) {
this.reapplicationDelayMap.clear();
} else {
List<LivingEntity> list = this.world.getEntitiesWithinAABB(LivingEntity.class, this.getBoundingBox());
if (!list.isEmpty()) {
List<LivingEntity> entities = new java.util.ArrayList<>();
for (LivingEntity livingentity : list) {
if (!this.reapplicationDelayMap.containsKey(livingentity) && livingentity.canBeHitWithPotion()) {
double d0 = livingentity.posX - this.posX;
double d1 = livingentity.posZ - this.posZ;
double d2 = d0 * d0 + d1 * d1;
if (d2 <= (double) (f * f)) {
entities.add(livingentity);
}
}
}
AreaEffectCloudApplyEvent event = CraftEventFactory.callAreaEffectCloudApplyEvent((AreaEffectCloudEntity) (Object) this, Lists.transform(entities, living -> ((LivingEntityBridge) living).bridge$getBukkitEntity()));
if (!event.isCancelled()) {
for (org.bukkit.entity.LivingEntity entity : event.getAffectedEntities()) {
if (entity instanceof CraftLivingEntity) {
LivingEntity livingentity = ((CraftLivingEntity) entity).getHandle();
this.reapplicationDelayMap.put(livingentity, this.ticksExisted + this.reapplicationDelay);
for (EffectInstance effectinstance : effects) {
if (effectinstance.getPotion().isInstant()) {
effectinstance.getPotion().affectEntity((AreaEffectCloudEntity) (Object) this, this.getOwner(), livingentity, effectinstance.getAmplifier(), 0.5D);
} else {
((LivingEntityBridge) livingentity).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.AREA_EFFECT_CLOUD);
livingentity.addPotionEffect(new EffectInstance(effectinstance));
}
}
if (this.radiusOnUse != 0.0F) {
f += this.radiusOnUse;
if (f < 0.5F) {
this.remove();
return;
}
this.setRadius(f);
}
if (this.durationOnUse != 0) {
this.duration += this.durationOnUse;
if (this.duration <= 0) {
this.remove();
return;
}
}
}
}
}
}
}
}
}
}
use of org.bukkit.craftbukkit.v.entity.CraftLivingEntity in project Arclight by IzzelAliz.
the class ArclightEventFactory method callEntityDeathEvent.
public static void callEntityDeathEvent(LivingEntity entity, List<ItemStack> drops) {
CraftLivingEntity craftLivingEntity = ((LivingEntityBridge) entity).bridge$getBukkitEntity();
EntityDeathEvent event = new EntityDeathEvent(craftLivingEntity, drops, ((LivingEntityBridge) entity).bridge$getExpReward());
callEvent(event);
((LivingEntityBridge) entity).bridge$setExpToDrop(event.getDroppedExp());
}
use of org.bukkit.craftbukkit.v.entity.CraftLivingEntity in project Arclight by IzzelAliz.
the class PotionEntityMixin method func_213888_a.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
private void func_213888_a(List<EffectInstance> list, @Nullable Entity entity) {
AxisAlignedBB axisalignedbb = this.getBoundingBox().grow(4.0, 2.0, 4.0);
List<LivingEntity> list2 = this.world.getEntitiesWithinAABB(LivingEntity.class, axisalignedbb);
Map<org.bukkit.entity.LivingEntity, Double> affected = new HashMap<>();
if (!list2.isEmpty()) {
for (LivingEntity entityliving : list2) {
if (entityliving.canBeHitWithPotion()) {
double d0 = this.getDistanceSq(entityliving);
if (d0 >= 16.0) {
continue;
}
double d2 = 1.0 - Math.sqrt(d0) / 4.0;
if (entityliving == entity) {
d2 = 1.0;
}
affected.put(((LivingEntityBridge) entityliving).bridge$getBukkitEntity(), d2);
}
}
}
PotionSplashEvent event = CraftEventFactory.callPotionSplashEvent((PotionEntity) (Object) this, affected);
if (!event.isCancelled() && list != null && !list.isEmpty()) {
for (org.bukkit.entity.LivingEntity victim : event.getAffectedEntities()) {
if (!(victim instanceof CraftLivingEntity)) {
continue;
}
LivingEntity entityliving2 = ((CraftLivingEntity) victim).getHandle();
double d2 = event.getIntensity(victim);
for (EffectInstance mobeffect : list) {
Effect mobeffectlist = mobeffect.getPotion();
if (!((WorldBridge) this.world).bridge$isPvpMode() && this.getThrower() instanceof ServerPlayerEntity && entityliving2 instanceof ServerPlayerEntity && entityliving2 != this.getThrower()) {
int i = Effect.getId(mobeffectlist);
if (i == 2 || i == 4 || i == 7 || i == 15 || i == 17 || i == 18) {
continue;
}
if (i == 19) {
continue;
}
}
if (mobeffectlist.isInstant()) {
mobeffectlist.affectEntity((PotionEntity) (Object) this, this.getThrower(), entityliving2, mobeffect.getAmplifier(), d2);
} else {
int i = (int) (d2 * mobeffect.getDuration() + 0.5);
if (i <= 20) {
continue;
}
((LivingEntityBridge) entityliving2).bridge$pushEffectCause(EntityPotionEffectEvent.Cause.POTION_SPLASH);
entityliving2.addPotionEffect(new EffectInstance(mobeffectlist, i, mobeffect.getAmplifier(), mobeffect.isAmbient(), mobeffect.doesShowParticles()));
}
}
}
}
}
use of org.bukkit.craftbukkit.v.entity.CraftLivingEntity in project Arclight by IzzelAliz.
the class MobEntityMixin method setAttackTarget.
/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public void setAttackTarget(@Nullable LivingEntity livingEntity) {
boolean fireEvent = arclight$fireEvent;
arclight$fireEvent = false;
EntityTargetEvent.TargetReason reason = arclight$reason == null ? EntityTargetEvent.TargetReason.UNKNOWN : arclight$reason;
arclight$reason = null;
if (fireEvent) {
if (reason == EntityTargetEvent.TargetReason.UNKNOWN && this.getAttackTarget() != null && livingEntity == null) {
reason = (this.getAttackTarget().isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED);
}
if (reason == EntityTargetEvent.TargetReason.UNKNOWN) {
ArclightMod.LOGGER.log(Level.WARN, "Unknown target reason, please report on the issue tracker", new Exception());
}
CraftLivingEntity ctarget = null;
if (livingEntity != null) {
ctarget = ((LivingEntityBridge) livingEntity).bridge$getBukkitEntity();
}
final EntityTargetLivingEntityEvent event = new EntityTargetLivingEntityEvent(this.getBukkitEntity(), ctarget, reason);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
if (arclight$targetSuccess != null)
arclight$targetSuccess.set(false);
return;
}
if (event.getTarget() != null) {
livingEntity = ((CraftLivingEntity) event.getTarget()).getHandle();
} else {
livingEntity = null;
}
}
this.attackTarget = livingEntity;
ForgeHooks.onLivingSetAttackTarget((MobEntity) (Object) this, this.attackTarget);
if (arclight$targetSuccess != null)
arclight$targetSuccess.set(true);
}
use of org.bukkit.craftbukkit.v.entity.CraftLivingEntity in project Arclight by IzzelAliz.
the class ExperienceOrbEntityMixin method arclight$targetPlayer.
@Redirect(method = "tick", at = @At(value = "FIELD", ordinal = 6, target = "Lnet/minecraft/entity/item/ExperienceOrbEntity;closestPlayer:Lnet/minecraft/entity/player/PlayerEntity;"))
private PlayerEntity arclight$targetPlayer(ExperienceOrbEntity entity) {
if (this.closestPlayer != arclight$lastPlayer) {
EntityTargetLivingEntityEvent event = CraftEventFactory.callEntityTargetLivingEvent((ExperienceOrbEntity) (Object) this, this.closestPlayer, (this.closestPlayer != null) ? EntityTargetEvent.TargetReason.CLOSEST_PLAYER : EntityTargetEvent.TargetReason.FORGOT_TARGET);
LivingEntity target = (event.getTarget() == null) ? null : ((CraftLivingEntity) event.getTarget()).getHandle();
if (event.isCancelled()) {
this.closestPlayer = arclight$lastPlayer;
return null;
} else {
this.closestPlayer = (target instanceof PlayerEntity) ? (PlayerEntity) target : null;
}
}
return this.closestPlayer;
}
Aggregations