From 84cb3de5e3ea2ca374bfa78b44b3f9cc1deaff9e Mon Sep 17 00:00:00 2001 From: Sollace Date: Thu, 19 Oct 2023 23:45:14 +0100 Subject: [PATCH] Fixed storm clouds not spawning lightning in the correct place --- .../unicopia/entity/mob/StormCloudEntity.java | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/StormCloudEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/StormCloudEntity.java index f522b812..828b2593 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/StormCloudEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/StormCloudEntity.java @@ -257,21 +257,24 @@ public class StormCloudEntity extends Entity implements MagicImmune { private void pickRandomPoints(int count, Consumer action) { BlockPos.iterateRandomly(random, 3, getBlockPos(), getSizeInBlocks()).forEach(pos -> { - - BlockPos.Mutable mutable = new BlockPos.Mutable(); - mutable.set(pos); - while (getWorld().isInBuildLimit(mutable) && getWorld().isAir(mutable)) { - mutable.move(Direction.DOWN); - } - while (getWorld().isInBuildLimit(mutable) && !getWorld().isAir(mutable)) { - mutable.move(Direction.UP); - } - mutable.move(Direction.DOWN); - - action.accept(pos); + action.accept(findSurfaceBelow(getWorld(), pos)); }); } + public static BlockPos findSurfaceBelow(World world, BlockPos pos) { + BlockPos.Mutable mutable = new BlockPos.Mutable(); + mutable.set(pos); + while (world.isInBuildLimit(mutable) && world.isAir(mutable)) { + mutable.move(Direction.DOWN); + } + while (world.isInBuildLimit(mutable) && !world.isAir(mutable)) { + mutable.move(Direction.UP); + } + mutable.move(Direction.DOWN); + + return mutable; + } + private void spawnLightningStrike(BlockPos pos, boolean cosmetic, boolean infect) { if (infect) { if (!CrystalShardsEntity.infestBlock((ServerWorld)getWorld(), pos)) {