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);
iplayer.getSpellSlot().get(SpellType.DISGUISE, true).orElseGet(() -> {
DisguiseSpell disc = SpellType.DISGUISE.create();
iplayer.setSpell(disc);
return disc;
}).setDisguise(looked);
iplayer.getSpellSlot().get(SpellType.DISGUISE, true)
.orElseGet(() -> SpellType.DISGUISE.apply(iplayer))
.setDisguise(looked);
if (!player.isCreative()) {
iplayer.getMagicalReserves().getMana().multiply(0.1F);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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