diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java index 52fa9381..c28e73a1 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/Caster.java @@ -73,6 +73,8 @@ public interface Caster extends Owned, Levelled, Affi /** * Removes the desired amount of mana or health from this caster in exchange for a spell's benefits. + *

+ * @return False if the transaction has depleted the caster's reserves. */ boolean subtractEnergyCost(double amount); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellPredicate.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellPredicate.java index 96d50971..304eb5b5 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellPredicate.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/SpellPredicate.java @@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.ability.magic; import java.util.function.Predicate; import com.minelittlepony.unicopia.ability.magic.spell.AbstractDisguiseSpell; +import com.minelittlepony.unicopia.ability.magic.spell.PlaceableSpell; import com.minelittlepony.unicopia.ability.magic.spell.ProjectileSpell; import com.minelittlepony.unicopia.ability.magic.spell.Spell; import com.minelittlepony.unicopia.ability.magic.spell.effect.ShieldSpell; @@ -11,6 +12,7 @@ import net.minecraft.entity.Entity; public interface SpellPredicate extends Predicate { SpellPredicate CAN_SUPPRESS = s -> s instanceof IllusionarySpell; + SpellPredicate IS_PLACED = s -> s instanceof PlaceableSpell; SpellPredicate HAS_PROJECTILE_EVENTS = s -> s instanceof ProjectileSpell; SpellPredicate IS_DISGUISE = s -> s instanceof AbstractDisguiseSpell; SpellPredicate IS_SHIELD_LIKE = spell -> spell instanceof ShieldSpell; diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java index f622cc9a..c44e5f1e 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/PlaceableSpell.java @@ -85,7 +85,7 @@ public class PlaceableSpell extends AbstractDelegatingSpell { CastSpellEntity entity = UEntities.CAST_SPELL.create(source.getWorld()); Vec3d pos = castEntity.getPosition().orElse(source.getOriginVector()); entity.updatePositionAndAngles(pos.x, pos.y, pos.z, 0, 0); - entity.getSpellSlot().put(this); + entity.getSpellSlot().put(spell.toPlaceable()); entity.setMaster(source); entity.world.spawnEntity(entity); @@ -107,8 +107,6 @@ public class PlaceableSpell extends AbstractDelegatingSpell { return super.tick(source, Situation.GROUND); } - this.onDestroyed(source); - return !isDead(); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java index d3547abc..9056aa02 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/CastSpellEntity.java @@ -104,7 +104,13 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster c.subtractEnergyCost(amount)).isPresent(); + if (getMaster() == null) { + return true; + } + + return Caster.of(getMaster()) + .filter(c -> c.subtractEnergyCost(amount)) + .isPresent(); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntityReference.java b/src/main/java/com/minelittlepony/unicopia/entity/EntityReference.java index af2cc36c..55c29d05 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntityReference.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/EntityReference.java @@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.util.NbtSerialisable; import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtElement; import net.minecraft.server.world.ServerWorld; @@ -89,7 +90,7 @@ public class EntityReference implements NbtSerialisable { private boolean checkReference(Entity e) { pos = Optional.of(e.getPos()); - return !e.isRemoved(); + return e instanceof PlayerEntity || !e.isRemoved(); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java index 8399c91c..46724e97 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -508,7 +508,9 @@ public class Pony extends Living implements Transmittable, Copieab public void copyFrom(Pony oldPlayer) { speciesPersisted = oldPlayer.speciesPersisted; if (!oldPlayer.getEntity().isRemoved()) { - getSpellSlot().put(oldPlayer.getSpellSlot().get(true).orElse(null)); + oldPlayer.getSpellSlot().stream(true).forEach(getSpellSlot()::put); + } else { + oldPlayer.getSpellSlot().stream(true).filter(SpellPredicate.IS_PLACED).forEach(getSpellSlot()::put); } oldPlayer.getSpellSlot().put(null); setSpecies(oldPlayer.getSpecies()); diff --git a/src/main/java/com/minelittlepony/unicopia/network/datasync/NetworkedReferenceSet.java b/src/main/java/com/minelittlepony/unicopia/network/datasync/NetworkedReferenceSet.java index 4da024cf..9218fdff 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/datasync/NetworkedReferenceSet.java +++ b/src/main/java/com/minelittlepony/unicopia/network/datasync/NetworkedReferenceSet.java @@ -48,6 +48,9 @@ public class NetworkedReferenceSet { public boolean clear() { dirty |= !ids.isEmpty() || !values.isEmpty(); ids.clear(); + for (NetworkedReference reference : values.values()) { + reference.updateReference(null); + } values.clear(); return dirty; }