diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ShieldSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ShieldSpell.java index 990a95a2..c35b73a0 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ShieldSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ShieldSpell.java @@ -39,6 +39,12 @@ public class ShieldSpell extends AbstractRangedAreaSpell implements Attached { return 0x66CDAA; } + @Override + public void setDead() { + super.setDead(); + particlEffect.destroy(); + } + @Override public void render(Caster source) { float radius = (float)getDrawDropOffRange(source); diff --git a/src/main/java/com/minelittlepony/unicopia/client/particle/SphereParticle.java b/src/main/java/com/minelittlepony/unicopia/client/particle/SphereParticle.java index 10636631..02a9ba1d 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/particle/SphereParticle.java +++ b/src/main/java/com/minelittlepony/unicopia/client/particle/SphereParticle.java @@ -66,6 +66,11 @@ public class SphereParticle extends Particle implements Attachment { this.link.attach(caster); } + @Override + public void detach() { + markDead(); + } + @Override public void setAttribute(int key, Object value) { if (key == 0) { diff --git a/src/main/java/com/minelittlepony/unicopia/particle/ParticleHandle.java b/src/main/java/com/minelittlepony/unicopia/particle/ParticleHandle.java index 14d1c97c..3181de8e 100644 --- a/src/main/java/com/minelittlepony/unicopia/particle/ParticleHandle.java +++ b/src/main/java/com/minelittlepony/unicopia/particle/ParticleHandle.java @@ -4,6 +4,7 @@ import java.util.Optional; import java.util.function.Consumer; import com.minelittlepony.unicopia.ability.magic.Caster; +import com.minelittlepony.unicopia.entity.Equine; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -31,6 +32,10 @@ public class ParticleHandle { return particleEffect; } + public void destroy() { + particleEffect.ifPresent(Attachment::detach); + } + @Environment(EnvType.CLIENT) private void addParticle(ParticleEffect effect, Vec3d pos, Vec3d vel) { Particle p = MinecraftClient.getInstance().particleManager.addParticle(effect, pos.x, pos.y, pos.z, vel.x, vel.y, vel.z); @@ -46,6 +51,8 @@ public class ParticleHandle { void attach(Caster caster); + void detach(); + void setAttribute(int key, Object value); } @@ -58,7 +65,7 @@ public class ParticleHandle { public void attach(Caster caster) { this.linked = true; this.caster = Optional.of(caster); - effect = caster.getSpell(false).getName(); + this.effect = caster.getSpell(false).getName(); } public boolean linked() { @@ -69,7 +76,12 @@ public class ParticleHandle { caster = caster.filter(c -> { Entity e = c.getEntity(); - return c.hasSpell() && c.getSpell(false).getName().equals(effect) && e != null && c.getWorld().getEntityById(e.getEntityId()) != null; + + return Equine.of(e) == c + && c.hasSpell() + && c.getSpell(false).getName().equals(effect) + && e != null + && c.getWorld().getEntityById(e.getEntityId()) != null; }); if (!caster.isPresent()) { action.run();