Skip to content

Commit

Permalink
fix: missing skylight for some chunks
Browse files Browse the repository at this point in the history
Add missing checkForUpdates() call in lightChunks()
  • Loading branch information
PhiProven committed Feb 12, 2021
1 parent 4c43554 commit 31a4fd2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

public interface LevelPropagatorAccess {
void invokePropagateLevel(long sourceId, long targetId, int level, boolean decrease);

void checkForUpdates();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,23 @@ public void updateLight(ChunkLightProvider<SkyLightStorage.Data, ?> lightProvide
return;
}

this.lightChunks(lightProvider);
this.updateRemovedLightmaps();

this.hasUpdates = false;
}

@Unique
private void lightChunks(final ChunkLightProvider<SkyLightStorage.Data, ?> 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);
Expand Down Expand Up @@ -297,43 +310,47 @@ public void updateLight(ChunkLightProvider<SkyLightStorage.Data, ?> 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();
}

/**
Expand Down

0 comments on commit 31a4fd2

Please sign in to comment.