Make starlight light read non-fatal if it throws

Brings behavior in line with the mod, we shouldn't kill the chunk
if the light data is corrupt, we can regenerate the light data
This commit is contained in:
Spottedleaf 2022-06-10 21:08:37 -07:00
parent 91cf4f0392
commit 1c4ca26d6e

View File

@ -5097,7 +5097,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- if (!flag2) { - if (!flag2) {
+ // Paper start - rewrite the light engine + // Paper start - rewrite the light engine
+ if (flag) { + if (flag) {
+ try {
+ if ((flag3 || flag4) && !flag2) { + if ((flag3 || flag4) && !flag2) {
+ // Paper end - rewrite the light engine
tasksToExecuteOnMain.add(() -> { // Paper - delay this task since we're executing off-main tasksToExecuteOnMain.add(() -> { // Paper - delay this task since we're executing off-main
lightengine.retainData(chunkPos, true); lightengine.retainData(chunkPos, true);
}); // Paper - delay this task since we're executing off-main }); // Paper - delay this task since we're executing off-main
@ -5112,11 +5114,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- lightengine.queueSectionData(LightLayer.BLOCK, SectionPos.of(chunkPos, b0), blockLight, true); - lightengine.queueSectionData(LightLayer.BLOCK, SectionPos.of(chunkPos, b0), blockLight, true);
- }); - });
- // Paper end - delay this task since we're executing off-main - // Paper end - delay this task since we're executing off-main
+ // Paper start - rewrite the light engine
+ // this is where our diff is + // this is where our diff is
+ blockNibbles[y - minSection] = new ca.spottedleaf.starlight.common.light.SWMRNibbleArray(sectionData.getByteArray("BlockLight").clone(), sectionData.getInt(BLOCKLIGHT_STATE_TAG)); // clone for data safety + blockNibbles[y - minSection] = new ca.spottedleaf.starlight.common.light.SWMRNibbleArray(sectionData.getByteArray("BlockLight").clone(), sectionData.getInt(BLOCKLIGHT_STATE_TAG)); // clone for data safety
+ } else { + } else {
+ blockNibbles[y - minSection] = new ca.spottedleaf.starlight.common.light.SWMRNibbleArray(null, sectionData.getInt(BLOCKLIGHT_STATE_TAG)); + blockNibbles[y - minSection] = new ca.spottedleaf.starlight.common.light.SWMRNibbleArray(null, sectionData.getInt(BLOCKLIGHT_STATE_TAG));
} }
+ // Paper end - rewrite the light engine
if (flag4) { if (flag4) {
- // Paper start - delay this task since we're executing off-main - // Paper start - delay this task since we're executing off-main
@ -5125,6 +5129,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
- lightengine.queueSectionData(LightLayer.SKY, SectionPos.of(chunkPos, b0), skyLight, true); - lightengine.queueSectionData(LightLayer.SKY, SectionPos.of(chunkPos, b0), skyLight, true);
- }); - });
- // Paper end - delay this task since we're executing off-mai - // Paper end - delay this task since we're executing off-mai
+ // Paper start - rewrite the light engine
+ // we store under the same key so mod programs editing nbt + // we store under the same key so mod programs editing nbt
+ // can still read the data, hopefully. + // can still read the data, hopefully.
+ // however, for compatibility we store chunks as unlit so vanilla + // however, for compatibility we store chunks as unlit so vanilla
@ -5134,6 +5139,12 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } else { + } else {
+ skyNibbles[y - minSection] = new ca.spottedleaf.starlight.common.light.SWMRNibbleArray(null, sectionData.getInt(SKYLIGHT_STATE_TAG)); + skyNibbles[y - minSection] = new ca.spottedleaf.starlight.common.light.SWMRNibbleArray(null, sectionData.getInt(SKYLIGHT_STATE_TAG));
} }
+ // Paper end - rewrite the light engine
+ // Paper start - rewrite the light engine
+ } catch (Exception ex) {
+ LOGGER.warn("Failed to load light data for chunk " + chunkPos + " in world '" + world.getWorld().getName() + "', light will be regenerated", ex);
+ flag = false;
+ }
+ // Paper end - rewrite light engine + // Paper end - rewrite light engine
} }
} }