From 9ebe391a2b3a32170d062e1e59bfcb37bd847dc7 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 30 Apr 2023 12:59:05 +0100 Subject: [PATCH] Fixed ponies without magical abilities being able to use gemstones to swap spells --- .../unicopia/entity/player/Pony.java | 16 ++++++++++++++++ .../unicopia/item/GemstoneItem.java | 4 ++++ 2 files changed, 20 insertions(+) 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 be1a02ed..eafc4ec4 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -157,6 +157,11 @@ public class Pony extends Living implements Copyable, Update respawnRace = race; } + /** + * Gets this player's species as it appears when interacting physically with other players or the world. + * This includes temporary race swaps due to illusions/shape shifting as well as artifacts that merely + * grant the abilities of a race, such as the alicorn amulet. + */ @Override public Race getSpecies() { if (AmuletSelectors.ALICORN_AMULET.test(entity)) { @@ -166,6 +171,10 @@ public class Pony extends Living implements Copyable, Update return getObservedSpecies(); } + /** + * Gets the species this player appears to be. + * This includes illusions and shape-shifting but excludes items that grant abilities without changing their race. + */ public Race getObservedSpecies() { return getSpellSlot() .get(SpellPredicate.IS_MIMIC, true) @@ -176,11 +185,18 @@ public class Pony extends Living implements Copyable, Update .orElse(getActualSpecies()); } + /** + * Gets the composite race that represents what this player is capable of. + * Physical is the race they appear to have, whilst pseudo is the race who's abilities they have been granted by magical means. + */ public Race.Composite getCompositeRace() { Race observed = getObservedSpecies(); return new Race.Composite(observed, AmuletSelectors.ALICORN_AMULET.test(entity) ? Race.ALICORN : observed); } + /** + * Gets the origin species of the player. This excludes any shapeshifting, illusions, or magic. + */ public Race getActualSpecies() { return Race.fromName(entity.getDataTracker().get(RACE), Race.HUMAN); } diff --git a/src/main/java/com/minelittlepony/unicopia/item/GemstoneItem.java b/src/main/java/com/minelittlepony/unicopia/item/GemstoneItem.java index aa0d6fde..97d75a77 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/GemstoneItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/GemstoneItem.java @@ -40,6 +40,10 @@ public class GemstoneItem extends Item implements MultiItem, EnchantableItem { ItemStack stack = user.getStackInHand(hand); PlayerCharmTracker charms = Pony.of(user).getCharms(); + if (!Pony.of(user).getObservedSpecies().canCast()) { + return result; + } + TypedActionResult> spell = EnchantableItem.consumeSpell(stack, user, ((Predicate>)charms.getEquippedSpell(hand)::equals).negate()); CustomisedSpellType existing = charms.getEquippedSpell(hand);