Skip to content

Commit

Permalink
Refactor lighting code, fix loaded chunks (Minestom#2164)
Browse files Browse the repository at this point in the history
  • Loading branch information
iam4722202468 committed May 30, 2024
1 parent d46c626 commit 1c7fc6c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
22 changes: 14 additions & 8 deletions src/main/java/net/minestom/server/instance/LightingChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,15 @@ public void onGenerate() {
if (neighborChunk == null) continue;

if (neighborChunk instanceof LightingChunk light) {
if (light.doneInit) light.resendTimer.set(20);
if (light.doneInit) {
light.resendTimer.set(20);
light.invalidate();

for (int section = minSection; section < maxSection; section++) {
light.getSection(section).blockLight().invalidate();
light.getSection(section).skyLight().invalidate();
}
}
}
}
}
Expand Down Expand Up @@ -316,13 +324,6 @@ public void tick(long time) {

if (doneInit && resendTimer.get() > 0) {
if (resendTimer.decrementAndGet() == 0) {
invalidate();

for (int section = minSection; section < maxSection; section++) {
getSection(section).blockLight().invalidate();
getSection(section).skyLight().invalidate();
}

sendLighting();
}
}
Expand Down Expand Up @@ -520,4 +521,9 @@ private static Set<Chunk> relight(Instance instance, Set<Point> queue, LightType
lightingChunk.entries.putAll(entries);
return lightingChunk;
}

@Override
public boolean isLoaded() {
return super.isLoaded() && doneInit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ final class BlockLight implements Light {
private byte[] contentPropagation;
private byte[] contentPropagationSwap;

private AtomicBoolean isValidBorders = new AtomicBoolean(true);
private AtomicBoolean needsSend = new AtomicBoolean(false);
private final AtomicBoolean isValidBorders = new AtomicBoolean(true);
private final AtomicBoolean needsSend = new AtomicBoolean(false);

private Set<Point> toUpdateSet = new HashSet<>();
private final Section[] neighborSections = new Section[BlockFace.values().length];
Expand Down Expand Up @@ -202,7 +202,7 @@ public void set(byte[] copyArray) {
this.content = copyArray.clone();
this.contentPropagation = this.content;
this.isValidBorders.set(true);
this.needsSend.set(false);
this.needsSend.set(true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public void set(byte[] copyArray) {
this.content = copyArray.clone();
this.contentPropagation = this.content;
this.isValidBorders.set(true);
this.needsSend.set(false);
this.needsSend.set(true);
}

@Override
Expand Down

0 comments on commit 1c7fc6c

Please sign in to comment.