From 76a7ecc3bbbd998e95960cef6effd8a575c15833 Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 1 Sep 2023 19:09:13 +0100 Subject: [PATCH] Fixed certain race buffs and checks not accounting for worn amulets (or failing if wearing an amulet) --- .../unicopia/EquinePredicates.java | 9 +-- .../com/minelittlepony/unicopia/Race.java | 18 ++++++ .../com/minelittlepony/unicopia/Unicopia.java | 4 +- .../unicopia/ability/AbilityDispatcher.java | 5 +- .../ability/EarthPonyStompAbility.java | 2 +- .../ability/PegasusFlightToggleAbility.java | 2 +- .../magic/spell/effect/AttractionUtils.java | 4 +- .../magic/spell/effect/SiphoningSpell.java | 2 +- .../advancement/CustomEventCriterion.java | 2 +- .../advancement/RaceChangeCriterion.java | 2 +- .../block/BaseZapAppleLeavesBlock.java | 2 +- .../unicopia/block/ZapAppleLogBlock.java | 2 +- .../unicopia/block/ZapBlock.java | 2 +- .../client/gui/spellbook/ProfileTooltip.java | 22 -------- .../SpellbookProfilePageContent.java | 18 ++++-- .../unicopia/command/SpeciesCommand.java | 2 +- .../unicopia/entity/Equine.java | 4 ++ .../entity/effect/RaceChangeStatusEffect.java | 2 +- .../unicopia/entity/player/ManaContainer.java | 4 +- .../entity/player/PlayerAttributes.java | 23 ++++---- .../unicopia/entity/player/PlayerPhysics.java | 4 +- .../unicopia/entity/player/Pony.java | 55 ++++++------------- .../unicopia/item/BellItem.java | 2 +- .../unicopia/item/CrystalHeartItem.java | 2 +- .../item/enchantment/EnchantmentUtil.java | 2 +- .../unicopia/mixin/MixinDamageSource.java | 4 +- .../unicopia/mixin/MixinPowderSnowBlock.java | 3 +- .../mixin/MixinServerPlayerEntity.java | 2 +- .../unicopia/network/Channel.java | 2 +- .../network/MsgRequestSpeciesChange.java | 4 +- .../server/world/NocturnalSleepManager.java | 4 +- .../unicopia/util/MagicalDamageSource.java | 3 +- 32 files changed, 104 insertions(+), 114 deletions(-) delete mode 100644 src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/ProfileTooltip.java diff --git a/src/main/java/com/minelittlepony/unicopia/EquinePredicates.java b/src/main/java/com/minelittlepony/unicopia/EquinePredicates.java index 30e2c015..a1c38c95 100644 --- a/src/main/java/com/minelittlepony/unicopia/EquinePredicates.java +++ b/src/main/java/com/minelittlepony/unicopia/EquinePredicates.java @@ -5,7 +5,6 @@ import java.util.function.Predicate; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.entity.Equine; import com.minelittlepony.unicopia.entity.MagicImmune; -import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.item.enchantment.UEnchantments; import net.minecraft.enchantment.EnchantmentHelper; @@ -16,11 +15,13 @@ import net.minecraft.predicate.entity.EntityPredicates; public interface EquinePredicates { Predicate IS_PLAYER = e -> e instanceof PlayerEntity; + Predicate BAT = physicalRaceMatches(Race.BAT::equals); + Predicate CHANGELING = physicalRaceMatches(Race.CHANGELING::equals); Predicate RACE_INTERACT_WITH_CLOUDS = raceMatches(Race::canInteractWithClouds); Predicate PLAYER_EARTH = IS_PLAYER.and(ofRace(Race.EARTH)); - Predicate PLAYER_BAT = IS_PLAYER.and(ofRace(Race.BAT)).or(physicalRaceMatches(Race.BAT::equals)); + Predicate PLAYER_BAT = IS_PLAYER.and(BAT); Predicate PLAYER_UNICORN = IS_PLAYER.and(raceMatches(Race::canCast)); Predicate PLAYER_CHANGELING = IS_PLAYER.and(ofRace(Race.CHANGELING)); Predicate PLAYER_PEGASUS = IS_PLAYER.and(e -> ((PlayerEntity)e).getAbilities().creativeMode || RACE_INTERACT_WITH_CLOUDS.test(e)); @@ -45,10 +46,10 @@ public interface EquinePredicates { } static Predicate raceMatches(Predicate predicate) { - return e -> Equine.of(e).map(Equine::getSpecies).filter(predicate).isPresent(); + return e -> Equine.of(e).filter(pony -> pony.getCompositeRace().any(predicate)).isPresent(); } static Predicate physicalRaceMatches(Predicate predicate) { - return e -> Pony.of(e).map(Pony::getActualSpecies).filter(predicate).isPresent(); + return e -> Equine.of(e).filter(pony -> predicate.test(pony.getCompositeRace().physical())).isPresent(); } } diff --git a/src/main/java/com/minelittlepony/unicopia/Race.java b/src/main/java/com/minelittlepony/unicopia/Race.java index 0bafe9fd..6647951f 100644 --- a/src/main/java/com/minelittlepony/unicopia/Race.java +++ b/src/main/java/com/minelittlepony/unicopia/Race.java @@ -187,6 +187,12 @@ public record Race (boolean canCast, FlightType flightType, boolean canUseEarth, } public record Composite (Race physical, @Nullable Race pseudo) { + public static Composite DEFAULT = new Composite(Race.HUMAN, null); + + public Race collapsed() { + return pseudo == null ? physical : pseudo; + } + public boolean includes(Race race) { return physical == race || pseudo == race; } @@ -194,6 +200,18 @@ public record Race (boolean canCast, FlightType flightType, boolean canUseEarth, public boolean any(Predicate test) { return test.test(physical) || (pseudo != null && test.test(pseudo)); } + + public boolean canUseEarth() { + return any(Race::canUseEarth); + } + + public boolean canFly() { + return any(Race::canFly); + } + + public boolean canCast() { + return any(Race::canCast); + } } } diff --git a/src/main/java/com/minelittlepony/unicopia/Unicopia.java b/src/main/java/com/minelittlepony/unicopia/Unicopia.java index fd06e637..661e4f04 100644 --- a/src/main/java/com/minelittlepony/unicopia/Unicopia.java +++ b/src/main/java/com/minelittlepony/unicopia/Unicopia.java @@ -103,8 +103,8 @@ public class Unicopia implements ModInitializer { public interface SidedAccess { Optional getPony(); - default Race getPlayerSpecies() { - return getPony().map(Pony::getSpecies).orElse(Race.HUMAN); + default Race.Composite getPlayerSpecies() { + return getPony().map(Pony::getCompositeRace).orElse(Race.Composite.DEFAULT); } } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java b/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java index 6ae10a9f..14bb8370 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java @@ -66,8 +66,9 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable { } public int getMaxPage() { - if (maxPage < 0 || prevRace != player.getSpecies()) { - prevRace = player.getSpecies(); + Race newRace = player.getCompositeRace().collapsed(); + if (maxPage < 0 || prevRace != newRace) { + prevRace = newRace; maxPage = 0; for (AbilitySlot slot : AbilitySlot.values()) { maxPage = Math.max(maxPage, getStat(slot).getMaxPage() - 1); diff --git a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java index 40fb5a36..544ae467 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyStompAbility.java @@ -127,7 +127,7 @@ public class EarthPonyStompAbility implements Ability { double amount = (1.5F * player.getAttributeInstance(EntityAttributes.GENERIC_ATTACK_DAMAGE).getValue() + heavyness * 0.4) / (float)(dist * 1.3F); if (i instanceof PlayerEntity) { - Race race = Pony.of((PlayerEntity)i).getSpecies(); + Race.Composite race = Pony.of((PlayerEntity)i).getCompositeRace(); if (race.canUseEarth()) { amount /= 3; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/PegasusFlightToggleAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/PegasusFlightToggleAbility.java index ebcd09bf..11ef53fc 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/PegasusFlightToggleAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/PegasusFlightToggleAbility.java @@ -45,7 +45,7 @@ public class PegasusFlightToggleAbility implements Ability { Identifier id = Abilities.REGISTRY.getId(this); return new Identifier(id.getNamespace(), "textures/gui/ability/" + id.getPath() + (player.getPhysics().isFlying() ? "_land" : "_takeoff") - + (player.getSpecies() == Race.CHANGELING ? "_changeling" : "") + + (player.getObservedSpecies() == Race.CHANGELING ? "_changeling" : "") + ".png"); } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractionUtils.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractionUtils.java index ad7487f1..248b87ca 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractionUtils.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/AttractionUtils.java @@ -48,13 +48,13 @@ public interface AttractionUtils { return Pony.of(entity).map(pony -> { double force = 0.75; - if (pony.getSpecies().canUseEarth()) { + if (pony.getCompositeRace().canUseEarth()) { force /= 2; if (pony.asEntity().isSneaking()) { force /= 6; } - } else if (pony.getSpecies().canFly()) { + } else if (pony.getCompositeRace().canFly()) { force *= 2; } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java index 705533c6..f6f45d05 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/SiphoningSpell.java @@ -138,7 +138,7 @@ public class SiphoningSpell extends AbstractAreaEffectSpell { if (e instanceof PlayerEntity) { Pony player = Pony.of((PlayerEntity)e); - Race race = player.getSpecies(); + Race.Composite race = player.getCompositeRace(); if (race.canCast()) { dealt /= 2; diff --git a/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java b/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java index b183cbad..5d70896d 100644 --- a/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java +++ b/src/main/java/com/minelittlepony/unicopia/advancement/CustomEventCriterion.java @@ -83,7 +83,7 @@ public class CustomEventCriterion extends AbstractCriterion 0 && count % repeatCount == 0)); } diff --git a/src/main/java/com/minelittlepony/unicopia/advancement/RaceChangeCriterion.java b/src/main/java/com/minelittlepony/unicopia/advancement/RaceChangeCriterion.java index 42b5dedd..b014417f 100644 --- a/src/main/java/com/minelittlepony/unicopia/advancement/RaceChangeCriterion.java +++ b/src/main/java/com/minelittlepony/unicopia/advancement/RaceChangeCriterion.java @@ -44,7 +44,7 @@ public class RaceChangeCriterion extends AbstractCriterion { - return List.of( - Text.literal(String.format("Level %d ", pony.getLevel().get() + 1)).append(pony.getActualSpecies().getDisplayName()).formatted(pony.getSpecies().getAffinity().getColor()), - Text.literal(String.format("Mana: %d%%", (int)(pony.getMagicalReserves().getMana().getPercentFill() * 100))), - Text.literal(String.format("Corruption: %d%%", (int)(pony.getCorruption().getScaled(100)))), - Text.literal(String.format("Experience: %d", (int)(pony.getMagicalReserves().getXp().getPercentFill() * 100))), - Text.literal(String.format("Next level in: %dxp", 100 - (int)(pony.getMagicalReserves().getXp().getPercentFill() * 100))) - ); - }; - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookProfilePageContent.java b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookProfilePageContent.java index 42d1a385..42ac5a74 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookProfilePageContent.java +++ b/src/main/java/com/minelittlepony/unicopia/client/gui/spellbook/SpellbookProfilePageContent.java @@ -1,7 +1,10 @@ package com.minelittlepony.unicopia.client.gui.spellbook; +import java.util.List; + import com.minelittlepony.common.client.gui.IViewRoot; import com.minelittlepony.common.client.gui.dimension.Bounds; +import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.client.gui.*; import com.minelittlepony.unicopia.entity.player.*; import com.minelittlepony.unicopia.util.ColorHelper; @@ -35,14 +38,21 @@ public class SpellbookProfilePageContent implements SpellbookChapterList.Content screen.addDrawable(new SpellbookScreen.ImageButton(x, y, size, size)) .getStyle() - .setIcon(TribeButton.createSprite(pony.getActualSpecies(), 0, 0, size)) - .setTooltip(ProfileTooltip.get(pony)); + .setIcon(TribeButton.createSprite(pony.getSpecies(), 0, 0, size)) + .setTooltip(() -> List.of( + Text.literal(String.format("Level %d ", pony.getLevel().get() + 1)).append(pony.getSpecies().getDisplayName()).formatted(pony.getSpecies().getAffinity().getColor()), + Text.literal(String.format("Mana: %d%%", (int)(pony.getMagicalReserves().getMana().getPercentFill() * 100))), + Text.literal(String.format("Corruption: %d%%", (int)(pony.getCorruption().getScaled(100)))), + Text.literal(String.format("Experience: %d", (int)(pony.getMagicalReserves().getXp().getPercentFill() * 100))), + Text.literal(String.format("Next level in: %dxp", 100 - (int)(pony.getMagicalReserves().getXp().getPercentFill() * 100))) + )); - if (pony.getSpecies() != pony.getActualSpecies()) { + Race inherited = pony.getCompositeRace().collapsed(); + if (inherited != pony.getSpecies()) { int halfSize = size / 2; screen.addDrawable(new SpellbookScreen.ImageButton(x + halfSize, y + halfSize, halfSize, halfSize)) .getStyle() - .setIcon(TribeButton.createSprite(pony.getSpecies(), 0, 0, halfSize)); + .setIcon(TribeButton.createSprite(inherited, 0, 0, halfSize)); } } diff --git a/src/main/java/com/minelittlepony/unicopia/command/SpeciesCommand.java b/src/main/java/com/minelittlepony/unicopia/command/SpeciesCommand.java index 4c7a7ac5..2a18cb47 100644 --- a/src/main/java/com/minelittlepony/unicopia/command/SpeciesCommand.java +++ b/src/main/java/com/minelittlepony/unicopia/command/SpeciesCommand.java @@ -87,7 +87,7 @@ class SpeciesCommand { } static int get(ServerCommandSource source, PlayerEntity player, boolean isSelf) { - Race spec = Pony.of(player).getActualSpecies(); + Race spec = Pony.of(player).getSpecies(); String name = "commands.race.tell."; name += isSelf ? "self" : "other"; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/Equine.java b/src/main/java/com/minelittlepony/unicopia/entity/Equine.java index a7e0e6fe..dbfd9295 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/Equine.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/Equine.java @@ -20,6 +20,10 @@ public interface Equine extends NbtSerialisable, Tickable, Pro void setSpecies(Race race); + default Race.Composite getCompositeRace() { + return new Race.Composite(getSpecies(), null); + } + /** * Called at the beginning of an update cycle. */ diff --git a/src/main/java/com/minelittlepony/unicopia/entity/effect/RaceChangeStatusEffect.java b/src/main/java/com/minelittlepony/unicopia/entity/effect/RaceChangeStatusEffect.java index 906fc91d..463d0f27 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/effect/RaceChangeStatusEffect.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/effect/RaceChangeStatusEffect.java @@ -81,7 +81,7 @@ public class RaceChangeStatusEffect extends StatusEffect { int progression = ticks % (stage.ordinal() * STAGE_DURATION); - if ((eq instanceof Pony pony ? pony.getActualSpecies() : eq.getSpecies()) == race || !race.isPermitted(entity instanceof PlayerEntity player ? player : null)) { + if (eq.getSpecies() == race || !race.isPermitted(entity instanceof PlayerEntity player ? player : null)) { if (progression == 0 && entity instanceof PlayerEntity player && stage == Stage.CRAWLING) { player.sendMessage(Stage.INITIAL.getMessage(race), true); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java b/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java index 450e2fe3..4ab1ddf4 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/ManaContainer.java @@ -95,13 +95,13 @@ class ManaContainer implements MagicReserves, Tickable, NbtSerialisable, Copyabl energy.addPercent(-1); } - if (pony.getSpecies().canFly() && !pony.getPhysics().isFlying()) { + if (pony.getCompositeRace().canFly() && !pony.getPhysics().isFlying()) { exhaustion.multiply(0.8F); } else { exhaustion.addPercent(-1); } - if (!pony.getSpecies().canFly() || !pony.getPhysics().isFlying()) { + if (!pony.getCompositeRace().canFly() || !pony.getPhysics().isFlying()) { if (mana.getPercentFill() < 1 && mana.getShadowFill(1) <= mana.getPercentFill(1)) { mana.addPercent(MathHelper.clamp(1 + pony.getLevel().get(), 1, 50) / 4F); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java index 93bd8287..8884b26d 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerAttributes.java @@ -17,9 +17,9 @@ public class PlayerAttributes implements Tickable { private static final EntityAttributeModifier EARTH_PONY_STRENGTH = new EntityAttributeModifier(UUID.fromString("777a5505-521e-480b-b9d5-6ea54f259564"), "Earth Pony Strength", 0.6, Operation.MULTIPLY_TOTAL); private static final EntityAttributeModifier EARTH_PONY_MINING_SPEED = - new EntityAttributeModifier(UUID.fromString("9fc9e269-152e-0b48-9bd5-564a546e59f2"), "Earth Pony Mining Speed", 0.4, Operation.MULTIPLY_TOTAL); + new EntityAttributeModifier(UUID.fromString("9fc9e269-152e-0b48-9bd5-564a546e59f2"), "Earth Pony Mining Speed", 0.5, Operation.MULTIPLY_TOTAL); private static final EntityAttributeModifier EARTH_PONY_KNOCKBACK_RESISTANCE = - new EntityAttributeModifier(UUID.fromString("79e269a8-03e8-b9d5-5853-e25fdcf6706d"), "Earth Pony Knockback Resistance", 2, Operation.ADDITION); + new EntityAttributeModifier(UUID.fromString("79e269a8-03e8-b9d5-5853-e25fdcf6706d"), "Earth Pony Knockback Resistance", 6, Operation.ADDITION); private static final EntityAttributeModifier PEGASUS_SPEED = new EntityAttributeModifier(UUID.fromString("9e2699fc-3b8d-4f71-9d2d-fb92ee19b4f7"), "Pegasus Speed", 0.2, Operation.MULTIPLY_TOTAL); @@ -41,15 +41,18 @@ public class PlayerAttributes implements Tickable { @Override public void tick() { PlayerEntity entity = pony.asEntity(); - Race race = pony.getSpecies(); + Race.Composite race = pony.getCompositeRace(); - toggleAttribute(entity, EntityAttributes.GENERIC_ATTACK_DAMAGE, EARTH_PONY_STRENGTH, race.canUseEarth()); - toggleAttribute(entity, EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, EARTH_PONY_STRENGTH, race.canUseEarth()); - toggleAttribute(entity, EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, EARTH_PONY_KNOCKBACK_RESISTANCE, race.canUseEarth() && entity.isSneaking()); - toggleAttribute(entity, EntityAttributes.GENERIC_MOVEMENT_SPEED, PEGASUS_SPEED, race.canFly()); - toggleAttribute(entity, EntityAttributes.GENERIC_ATTACK_SPEED, PEGASUS_SPEED, race.canFly()); - toggleAttribute(entity, UEntityAttributes.EXTENDED_REACH_DISTANCE, PEGASUS_REACH, race.canFly()); - toggleAttribute(entity, UEntityAttributes.EXTRA_MINING_SPEED, EARTH_PONY_MINING_SPEED, race.canUseEarth()); + boolean earth = race.canUseEarth(); + boolean flight = race.canFly(); + + toggleAttribute(entity, EntityAttributes.GENERIC_ATTACK_DAMAGE, EARTH_PONY_STRENGTH, earth); + toggleAttribute(entity, EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, EARTH_PONY_STRENGTH, earth); + toggleAttribute(entity, EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, EARTH_PONY_KNOCKBACK_RESISTANCE, earth && entity.isSneaking()); + toggleAttribute(entity, EntityAttributes.GENERIC_MOVEMENT_SPEED, PEGASUS_SPEED, flight); + toggleAttribute(entity, EntityAttributes.GENERIC_ATTACK_SPEED, PEGASUS_SPEED, flight); + toggleAttribute(entity, UEntityAttributes.EXTENDED_REACH_DISTANCE, PEGASUS_REACH, flight); + toggleAttribute(entity, UEntityAttributes.EXTRA_MINING_SPEED, EARTH_PONY_MINING_SPEED, earth); } private void toggleAttribute(PlayerEntity entity, EntityAttribute attribute, EntityAttributeModifier modifier, boolean enable) { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java index 30ad9e53..aa302521 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/PlayerPhysics.java @@ -353,7 +353,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab descentRate = 0; ticksDiving = 0; - if (Abilities.RAINBOOM.canUse(pony.getActualSpecies()) && entity.isOnGround()) { + if (Abilities.RAINBOOM.canUse(pony.getSpecies()) && entity.isOnGround()) { pony.getMagicalReserves().getCharge().set(0); } @@ -683,7 +683,7 @@ public class PlayerPhysics extends EntityPhysics implements Tickab SoundEmitter.playSoundAt(entity, USounds.AMBIENT_WIND_GUST, SoundCategory.AMBIENT, 3, 1); } - float weight = 1 + (EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, entity) * 0.8F) + (pony.getActualSpecies().canUseEarth() ? 1 : 0); + float weight = 1 + (EnchantmentHelper.getEquipmentLevel(UEnchantments.HEAVY, entity) * 0.8F) + (pony.getCompositeRace().canUseEarth() ? 1 : 0); velocity.add(WeatherConditions.getAirflow(entity.getBlockPos(), entity.getWorld()), 0.04F * effectStrength); velocity.add(Vec3d.fromPolar( 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 810b468a..2251c797 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -190,23 +190,11 @@ public class Pony extends Living implements Copyable, Update } /** - * 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. - * - * @deprecated Use {@link Pony#getCompositeRace()} or {@link Pony#getObservedSpecies()} + * Gets this player's inherent species. */ - @Deprecated @Override public Race getSpecies() { - if (AmuletSelectors.ALICORN_AMULET.test(entity)) { - return Race.ALICORN; - } - if (AmuletSelectors.UNICORN_AMULET.test(entity)) { - return Race.UNICORN; - } - - return getObservedSpecies(); + return Race.fromName(entity.getDataTracker().get(RACE), Race.HUMAN); } /** @@ -219,30 +207,23 @@ public class Pony extends Living implements Copyable, Update .map(AbstractDisguiseSpell::getDisguise) .map(EntityAppearance::getAppearance) .flatMap(Pony::of) - .map(Pony::getActualSpecies) - .orElseGet(this::getActualSpecies); + .map(Pony::getSpecies) + .orElseGet(this::getSpecies); } /** * 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. */ + @Override public Race.Composite getCompositeRace() { - Race observed = getObservedSpecies(); - return new Race.Composite(observed, + return new Race.Composite(getObservedSpecies(), AmuletSelectors.UNICORN_AMULET.test(entity) ? Race.UNICORN : AmuletSelectors.ALICORN_AMULET.test(entity) ? Race.ALICORN : null ); } - /** - * 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); - } - @Override public void setSpecies(Race race) { race = race.validate(entity); @@ -575,7 +556,7 @@ public class Pony extends Living implements Copyable, Update } } - if (entity.hurtTime == 1 && getSpecies().canCast()) { + if (entity.hurtTime == 1 && getCompositeRace().physical().canCast()) { corruption.add(1); setDirty(); } @@ -586,7 +567,7 @@ public class Pony extends Living implements Copyable, Update public void tick() { super.tick(); - Race currentRace = getActualSpecies(); + Race currentRace = getSpecies(); if (!currentRace.isUnset()) { Race newRace = currentRace.validate(entity); @@ -596,16 +577,12 @@ public class Pony extends Living implements Copyable, Update } sendCapabilities(); - - //if (!isClient()) { - // CrystalShardsEntity.infestBlock((ServerWorld)asWorld(), entity.getBlockPos().down()); - //} } @Override public boolean canBeSeenBy(Entity entity) { if (entity instanceof HostileEntity hostile - && getActualSpecies() == Race.BAT + && getSpecies() == Race.BAT && hostile.getTarget() != this.entity && hostile.getAttacker() != this.entity && entity.distanceTo(this.entity) > entity.getWidth()) { @@ -659,7 +636,7 @@ public class Pony extends Living implements Copyable, Update && !cause.isOf(DamageTypes.THORNS) && !cause.isOf(DamageTypes.FREEZE)) { - if (getSpecies().canUseEarth() && entity.isSneaking()) { + if (getCompositeRace().canUseEarth() && entity.isSneaking()) { amount /= (cause.isOf(DamageTypes.MOB_PROJECTILE) ? 3 : 2) * (entity.getHealth() < 5 ? 3 : 1); return Optional.of(amount); @@ -692,7 +669,7 @@ public class Pony extends Living implements Copyable, Update } } - if (getSpecies().canFly() || (getSpecies().canUseEarth() && entity.isSneaking())) { + if (getCompositeRace().canFly() || (getCompositeRace().canUseEarth() && entity.isSneaking())) { distance -= 5; } distance = Math.max(0, distance); @@ -710,7 +687,7 @@ public class Pony extends Living implements Copyable, Update protected void handleFall(float distance, float damageMultiplier, DamageSource cause) { super.handleFall(distance, damageMultiplier, cause); - if (getSpecies().canUseEarth() && entity.isSneaking()) { + if (getCompositeRace().canUseEarth() && entity.isSneaking()) { double radius = distance / 10; if (radius > 0) { EarthPonyStompAbility.spawnEffectAround(entity, entity.getLandingPos(), radius, radius); @@ -775,7 +752,7 @@ public class Pony extends Living implements Copyable, Update } public ActionResult canSleepNow() { - if (asWorld().getGameRules().getBoolean(UGameRules.DO_NOCTURNAL_BAT_PONIES) && getActualSpecies().isNocturnal()) { + if (asWorld().getGameRules().getBoolean(UGameRules.DO_NOCTURNAL_BAT_PONIES) && getSpecies().isNocturnal()) { return asWorld().isDay() ? ActionResult.SUCCESS : ActionResult.FAIL; } @@ -790,7 +767,7 @@ public class Pony extends Living implements Copyable, Update @Override public void toSyncronisedNbt(NbtCompound compound) { super.toSyncronisedNbt(compound); - compound.putString("playerSpecies", Race.REGISTRY.getId(getActualSpecies()).toString()); + compound.putString("playerSpecies", Race.REGISTRY.getId(getSpecies()).toString()); compound.putFloat("magicExhaustion", magicExhaustion); compound.putInt("ticksHanging", ticksHanging); BLOCK_POS.writeOptional("hangingPosition", compound, getHangingPosition()); @@ -843,7 +820,7 @@ public class Pony extends Living implements Copyable, Update && entity instanceof ServerPlayerEntity && entity.getWorld().getGameRules().getBoolean(UGameRules.SWAP_TRIBE_ON_DEATH) && oldPlayer.respawnRace.isUnset()) - || oldPlayer.getActualSpecies().isUnset(); + || oldPlayer.getSpecies().isUnset(); if (alive) { oldPlayer.getSpellSlot().stream(true).forEach(getSpellSlot()::put); @@ -866,7 +843,7 @@ public class Pony extends Living implements Copyable, Update } } - setSpecies(oldPlayer.respawnRace != Race.UNSET && !alive ? oldPlayer.respawnRace : oldPlayer.getActualSpecies()); + setSpecies(oldPlayer.respawnRace != Race.UNSET && !alive ? oldPlayer.respawnRace : oldPlayer.getSpecies()); getDiscoveries().copyFrom(oldPlayer.getDiscoveries(), alive); getPhysics().copyFrom(oldPlayer.getPhysics(), alive); if (!forcedSwap) { diff --git a/src/main/java/com/minelittlepony/unicopia/item/BellItem.java b/src/main/java/com/minelittlepony/unicopia/item/BellItem.java index 3c0cdbe0..472d1261 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/BellItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/BellItem.java @@ -138,7 +138,7 @@ public class BellItem extends Item implements ChargeableItem { if (living instanceof Pony pony) { amountDrawn = pony.getMagicalReserves().getMana().get() * 0.2F; pony.getMagicalReserves().getMana().multiply(0.8F); - if (pony.getActualSpecies() == Race.CHANGELING) { + if (pony.getSpecies() == Race.CHANGELING) { particleType = ParticleTypes.HEART; } } else { diff --git a/src/main/java/com/minelittlepony/unicopia/item/CrystalHeartItem.java b/src/main/java/com/minelittlepony/unicopia/item/CrystalHeartItem.java index b191137f..facbf85c 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/CrystalHeartItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/CrystalHeartItem.java @@ -130,7 +130,7 @@ public class CrystalHeartItem extends Item implements FloatingArtefactEntity.Art } }); VecHelper.findInRange(entity, entity.getWorld(), entity.getPos(), 20, i -> { - return i instanceof ItemEntity ie && isFillable(ie.getStack()) && Equine.of(i).filter(p -> p.getSpecies() == Race.CHANGELING).isPresent(); + return i instanceof ItemEntity ie && isFillable(ie.getStack()) && EquinePredicates.CHANGELING.test(i); }).forEach(i -> containers.add((ItemEntity)i)); int demand = outputs.size() + containers.stream().mapToInt(i -> i.getStack().getCount()).sum(); diff --git a/src/main/java/com/minelittlepony/unicopia/item/enchantment/EnchantmentUtil.java b/src/main/java/com/minelittlepony/unicopia/item/enchantment/EnchantmentUtil.java index 6d223e8d..5bc6d8f2 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/enchantment/EnchantmentUtil.java +++ b/src/main/java/com/minelittlepony/unicopia/item/enchantment/EnchantmentUtil.java @@ -41,7 +41,7 @@ public interface EnchantmentUtil { } static int getLuck(int baseline, LivingEntity entity) { - boolean naturallyLucky = Living.getOrEmpty(entity).filter(c -> c.getSpecies().canUseEarth()).isPresent(); + boolean naturallyLucky = Living.getOrEmpty(entity).filter(c -> c.getCompositeRace().canUseEarth()).isPresent(); if (naturallyLucky) { baseline += 15; } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinDamageSource.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinDamageSource.java index a2ff8de6..7da56dcd 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinDamageSource.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinDamageSource.java @@ -30,7 +30,7 @@ abstract class MixinDamageSource { }); - Pony.of(entity).filter(e -> e.getSpecies().canFly()).ifPresent(pony -> { + Pony.of(entity).filter(e -> e.getCompositeRace().canFly()).ifPresent(pony -> { if (pony.getPhysics().isFlying()) { info.setReturnValue(Text.translatable("death.attack.unicopia.generic.whilst_flying", info.getReturnValue())); } @@ -47,7 +47,7 @@ abstract class MixinFallLocation { return; } Pony.of(entity).ifPresent(pony -> { - if (pony.getSpecies().canFly()) { + if (pony.getCompositeRace().canFly()) { info.setReturnValue(new FallLocation(location.id() + ".pegasus")); } }); diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinPowderSnowBlock.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinPowderSnowBlock.java index 2ecdc435..3b4afd10 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinPowderSnowBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinPowderSnowBlock.java @@ -5,7 +5,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.entity.player.Pony; import net.minecraft.block.PowderSnowBlock; @@ -15,7 +14,7 @@ import net.minecraft.entity.Entity; abstract class MixinPowderSnowBlock { @Inject(method = "canWalkOnPowderSnow", at = @At("HEAD"), cancellable = true) private static void onCanWalkOnPowderSnow(Entity entity, CallbackInfoReturnable info) { - if (Pony.of(entity).map(Pony::getSpecies).filter(Race::canFly).isPresent()) { + if (Pony.of(entity).filter(pony -> pony.getCompositeRace().canFly()).isPresent()) { info.setReturnValue(true); } } diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinServerPlayerEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinServerPlayerEntity.java index c73851b4..17bb934d 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinServerPlayerEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinServerPlayerEntity.java @@ -40,7 +40,7 @@ abstract class MixinServerPlayerEntity extends PlayerEntity implements ScreenHan at = @At(value = "FIELD", target = "net/minecraft/entity/player/PlayerEntity$SleepFailureReason.NOT_POSSIBLE_NOW:Lnet/minecraft/entity/player/PlayerEntity$SleepFailureReason;"), cancellable = true) private void onTrySleep(BlockPos pos, CallbackInfoReturnable> info) { - if (get().getActualSpecies().isNocturnal() && get().asWorld().getGameRules().getBoolean(UGameRules.DO_NOCTURNAL_BAT_PONIES)) { + if (get().getSpecies().isNocturnal() && get().asWorld().getGameRules().getBoolean(UGameRules.DO_NOCTURNAL_BAT_PONIES)) { ((PlayerEntity)this).sendMessage(Text.translatable("block.unicopia.bed.no_sleep.nocturnal"), true); info.setReturnValue(Either.left(PlayerEntity.SleepFailureReason.OTHER_PROBLEM)); diff --git a/src/main/java/com/minelittlepony/unicopia/network/Channel.java b/src/main/java/com/minelittlepony/unicopia/network/Channel.java index 313a1e60..b62dd139 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/Channel.java +++ b/src/main/java/com/minelittlepony/unicopia/network/Channel.java @@ -35,7 +35,7 @@ public interface Channel { static void bootstrap() { ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { Pony pony = Pony.of(handler.player); - if (pony.getActualSpecies() == Race.UNSET) { + if (pony.getSpecies() == Race.UNSET) { Race race = UnicopiaWorldProperties.forWorld(handler.player.getServerWorld()).getDefaultRace(); if (!race.isPermitted(handler.player)) { race = Race.UNSET; diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java index e4427e64..a0af9093 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestSpeciesChange.java @@ -35,14 +35,14 @@ public record MsgRequestSpeciesChange ( public void handle(ServerPlayerEntity sender) { Pony player = Pony.of(sender); - if (force || player.getActualSpecies().isUnset()) { + if (force || player.getSpecies().isUnset()) { player.setSpecies(newRace.isPermitted(sender) ? newRace : UnicopiaWorldProperties.forWorld((ServerWorld)player.asWorld()).getDefaultRace()); if (force) { if (sender.getWorld().getGameRules().getBoolean(UGameRules.ANNOUNCE_TRIBE_JOINS)) { Text message = Text.translatable("respawn.reason.joined_new_tribe", sender.getDisplayName(), - player.getActualSpecies().getDisplayName(), player.getActualSpecies().getAltDisplayName()); + player.getSpecies().getDisplayName(), player.getSpecies().getAltDisplayName()); sender.getWorld().getPlayers().forEach(p -> { ((ServerPlayerEntity)p).sendMessageToClient(message, false); }); diff --git a/src/main/java/com/minelittlepony/unicopia/server/world/NocturnalSleepManager.java b/src/main/java/com/minelittlepony/unicopia/server/world/NocturnalSleepManager.java index f39e0dc2..113f50b3 100644 --- a/src/main/java/com/minelittlepony/unicopia/server/world/NocturnalSleepManager.java +++ b/src/main/java/com/minelittlepony/unicopia/server/world/NocturnalSleepManager.java @@ -33,7 +33,7 @@ public class NocturnalSleepManager extends SleepManager { if (world.getGameRules().getBoolean(GameRules.DO_DAYLIGHT_CYCLE) && world.getPlayers().stream() .filter(LivingEntity::isSleeping) .map(Pony::of) - .map(Pony::getActualSpecies) + .map(Pony::getSpecies) .noneMatch(Race::isDayurnal)) { world.setTimeOfDay(world.getLevelProperties().getTimeOfDay() - DAY_LENGTH + 13500); } @@ -50,7 +50,7 @@ public class NocturnalSleepManager extends SleepManager { return players.stream().filter(player -> { Pony pony = Pony.of(player); - return (pony.getActualSpecies().isNocturnal() == world.isDay()); + return (pony.getSpecies().isNocturnal() == world.isDay()); }).toList(); } diff --git a/src/main/java/com/minelittlepony/unicopia/util/MagicalDamageSource.java b/src/main/java/com/minelittlepony/unicopia/util/MagicalDamageSource.java index 41a3060d..a683004a 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/MagicalDamageSource.java +++ b/src/main/java/com/minelittlepony/unicopia/util/MagicalDamageSource.java @@ -74,8 +74,7 @@ public class MagicalDamageSource extends DamageSource { } Text message = Text.translatable(basic, params.toArray()); - return Pony.of(target).filter(e -> e.getSpecies().canFly()).map(pony -> { - + return Pony.of(target).filter(e -> e.getCompositeRace().canFly()).map(pony -> { if (pony.getPhysics().isFlying()) { return Text.translatable("death.attack.unicopia.generic.whilst_flying", message); }