From 00826141ffba3d06d598bb661f488ef3b8698ee7 Mon Sep 17 00:00:00 2001 From: Grayray75 <69988482+Grayray75@users.noreply.github.com> Date: Sat, 12 Aug 2023 00:07:18 +0200 Subject: [PATCH] Fix crash while generating chunks --- .../phosphor/mixins/common/ChunkMixin.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/jellysquid/mods/phosphor/mixins/common/ChunkMixin.java b/src/main/java/me/jellysquid/mods/phosphor/mixins/common/ChunkMixin.java index 05bd05b..a3d64d2 100644 --- a/src/main/java/me/jellysquid/mods/phosphor/mixins/common/ChunkMixin.java +++ b/src/main/java/me/jellysquid/mods/phosphor/mixins/common/ChunkMixin.java @@ -4,6 +4,7 @@ import me.jellysquid.mods.phosphor.api.IChunkLightingData; import me.jellysquid.mods.phosphor.api.ILightingEngine; import me.jellysquid.mods.phosphor.api.ILightingEngineProvider; +import me.jellysquid.mods.phosphor.mod.PhosphorMod; import me.jellysquid.mods.phosphor.mod.world.WorldChunkSlice; import me.jellysquid.mods.phosphor.mod.world.lighting.LightingHooks; import net.minecraft.block.BlockState; @@ -256,7 +257,18 @@ private void recheckGapsSkylightNeighborHeight(WorldChunkSlice slice, int x, int } private void checkSkylightNeighborHeight(WorldChunkSlice slice, int x, int z, int maxValue) { - int i = slice.getChunkFromWorldCoords(x, z).getHighestBlockY(x & 15, z & 15); + if (!slice.isLoaded(x, z, 16)) { + return; + } + + Chunk chunk = slice.getChunkFromWorldCoords(x, z); + + if (chunk == null) { + PhosphorMod.LOGGER.warn("Chunk is null! x: " + x + " z: " + z + " maxValue: " + maxValue); + return; + } + + int i = chunk.getHighestBlockY(x & 15, z & 15); if (i > maxValue) { this.updateSkylightNeighborHeight(slice, x, z, maxValue, i + 1); @@ -268,9 +280,9 @@ else if (i < maxValue) { private void updateSkylightNeighborHeight(WorldChunkSlice slice, int x, int z, int startY, int endY) { if (endY > startY) { - if (!slice.isLoaded(x, z, 16)) { + /*if (!slice.isLoaded(x, z, 16)) { return; - } + }*/ for (int i = startY; i < endY; ++i) { this.world.method_8539(LightType.SKY, new BlockPos(x, i, z));