diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlacementControlSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlacementControlSpell.java index 9eee830f..339deac6 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlacementControlSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlacementControlSpell.java @@ -77,39 +77,38 @@ public class PlacementControlSpell extends AbstractSpell implements OrientedSpel @Override public boolean apply(Caster caster) { - if (delegate == null) { - return false; - } - boolean result = super.apply(caster); - if (result) { - if (dimension.isEmpty()) { - setDimension(caster.asWorld().getRegistryKey()); - } - if (position.isEmpty()) { - setPosition(caster.asEntity().getPos()); - } - if (delegate instanceof PlacementDelegate) { - ((PlacementDelegate)delegate).onPlaced(caster, this); - } - - CastSpellEntity entity = new CastSpellEntity(caster.asWorld(), caster, this); - - Vec3d pos = position.get(); - Vec3d rot = orientation.orElse(Vec3d.ZERO); - - entity.updatePositionAndAngles(pos.x, pos.y, pos.z, (float)rot.y, (float)rot.x); - entity.getWorld().spawnEntity(entity); - - placedEntityId = entity.getUuid(); - } - return result; + return delegate != null && super.apply(caster); } @Override public boolean tick(Caster source, Situation situation) { - if (!source.isClient() && getConnection(source) == null) { - setDead(); + if (!source.isClient()) { + + if (placedEntityId == null) { + if (dimension.isEmpty()) { + setDimension(source.asWorld().getRegistryKey()); + } + if (position.isEmpty()) { + setPosition(source.asEntity().getPos()); + } + System.out.println("Creating placed spell"); + CastSpellEntity entity = new CastSpellEntity(source.asWorld(), source, this); + + Vec3d pos = position.get(); + Vec3d rot = orientation.orElse(Vec3d.ZERO); + + entity.updatePositionAndAngles(pos.x, pos.y, pos.z, (float)rot.y, (float)rot.x); + entity.getWorld().spawnEntity(entity); + + placedEntityId = entity.getUuid(); + setDirty(); + } else { + if (getConnection(source) == null) { + setDead(); + } + } } + return !isDead(); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisplacementSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisplacementSpell.java index 1afef18f..974da9de 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisplacementSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/DisplacementSpell.java @@ -18,13 +18,13 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.math.Vec3d; -public class DisplacementSpell extends AbstractSpell implements HomingSpell, ProjectileDelegate.EntityHitListener { +public class DisplacementSpell extends AbstractSpell implements HomingSpell, ProjectileDelegate.HitListener { private static final SpellAttribute DAMAGE_TO_TARGET = SpellAttribute.create(SpellAttributeType.DAMAGE_TO_TARGET, AttributeFormat.REGULAR, AttributeFormat.PERCENTAGE, Trait.BLOOD, blood -> blood); static final TooltipFactory TOOLTIP = DAMAGE_TO_TARGET; - private final EntityReference target = new EntityReference<>(); + private final EntityReference target = dataTracker.startTracking(new EntityReference<>()); private int ticks = 10; @@ -34,7 +34,7 @@ public class DisplacementSpell extends AbstractSpell implements HomingSpell, Pro @Override public Spell prepareForCast(Caster caster, CastingMethod method) { - return toPlaceable(); + return method.isIndirectCause() ? this : toPlaceable(); } @Override @@ -43,14 +43,23 @@ public class DisplacementSpell extends AbstractSpell implements HomingSpell, Pro originator.asEntity().setGlowing(true); + if (situation == Situation.PROJECTILE) { + return !isDead(); + } + ticks--; if (originator.isClient()) { return !isDead() || ticks >= -10; } - if (ticks == 0) { - target.ifPresent(originator.asWorld(), target -> apply(originator, target)); + if (!originator.isClient()) { + target.ifPresent(originator.asWorld(), target -> { + target.setGlowing(true); + if (ticks == 0) { + apply(originator, target); + } + }); } return ticks >= -10; @@ -58,7 +67,18 @@ public class DisplacementSpell extends AbstractSpell implements HomingSpell, Pro @Override public void onImpact(MagicProjectileEntity projectile, EntityHitResult hit) { - Caster.of(projectile.getMaster()).ifPresent(originator -> apply(originator, hit.getEntity())); + HitListener.super.onImpact(projectile, hit); + Caster.of(projectile.getMaster()).ifPresent(originator -> { + apply(originator, hit.getEntity()); + }); + } + + @Override + public void onImpact(MagicProjectileEntity projectile) { + if (projectile.getMaster() instanceof Entity owner) { + owner.setGlowing(false); + } + target.ifPresent(projectile.asWorld(), e -> e.setGlowing(false)); } private void apply(Caster originator, Entity target) { @@ -107,11 +127,13 @@ public class DisplacementSpell extends AbstractSpell implements HomingSpell, Pro public void toNBT(NbtCompound compound) { super.toNBT(compound); compound.putInt("ticks", ticks); + compound.put("target", target.toNBT()); } @Override public void fromNBT(NbtCompound compound) { super.fromNBT(compound); ticks = compound.getInt("ticks"); + target.fromNBT(compound.getCompound("target")); } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java index fbca955c..34216ea4 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java @@ -11,6 +11,7 @@ import com.minelittlepony.unicopia.ability.magic.SpellSlots; import com.minelittlepony.unicopia.ability.magic.spell.PlacementControlSpell; import com.minelittlepony.unicopia.ability.magic.spell.Situation; import com.minelittlepony.unicopia.ability.magic.spell.Spell; +import com.minelittlepony.unicopia.ability.magic.spell.PlacementControlSpell.PlacementDelegate; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.entity.EntityPhysics; import com.minelittlepony.unicopia.entity.EntityReference; @@ -70,8 +71,12 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster type, World world) {