From 0f4826e8024095660fdc2e422f662346187c3b8e Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 21 Sep 2024 21:41:04 +0100 Subject: [PATCH] Fixed disguises applied via commands not remaining when applied to a non-changeling entity --- .../ability/magic/spell/DispersableDisguiseSpell.java | 11 ++++++++++- .../unicopia/command/DisguiseCommand.java | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java index 7f614bc6..2b7f7cb8 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/DispersableDisguiseSpell.java @@ -26,11 +26,18 @@ public class DispersableDisguiseSpell extends AbstractDisguiseSpell implements I private final DataTracker.Entry suppressed = dataTracker.startTracking(TrackableDataType.BOOLEAN, false); private int suppressionCounter; + private boolean forced; + public DispersableDisguiseSpell(CustomisedSpellType type) { super(type); setHidden(true); } + public void setForced() { + forced = true; + setHidden(false); + } + @Override public boolean isVulnerable(Caster otherSource, Spell other) { return suppressionCounter <= otherSource.getLevel().get(); @@ -59,7 +66,7 @@ public class DispersableDisguiseSpell extends AbstractDisguiseSpell implements I } } - if (!source.canUse(Abilities.DISGUISE)) { + if (!forced && !source.canUse(Abilities.DISGUISE)) { setDead(); } @@ -91,12 +98,14 @@ public class DispersableDisguiseSpell extends AbstractDisguiseSpell implements I public void toNBT(NbtCompound compound) { super.toNBT(compound); compound.putInt("suppressionCounter", suppressionCounter); + compound.putBoolean("forced", forced); } @Override public void fromNBT(NbtCompound compound) { super.fromNBT(compound); suppressionCounter = compound.getInt("suppressionCounter"); + forced = compound.getBoolean("forced"); if (suppressionCounter > 0) { suppressed.set(true); } diff --git a/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java b/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java index d735c89a..5dba2c32 100644 --- a/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java +++ b/src/main/java/com/minelittlepony/unicopia/command/DisguiseCommand.java @@ -4,8 +4,10 @@ import java.util.function.Function; import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.InteractionManager; +import com.minelittlepony.unicopia.ability.Abilities; import com.minelittlepony.unicopia.ability.magic.SpellPredicate; import com.minelittlepony.unicopia.ability.magic.spell.CastingMethod; +import com.minelittlepony.unicopia.ability.magic.spell.DispersableDisguiseSpell; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.entity.player.Pony; import com.mojang.authlib.GameProfile; @@ -81,7 +83,13 @@ public class DisguiseCommand { Pony iplayer = Pony.of(player); iplayer.getSpellSlot().get(SpellType.CHANGELING_DISGUISE) - .orElseGet(() -> SpellType.CHANGELING_DISGUISE.withTraits().apply(iplayer, CastingMethod.INNATE)) + .orElseGet(() -> { + DispersableDisguiseSpell spell = SpellType.CHANGELING_DISGUISE.withTraits().apply(iplayer, CastingMethod.INNATE); + if (!iplayer.canUse(Abilities.DISGUISE)) { + spell.setForced(); + } + return spell; + }) .setDisguise(entity); if (source.getEntity() == player) {