From 575e54885dbc73f13ea0e895fed0584ef87f704f Mon Sep 17 00:00:00 2001 From: WinDanesz <31292708+windanesz@users.noreply.github.com> Date: Fri, 7 Jun 2024 23:52:57 +0200 Subject: [PATCH] fix: Fix crash with NPCs drinking potions. Fixes https://github.com/WinDanesz/ArcaneApprentices/issues/21 --- .../mixin/modrefs/HandleDiffuserRef.java | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/windanesz/ancientspellcraft/mixin/modrefs/HandleDiffuserRef.java b/src/main/java/com/windanesz/ancientspellcraft/mixin/modrefs/HandleDiffuserRef.java index 1e3b6c11..f5a0c8ab 100644 --- a/src/main/java/com/windanesz/ancientspellcraft/mixin/modrefs/HandleDiffuserRef.java +++ b/src/main/java/com/windanesz/ancientspellcraft/mixin/modrefs/HandleDiffuserRef.java @@ -18,31 +18,34 @@ public class HandleDiffuserRef { public static void diffuser(ItemStack stack, World world, EntityLivingBase entityLiving) { - EntityPlayer player = (EntityPlayer) entityLiving; - if (ItemArtefact.isArtefactActive(player, ASItems.charm_arcane_diffuser)) { - List entities = EntityUtils.getEntitiesWithinRadius(7, player.posX, player.posY, player.posZ, world, EntityLivingBase.class); - entities.removeIf(e -> !AllyDesignationSystem.isAllied(player, e)); - entities.removeIf(e -> e == player); + if (entityLiving instanceof EntityPlayer) { - for (PotionEffect potioneffect : PotionUtils.getEffectsFromStack(stack)) { - for (EntityLivingBase entity : entities) { - if (potioneffect.getPotion().isInstant()) { - potioneffect.getPotion().affectEntity(entity, player, entity, potioneffect.getAmplifier(), 0.3D); - } else { - entity.addPotionEffect(new PotionEffect(potioneffect.getPotion(), (int) (potioneffect.getDuration() * 0.3f), potioneffect.getAmplifier())); + EntityPlayer player = (EntityPlayer) entityLiving; + if (ItemArtefact.isArtefactActive(player, ASItems.charm_arcane_diffuser)) { + List entities = EntityUtils.getEntitiesWithinRadius(7, player.posX, player.posY, player.posZ, world, EntityLivingBase.class); + entities.removeIf(e -> !AllyDesignationSystem.isAllied(player, e)); + entities.removeIf(e -> e == player); + + for (PotionEffect potioneffect : PotionUtils.getEffectsFromStack(stack)) { + for (EntityLivingBase entity : entities) { + if (potioneffect.getPotion().isInstant()) { + potioneffect.getPotion().affectEntity(entity, player, entity, potioneffect.getAmplifier(), 0.3D); + } else { + entity.addPotionEffect(new PotionEffect(potioneffect.getPotion(), (int) (potioneffect.getDuration() * 0.3f), potioneffect.getAmplifier())); + } } } - } - if (world.isRemote) { - Vec3d origin = player.getPositionVector(); - for (int i = 0; (float) i < 40.0F; ++i) { - double particleX = origin.x - 1.0 + 2.0 * world.rand.nextDouble(); - double particleZ = origin.z - 1.0 + 2.0 * world.rand.nextDouble(); - ParticleBuilder.create(ParticleBuilder.Type.DARK_MAGIC).pos(particleX, origin.y + 0.5, particleZ).vel(particleX - origin.x, 0.0, particleZ - origin.z).clr(0xad73bd).spawn(world); - particleX = origin.x - 1.0 + 2.0 * world.rand.nextDouble(); - particleZ = origin.z - 1.0 + 2.0 * world.rand.nextDouble(); - ParticleBuilder.create(ParticleBuilder.Type.SPARKLE).pos(particleX, origin.y + 0.5, particleZ).vel(particleX - origin.x, 0.0, particleZ - origin.z).time(30).clr(0xa522c9).spawn(world); + if (world.isRemote) { + Vec3d origin = player.getPositionVector(); + for (int i = 0; (float) i < 40.0F; ++i) { + double particleX = origin.x - 1.0 + 2.0 * world.rand.nextDouble(); + double particleZ = origin.z - 1.0 + 2.0 * world.rand.nextDouble(); + ParticleBuilder.create(ParticleBuilder.Type.DARK_MAGIC).pos(particleX, origin.y + 0.5, particleZ).vel(particleX - origin.x, 0.0, particleZ - origin.z).clr(0xad73bd).spawn(world); + particleX = origin.x - 1.0 + 2.0 * world.rand.nextDouble(); + particleZ = origin.z - 1.0 + 2.0 * world.rand.nextDouble(); + ParticleBuilder.create(ParticleBuilder.Type.SPARKLE).pos(particleX, origin.y + 0.5, particleZ).vel(particleX - origin.x, 0.0, particleZ - origin.z).time(30).clr(0xa522c9).spawn(world); + } } } }