diff --git a/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java index d7e262b8..059b7575 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/UnicornCastingAbility.java @@ -103,7 +103,7 @@ public class UnicornCastingAbility extends AbstractSpellCastingAbility { }, true); player.subtractEnergyCost(removed ? 2 : 4); if (!removed) { - Spell s = spell.apply(player, CastingMethod.GEM); + Spell s = spell.apply(player, CastingMethod.DIRECT); if (s == null) { player.spawnParticles(ParticleTypes.LARGE_SMOKE, 6); player.playSound(USounds.SPELL_CAST_FAIL, 1, 0.5F); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/CastingMethod.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/CastingMethod.java index b67a1493..6a035a14 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/CastingMethod.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/CastingMethod.java @@ -4,15 +4,15 @@ public enum CastingMethod { /** * Casting from a gem or a unicorn's equipped spell. */ - GEM, + DIRECT, /** * Casting a projectile form from a gem or unicorn's equipped spell */ - GEM_PROJECTILE, + STORED, /** * Result of a projectile impact */ - PROJECTILE, + INDIRECT, /** * Casting from a magic staff */ @@ -20,5 +20,21 @@ public enum CastingMethod { /** * Result of an entities innate ability */ - INNATE + INNATE; + + public boolean isIndirectCause() { + return this == STAFF || this == STORED; + } + + public boolean isIndirectEffect() { + return this == INDIRECT; + } + + public boolean isDirect() { + return this == DIRECT || this == INNATE; + } + + public boolean isTool() { + return this == STAFF; + } } \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ThrowableSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ThrowableSpell.java index 80687e59..45dcc246 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ThrowableSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ThrowableSpell.java @@ -64,7 +64,7 @@ public final class ThrowableSpell extends AbstractDelegatingSpell { projectile.setPosition(entity.getX(), entity.getEyeY() - 0.1F, entity.getZ()); projectile.setOwner(entity); projectile.setItem(UItems.GEMSTONE.getDefaultStack(spell.getType())); - spell.prepareForCast(caster, CastingMethod.PROJECTILE).apply(projectile); + spell.prepareForCast(caster, CastingMethod.STORED).apply(projectile); projectile.setVelocity(entity, entity.getPitch(), entity.getYaw(), 0, 1.5F, divergance); projectile.setNoGravity(true); configureProjectile(projectile, caster); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractiveSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractiveSpell.java index 0f857102..e1d05b04 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractiveSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractiveSpell.java @@ -146,7 +146,7 @@ public class AttractiveSpell extends ShieldSpell implements HomingSpell, TimedSp public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) { if (!isDead() && getTraits().get(Trait.CHAOS) > 0) { setDead(); - Caster.of(hit.getEntity()).ifPresent(caster -> getTypeAndTraits().apply(caster, CastingMethod.PROJECTILE)); + Caster.of(hit.getEntity()).ifPresent(caster -> getTypeAndTraits().apply(caster, CastingMethod.INDIRECT)); } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/BubbleSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/BubbleSpell.java index b64ed22f..259bee40 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/BubbleSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/BubbleSpell.java @@ -153,7 +153,7 @@ public class BubbleSpell extends AbstractSpell implements TimedSpell, @Override public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) { Caster.of(hit.getEntity()).ifPresent(caster -> { - getTypeAndTraits().apply(caster, CastingMethod.PROJECTILE); + getTypeAndTraits().apply(caster, CastingMethod.INDIRECT); }); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java index 400e9af6..8fd95e67 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/LightSpell.java @@ -86,7 +86,7 @@ public class LightSpell extends AbstractSpell implements TimedSpell, ProjectileD @Override public void onImpact(MagicProjectileEntity projectile) { - Caster.of(projectile.getMaster()).ifPresent(caster -> getTypeAndTraits().apply(caster, CastingMethod.PROJECTILE)); + Caster.of(projectile.getMaster()).ifPresent(caster -> getTypeAndTraits().apply(caster, CastingMethod.INDIRECT)); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java index 14fbb580..faa7df4f 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java @@ -5,17 +5,22 @@ import java.util.Optional; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.CastingMethod; +import com.minelittlepony.unicopia.ability.magic.spell.HomingSpell; import com.minelittlepony.unicopia.ability.magic.spell.Situation; +import com.minelittlepony.unicopia.ability.magic.spell.Spell; import com.minelittlepony.unicopia.entity.EntityReference; import com.minelittlepony.unicopia.entity.behaviour.EntitySwap; import com.minelittlepony.unicopia.entity.behaviour.Inventory; +import com.minelittlepony.unicopia.projectile.MagicProjectileEntity; +import com.minelittlepony.unicopia.projectile.ProjectileDelegate; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; +import net.minecraft.util.hit.EntityHitResult; -public class MindSwapSpell extends MimicSpell { +public class MindSwapSpell extends MimicSpell implements ProjectileDelegate.EntityHitListener { private final EntityReference counterpart = new EntityReference<>(); @@ -28,6 +33,10 @@ public class MindSwapSpell extends MimicSpell { super(type); } + @Override + public Spell prepareForCast(Caster caster, CastingMethod method) { + return method == CastingMethod.STAFF ? toThrowable() : this; + } @Override public void onDestroyed(Caster caster) { @@ -57,6 +66,10 @@ public class MindSwapSpell extends MimicSpell { @Override public boolean tick(Caster caster, Situation situation) { + if (situation != Situation.BODY) { + return true; + } + if (!caster.isClient()) { if (!initialized) { initialized = true; @@ -66,7 +79,7 @@ public class MindSwapSpell extends MimicSpell { setDisguise(e); Caster other = Caster.of(e).get(); - SpellType.MIMIC.withTraits().apply(other, CastingMethod.PROJECTILE).setDisguise(master); + SpellType.MIMIC.withTraits().apply(other, CastingMethod.INDIRECT).setDisguise(master); EntitySwap.ALL.accept(master, e); Inventory.swapInventories( @@ -100,6 +113,16 @@ public class MindSwapSpell extends MimicSpell { return super.tick(caster, situation); } + + @Override + public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) { + Caster.of(projectile.getMaster()).ifPresent(master -> { + if (getTypeAndTraits().apply(master, CastingMethod.DIRECT) instanceof HomingSpell homing) { + homing.setTarget(hit.getEntity()); + } + }); + } + @Override public boolean setTarget(Entity target) { if (target instanceof LivingEntity living && Caster.of(target).isPresent()) { diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/NecromancySpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/NecromancySpell.java index 79903e19..04abf759 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/NecromancySpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/NecromancySpell.java @@ -7,9 +7,7 @@ import java.util.function.Supplier; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.AbstractAreaEffectSpell; -import com.minelittlepony.unicopia.ability.magic.spell.CastingMethod; import com.minelittlepony.unicopia.ability.magic.spell.Situation; -import com.minelittlepony.unicopia.ability.magic.spell.Spell; import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait; import com.minelittlepony.unicopia.entity.Creature; import com.minelittlepony.unicopia.entity.EntityReference; @@ -88,11 +86,6 @@ public class NecromancySpell extends AbstractAreaEffectSpell implements Projecti super(type); } - @Override - public Spell prepareForCast(Caster caster, CastingMethod method) { - return method == CastingMethod.GEM ? toPlaceable() : super.prepareForCast(caster, method); - } - @Override public boolean tick(Caster source, Situation situation) {