From 48f9d6242c5ddaee6f0eeebbc525ee7edec42086 Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 28 Sep 2023 21:51:45 +0100 Subject: [PATCH] Prevent spawning multiple sombras and prevent the altar from reactivating after successfully summoning him --- .../minelittlepony/unicopia/entity/mob/SombraEntity.java | 7 +++++++ .../minelittlepony/unicopia/item/AlicornAmuletItem.java | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/SombraEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/SombraEntity.java index addb0236..d280b586 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/SombraEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/SombraEntity.java @@ -76,6 +76,7 @@ import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; import net.minecraft.util.math.Direction; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; @@ -105,6 +106,12 @@ public class SombraEntity extends HostileEntity implements ArenaCombatant, Parti private float currentSize; public static void startEncounter(World world, BlockPos pos) { + if (world.getEntitiesByClass(Entity.class, new Box(pos).expand(16), e -> { + return e instanceof SombraEntity || e instanceof StormCloudEntity cloud && cloud.cursed; + }).size() > 0) { + return; + } + StormCloudEntity cloud = UEntities.STORM_CLOUD.create(world); cloud.setPosition(pos.up(10).toCenterPos()); cloud.setSize(1); diff --git a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java index 10308b35..7a4eb3f3 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/AlicornAmuletItem.java @@ -4,6 +4,7 @@ import java.util.*; import org.jetbrains.annotations.Nullable; +import com.google.common.base.Predicates; import com.google.common.collect.ImmutableMultimap; import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.USounds; @@ -12,6 +13,7 @@ import com.minelittlepony.unicopia.entity.*; import com.minelittlepony.unicopia.entity.damage.UDamageTypes; import com.minelittlepony.unicopia.entity.effect.UEffects; import com.minelittlepony.unicopia.entity.mob.SombraEntity; +import com.minelittlepony.unicopia.entity.mob.SpellbookEntity; import com.minelittlepony.unicopia.entity.player.*; import com.minelittlepony.unicopia.particle.FollowingParticleEffect; import com.minelittlepony.unicopia.particle.ParticleUtils; @@ -201,6 +203,7 @@ public class AlicornAmuletItem extends AmuletItem implements ItemTracker.Trackab stack.decrement(1); world.createExplosion(null, entity.getX(), entity.getY(), entity.getZ(), 0, ExplosionSourceType.NONE); world.playSound(null, entity.getBlockPos(), USounds.ENTITY_SOMBRA_LAUGH, SoundCategory.AMBIENT, 10, 1); + world.getEntitiesByClass(SpellbookEntity.class, entity.getBoundingBox().expand(6), Predicates.alwaysTrue()).forEach(Entity::kill); SombraEntity.startEncounter(world, entity.getBlockPos()); }