Fixed storm clouds not spawning lightning in the correct place

This commit is contained in:
Sollace 2023-10-19 23:45:14 +01:00
parent c3fee217d1
commit 84cb3de5e3
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB

View file

@ -257,21 +257,24 @@ public class StormCloudEntity extends Entity implements MagicImmune {
private void pickRandomPoints(int count, Consumer<BlockPos> action) { private void pickRandomPoints(int count, Consumer<BlockPos> action) {
BlockPos.iterateRandomly(random, 3, getBlockPos(), getSizeInBlocks()).forEach(pos -> { BlockPos.iterateRandomly(random, 3, getBlockPos(), getSizeInBlocks()).forEach(pos -> {
action.accept(findSurfaceBelow(getWorld(), 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);
}); });
} }
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) { private void spawnLightningStrike(BlockPos pos, boolean cosmetic, boolean infect) {
if (infect) { if (infect) {
if (!CrystalShardsEntity.infestBlock((ServerWorld)getWorld(), pos)) { if (!CrystalShardsEntity.infestBlock((ServerWorld)getWorld(), pos)) {