From 3948bf4a58172c55d90e7cb51ba634775e75d6c3 Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 9 Nov 2023 23:41:09 +0000 Subject: [PATCH] Anyone who can use the change form ability can also sign and use the friendship bracelets --- .../unicopia/ability/ChangeFormAbility.java | 43 ++++++++++++------- .../unicopia/entity/player/Pony.java | 2 +- .../unicopia/item/FriendshipBraceletItem.java | 3 +- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/ChangeFormAbility.java b/src/main/java/com/minelittlepony/unicopia/ability/ChangeFormAbility.java index fb60bdac..ead40298 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/ChangeFormAbility.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/ChangeFormAbility.java @@ -1,6 +1,8 @@ package com.minelittlepony.unicopia.ability; +import java.util.List; import java.util.Optional; +import java.util.stream.Stream; import org.jetbrains.annotations.Nullable; @@ -8,6 +10,7 @@ import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.ability.data.Hit; import com.minelittlepony.unicopia.entity.player.Pony; +import com.minelittlepony.unicopia.item.FriendshipBraceletItem; import net.minecraft.particle.ParticleTypes; import net.minecraft.sound.SoundCategory; @@ -67,12 +70,17 @@ public class ChangeFormAbility implements Ability { return false; } - player.subtractEnergyCost(5); - - Race.Composite composite = player.getCompositeRace(); - Race actualRace = player.getSpecies(); - player.setSpecies(composite.potential()); - player.setSuppressedRace(actualRace.availability().isGrantable() ? actualRace : Race.UNSET); + List targets = getTargets(player).toList(); + player.subtractEnergyCost(5 * targets.size()); + boolean isTransforming = player.getSuppressedRace().isUnset(); + targets.forEach(target -> { + Race supressed = target.getSuppressedRace(); + if (target == player || supressed.isUnset() == isTransforming) { + Race actualRace = target.getSpecies(); + target.setSpecies(supressed.or(player.getCompositeRace().potential())); + target.setSuppressedRace(isTransforming ? actualRace : Race.UNSET); + } + }); return true; } @@ -80,20 +88,25 @@ public class ChangeFormAbility implements Ability { @Override public void warmUp(Pony player, AbilitySlot slot) { player.getMagicalReserves().getExertion().addPercent(6); + getTargets(player).forEach(target -> { + if (player.getAbilities().getStat(slot).getWarmup() % 5 == 0) { + player.asWorld().playSound(target.asEntity(), target.getOrigin(), SoundEvents.BLOCK_BUBBLE_COLUMN_WHIRLPOOL_INSIDE, SoundCategory.PLAYERS); + } - if (player.getAbilities().getStat(slot).getWarmup() % 5 == 0) { - player.asWorld().playSound(null, player.getOrigin(), SoundEvents.BLOCK_BUBBLE_COLUMN_WHIRLPOOL_INSIDE, SoundCategory.PLAYERS); - } + if (player.asWorld().random.nextInt(5) == 0) { + player.asWorld().playSound(target.asEntity(), target.getOrigin(), USounds.Vanilla.BLOCK_BUBBLE_COLUMN_BUBBLE_POP, SoundCategory.PLAYERS); + } - if (player.asWorld().random.nextInt(5) == 0) { - player.asWorld().playSound(null, player.getOrigin(), USounds.Vanilla.BLOCK_BUBBLE_COLUMN_BUBBLE_POP, SoundCategory.PLAYERS); - } - - player.spawnParticles(ParticleTypes.BUBBLE_COLUMN_UP, 15); - player.spawnParticles(ParticleTypes.BUBBLE_POP, 15); + target.spawnParticles(ParticleTypes.BUBBLE_COLUMN_UP, 15); + target.spawnParticles(ParticleTypes.BUBBLE_POP, 15); + }); } @Override public void coolDown(Pony player, AbilitySlot slot) { } + + private Stream getTargets(Pony player) { + return Stream.concat(Stream.of(player), FriendshipBraceletItem.getPartyMembers(player, 3)); + } } 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 221d4dc3..8dfef123 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Pony.java @@ -247,7 +247,7 @@ public class Pony extends Living implements Copyable, Update setSuppressedRace(Race.UNSET); } - private Race getSuppressedRace() { + public Race getSuppressedRace() { return Race.fromName(entity.getDataTracker().get(SUPPRESSED_RACE), Race.UNSET); } diff --git a/src/main/java/com/minelittlepony/unicopia/item/FriendshipBraceletItem.java b/src/main/java/com/minelittlepony/unicopia/item/FriendshipBraceletItem.java index 5575d357..326ddd43 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/FriendshipBraceletItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/FriendshipBraceletItem.java @@ -10,6 +10,7 @@ import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.compat.trinkets.TrinketsDelegate; +import com.minelittlepony.unicopia.entity.AmuletSelectors; import com.minelittlepony.unicopia.entity.player.Pony; import net.fabricmc.api.EnvType; @@ -37,7 +38,7 @@ public class FriendshipBraceletItem extends WearableItem implements DyeableItem, public TypedActionResult use(World world, PlayerEntity player, Hand hand) { ItemStack stack = player.getStackInHand(hand); - if (!isSigned(stack) && EquinePredicates.PLAYER_UNICORN.test(player)) { + if (!isSigned(stack) && (EquinePredicates.PLAYER_UNICORN.test(player) || AmuletSelectors.PEARL_NECKLACE.test(player))) { player.setCurrentHand(hand); ItemStack result = stack.copy();