mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 23:27:59 +01:00
Placed spells are no longer lost when the player dies
This commit is contained in:
parent
e6b0ad9fa4
commit
c27aad9154
7 changed files with 20 additions and 6 deletions
|
@ -73,6 +73,8 @@ public interface Caster<E extends LivingEntity> extends Owned<E>, Levelled, Affi
|
|||
|
||||
/**
|
||||
* Removes the desired amount of mana or health from this caster in exchange for a spell's benefits.
|
||||
* <p>
|
||||
* @return False if the transaction has depleted the caster's reserves.
|
||||
*/
|
||||
boolean subtractEnergyCost(double amount);
|
||||
|
||||
|
|
|
@ -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<T extends Spell> extends Predicate<Spell> {
|
||||
SpellPredicate<IllusionarySpell> CAN_SUPPRESS = s -> s instanceof IllusionarySpell;
|
||||
SpellPredicate<PlaceableSpell> IS_PLACED = s -> s instanceof PlaceableSpell;
|
||||
SpellPredicate<ProjectileSpell> HAS_PROJECTILE_EVENTS = s -> s instanceof ProjectileSpell;
|
||||
SpellPredicate<AbstractDisguiseSpell> IS_DISGUISE = s -> s instanceof AbstractDisguiseSpell;
|
||||
SpellPredicate<ShieldSpell> IS_SHIELD_LIKE = spell -> spell instanceof ShieldSpell;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,13 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster<Livin
|
|||
|
||||
@Override
|
||||
public boolean subtractEnergyCost(double amount) {
|
||||
return Caster.of(getMaster()).filter(c -> c.subtractEnergyCost(amount)).isPresent();
|
||||
if (getMaster() == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Caster.of(getMaster())
|
||||
.filter(c -> c.subtractEnergyCost(amount))
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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<T extends Entity> implements NbtSerialisable {
|
|||
|
||||
private boolean checkReference(Entity e) {
|
||||
pos = Optional.of(e.getPos());
|
||||
return !e.isRemoved();
|
||||
return e instanceof PlayerEntity || !e.isRemoved();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -508,7 +508,9 @@ public class Pony extends Living<PlayerEntity> 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());
|
||||
|
|
|
@ -48,6 +48,9 @@ public class NetworkedReferenceSet<T> {
|
|||
public boolean clear() {
|
||||
dirty |= !ids.isEmpty() || !values.isEmpty();
|
||||
ids.clear();
|
||||
for (NetworkedReference<T> reference : values.values()) {
|
||||
reference.updateReference(null);
|
||||
}
|
||||
values.clear();
|
||||
return dirty;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue