Fixed issues with the disguise spell

This commit is contained in:
Sollace 2021-03-07 11:04:32 +02:00
parent 63c1b4ef7f
commit 1147249059
7 changed files with 41 additions and 29 deletions

View file

@ -58,12 +58,9 @@ public class ChangelingDisguiseAbility extends ChangelingFeedAbility {
player.getEntityWorld().playSound(null, player.getBlockPos(), SoundEvents.ENTITY_PARROT_IMITATE_RAVAGER, SoundCategory.PLAYERS, 1.4F, 0.4F); player.getEntityWorld().playSound(null, player.getBlockPos(), SoundEvents.ENTITY_PARROT_IMITATE_RAVAGER, SoundCategory.PLAYERS, 1.4F, 0.4F);
iplayer.getSpellSlot().get(SpellType.DISGUISE, true).orElseGet(() -> { iplayer.getSpellSlot().get(SpellType.DISGUISE, true)
DisguiseSpell disc = SpellType.DISGUISE.create(); .orElseGet(() -> SpellType.DISGUISE.apply(iplayer))
.setDisguise(looked);
iplayer.setSpell(disc);
return disc;
}).setDisguise(looked);
if (!player.isCreative()) { if (!player.isCreative()) {
iplayer.getMagicalReserves().getMana().multiply(0.1F); iplayer.getMagicalReserves().getMana().multiply(0.1F);

View file

@ -66,7 +66,6 @@ public abstract class AbstractSpell implements Spell {
@Override @Override
public void onDestroyed(Caster<?> caster) { public void onDestroyed(Caster<?> caster) {
setDead();
} }
@Override @Override

View file

@ -44,8 +44,12 @@ public class DisguiseSpell extends AbstractSpell implements Attached, Suppressab
@Override @Override
public void onDestroyed(Caster<?> caster) { public void onDestroyed(Caster<?> caster) {
super.onDestroyed(caster);
caster.getEntity().calculateDimensions(); caster.getEntity().calculateDimensions();
caster.getEntity().setInvisible(false);
if (caster instanceof Pony) {
((Pony) caster).setInvisible(false);
}
disguise.remove();
} }
@Override @Override
@ -164,7 +168,7 @@ public class DisguiseSpell extends AbstractSpell implements Attached, Suppressab
} }
} }
return !source.getMaster().isDead(); return !isDead() && !source.getMaster().isDead();
} }
@Override @Override

View file

@ -85,7 +85,6 @@ public class NecromancySpell extends AbstractPlacedSpell {
@Override @Override
public void onDestroyed(Caster<?> caster) { public void onDestroyed(Caster<?> caster) {
super.onDestroyed(caster);
LivingEntity master = caster.getMaster(); LivingEntity master = caster.getMaster();
summonedEntities.forEach(ref -> { summonedEntities.forEach(ref -> {
ref.ifPresent(caster.getWorld(), e -> { ref.ifPresent(caster.getWorld(), e -> {

View file

@ -118,13 +118,19 @@ public final class SpellType<T extends Spell> implements Affine, SpellPredicate<
return null; return null;
} }
public boolean apply(Caster<?> caster) { @Nullable
public T apply(Caster<?> caster) {
if (isEmpty()) { if (isEmpty()) {
caster.setSpell(null); caster.setSpell(null);
return false; return null;
} }
return create().apply(caster); T spell = create();
if (spell.apply(caster)) {
return spell;
}
return null;
} }
@Override @Override
@ -162,8 +168,8 @@ public final class SpellType<T extends Spell> implements Affine, SpellPredicate<
} }
@Nullable @Nullable
public static Spell fromNBT(CompoundTag compound) { public static Spell fromNBT(@Nullable CompoundTag compound) {
if (compound.contains("effect_id")) { if (compound != null && compound.contains("effect_id")) {
Spell effect = getKey(new Identifier(compound.getString("effect_id"))).create(); Spell effect = getKey(new Identifier(compound.getString("effect_id"))).create();
if (effect != null) { if (effect != null) {

View file

@ -61,9 +61,8 @@ public class DisguiseCommand {
throw FAILED_EXCEPTION.create(); throw FAILED_EXCEPTION.create();
} }
iplayer.getSpellSlot() iplayer.getSpellSlot().get(SpellType.DISGUISE, true)
.get(SpellType.DISGUISE, true) .orElseGet(() -> SpellType.DISGUISE.apply(iplayer))
.orElseGet(SpellType.DISGUISE::create)
.setDisguise(entity); .setDisguise(entity);
if (!isSelf) { if (!isSelf) {

View file

@ -1,5 +1,6 @@
package com.minelittlepony.unicopia.network; package com.minelittlepony.unicopia.network;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -12,7 +13,6 @@ import com.minelittlepony.unicopia.ability.magic.spell.SpellType;
import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedData;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.util.Identifier;
/** /**
* Synchronisation class for spells. * Synchronisation class for spells.
@ -66,31 +66,39 @@ public class EffectSync implements SpellContainer {
Spell effect = spell.orElse(null); Spell effect = spell.orElse(null);
if (comp == null || !comp.contains("effect_id")) { if (comp == null || !comp.contains("effect_id") || !comp.contains("uuid")) {
updateReference(null); if (effect != null) {
} else if (!checkReference() || !effect.getType().getId().equals(new Identifier(comp.getString("effect_id")))) { updateReference(null);
}
} else if (effect == null || !effect.getUuid().equals(comp.getUuid("uuid"))) {
updateReference(SpellType.fromNBT(comp)); updateReference(SpellType.fromNBT(comp));
} else if (owner.getEntity().world.isClient()) { } else if (owner.isClient()) {
if (lastValue != comp || !(comp == null || comp.equals(lastValue))) { if (!Objects.equals(lastValue, comp)) {
lastValue = comp; lastValue = comp;
effect.fromNBT(comp); effect.fromNBT(comp);
} }
} else if ((force || !owner.isClient()) && effect.isDirty()) { } else if (force && effect.isDirty()) {
put(effect); put(effect);
} }
} }
@Override @Override
public void put(@Nullable Spell effect) { public void put(@Nullable Spell effect) {
effect = effect == null || effect.isDead() ? null : effect;
updateReference(effect); updateReference(effect);
owner.getEntity().getDataTracker().set(param, effect == null ? new CompoundTag() : SpellType.toNBT(effect)); owner.getEntity().getDataTracker().set(param, effect == null ? new CompoundTag() : SpellType.toNBT(effect));
} }
private void updateReference(@Nullable Spell effect) { private void updateReference(@Nullable Spell effect) {
if (spell.isPresent() && spell.get() != effect) { @Nullable
spell.get().setDead(); Spell old = spell.orElse(null);
spell.get().onDestroyed(owner); if (old != effect) {
spell = Optional.ofNullable(effect);
if (old != null && (effect == null || !old.getUuid().equals(effect.getUuid()))) {
old.setDead();
old.onDestroyed(owner);
}
} }
spell = Optional.ofNullable(effect);
} }
} }