From 31a4fd2181d283ce4e95794c346b21a07048c06b Mon Sep 17 00:00:00 2001 From: PhiPro95 Date: Fri, 12 Feb 2021 05:49:57 +0100 Subject: [PATCH] fix: missing skylight for some chunks Add missing checkForUpdates() call in lightChunks() --- .../chunk/light/LevelPropagatorAccess.java | 2 + .../chunk/light/MixinLevelPropagator.java | 11 +++ .../chunk/light/MixinSkyLightStorage.java | 67 ++++++++++++------- 3 files changed, 55 insertions(+), 25 deletions(-) diff --git a/src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/LevelPropagatorAccess.java b/src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/LevelPropagatorAccess.java index 021aa225..65f91c3c 100644 --- a/src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/LevelPropagatorAccess.java +++ b/src/main/java/me/jellysquid/mods/phosphor/common/chunk/light/LevelPropagatorAccess.java @@ -2,4 +2,6 @@ public interface LevelPropagatorAccess { void invokePropagateLevel(long sourceId, long targetId, int level, boolean decrease); + + void checkForUpdates(); } diff --git a/src/main/java/me/jellysquid/mods/phosphor/mixin/chunk/light/MixinLevelPropagator.java b/src/main/java/me/jellysquid/mods/phosphor/mixin/chunk/light/MixinLevelPropagator.java index 8f48e22a..1a034637 100644 --- a/src/main/java/me/jellysquid/mods/phosphor/mixin/chunk/light/MixinLevelPropagator.java +++ b/src/main/java/me/jellysquid/mods/phosphor/mixin/chunk/light/MixinLevelPropagator.java @@ -33,10 +33,21 @@ public abstract class MixinLevelPropagator implements LevelPropagatorExtended, L @Shadow protected abstract void updateLevel(long sourceId, long id, int level, int currentLevel, int pendingLevel, boolean decrease); + @Shadow + private volatile boolean hasPendingUpdates; + + @Shadow + private int minPendingLevel; + @Override @Invoker("propagateLevel") public abstract void invokePropagateLevel(long sourceId, long targetId, int level, boolean decrease); + @Override + public void checkForUpdates() { + this.hasPendingUpdates = this.minPendingLevel < this.levelCount; + } + // [VanillaCopy] LevelPropagator#propagateLevel(long, long, int, boolean) @Override public void propagateLevel(long sourceId, BlockState sourceState, long targetId, int level, boolean decrease) { diff --git a/src/main/java/me/jellysquid/mods/phosphor/mixin/chunk/light/MixinSkyLightStorage.java b/src/main/java/me/jellysquid/mods/phosphor/mixin/chunk/light/MixinSkyLightStorage.java index 2c60315a..5f63d63b 100644 --- a/src/main/java/me/jellysquid/mods/phosphor/mixin/chunk/light/MixinSkyLightStorage.java +++ b/src/main/java/me/jellysquid/mods/phosphor/mixin/chunk/light/MixinSkyLightStorage.java @@ -240,10 +240,23 @@ public void updateLight(ChunkLightProvider lightProvide return; } + this.lightChunks(lightProvider); + this.updateRemovedLightmaps(); + + this.hasUpdates = false; + } + + @Unique + private void lightChunks(final ChunkLightProvider lightProvider) { + if (this.initSkylightChunks.isEmpty()) { + return; + } + + final LevelPropagatorAccess levelPropagator = (LevelPropagatorAccess) lightProvider; + for (final LongIterator it = this.initSkylightChunks.iterator(); it.hasNext(); ) { final long chunkPos = it.nextLong(); - final LevelPropagatorAccess levelPropagator = (LevelPropagatorAccess) lightProvider; final int minY = this.fillSkylightColumn(lightProvider, chunkPos); this.enabledColumns.add(chunkPos); @@ -297,43 +310,47 @@ public void updateLight(ChunkLightProvider lightProvide } } + levelPropagator.checkForUpdates(); this.initSkylightChunks.clear(); + } - if (!this.removedLightmaps.isEmpty()) { - final LongSet removedLightmaps = new LongOpenHashSet(this.removedLightmaps); + @Unique + private void updateRemovedLightmaps() { + if (this.removedLightmaps.isEmpty()) { + return; + } - for (final LongIterator it = removedLightmaps.iterator(); it.hasNext(); ) { - final long sectionPos = it.nextLong(); + final LongSet removedLightmaps = new LongOpenHashSet(this.removedLightmaps); - if (!this.enabledChunks.contains(ChunkSectionPos.withZeroY(sectionPos))) { - continue; - } + for (final LongIterator it = removedLightmaps.iterator(); it.hasNext(); ) { + final long sectionPos = it.nextLong(); - if (!this.removedLightmaps.contains(sectionPos)) { - continue; - } + if (!this.enabledChunks.contains(ChunkSectionPos.withZeroY(sectionPos))) { + continue; + } - final long sectionPosAbove = this.getSectionAbove(sectionPos); + if (!this.removedLightmaps.contains(sectionPos)) { + continue; + } - if (sectionPosAbove == Long.MAX_VALUE) { - this.updateVanillaLightmapsBelow(sectionPos, this.isSectionEnabled(sectionPos) ? DIRECT_SKYLIGHT_MAP : null, true); - } else { - long removedLightmapPosAbove = sectionPos; + final long sectionPosAbove = this.getSectionAbove(sectionPos); - for (long pos = sectionPos; pos != sectionPosAbove; pos = ChunkSectionPos.offset(pos, Direction.UP)) { - if (this.removedLightmaps.remove(pos)) { - removedLightmapPosAbove = pos; - } - } + if (sectionPosAbove == Long.MAX_VALUE) { + this.updateVanillaLightmapsBelow(sectionPos, this.isSectionEnabled(sectionPos) ? DIRECT_SKYLIGHT_MAP : null, true); + } else { + long removedLightmapPosAbove = sectionPos; - this.updateVanillaLightmapsBelow(removedLightmapPosAbove, this.vanillaLightmapComplexities.get(sectionPosAbove) == 0 ? null : this.getLightSection(sectionPosAbove, true), false); + for (long pos = sectionPos; pos != sectionPosAbove; pos = ChunkSectionPos.offset(pos, Direction.UP)) { + if (this.removedLightmaps.remove(pos)) { + removedLightmapPosAbove = pos; + } } - } - this.removedLightmaps.clear(); + this.updateVanillaLightmapsBelow(removedLightmapPosAbove, this.vanillaLightmapComplexities.get(sectionPosAbove) == 0 ? null : this.getLightSection(sectionPosAbove, true), false); + } } - this.hasUpdates = false; + this.removedLightmaps.clear(); } /**