Handle corrupt light data gracefully
First, if the light data is not marked as correct, we should not be parsing it in the first place. This will eliminate errors from parsing possibly different versioned light data. Secondly, if parsing the light data throws an exception (from the SWMRNibbleArray constructor), then we can simply mark the returned chunk as having incorrect light data - rather than propagating the exception and causing the chunk to be re-generated.
This commit is contained in:
@@ -33324,33 +33324,45 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ final ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray[] blockNibbles = ca.spottedleaf.moonrise.patches.starlight.light.StarLightEngine.getFilledEmptyLight(world);
|
||||
+ final ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray[] skyNibbles = ca.spottedleaf.moonrise.patches.starlight.light.StarLightEngine.getFilledEmptyLight(world);
|
||||
+
|
||||
+ for (final SerializableChunkData.SectionData sectionData : this.sectionData) {
|
||||
+ final int y = sectionData.y();
|
||||
+ final DataLayer blockLight = sectionData.blockLight();
|
||||
+ final DataLayer skyLight = sectionData.skyLight();
|
||||
+
|
||||
+ final int blockState = ((ca.spottedleaf.moonrise.patches.starlight.storage.StarlightSectionData)(Object)sectionData).starlight$getBlockLightState();
|
||||
+ final int skyState = ((ca.spottedleaf.moonrise.patches.starlight.storage.StarlightSectionData)(Object)sectionData).starlight$getSkyLightState();
|
||||
+
|
||||
+ if (blockState >= 0) {
|
||||
+ if (blockLight != null) {
|
||||
+ blockNibbles[y - minSection] = new ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray(ca.spottedleaf.moonrise.common.util.MixinWorkarounds.clone(blockLight.getData()), blockState); // clone for data safety
|
||||
+ } else {
|
||||
+ blockNibbles[y - minSection] = new ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray(null, blockState);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (skyState >= 0 && hasSkyLight) {
|
||||
+ if (skyLight != null) {
|
||||
+ skyNibbles[y - minSection] = new ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray(ca.spottedleaf.moonrise.common.util.MixinWorkarounds.clone(skyLight.getData()), skyState); // clone for data safety
|
||||
+ } else {
|
||||
+ skyNibbles[y - minSection] = new ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray(null, skyState);
|
||||
+ }
|
||||
+ }
|
||||
+ if (!this.lightCorrect) {
|
||||
+ ((ca.spottedleaf.moonrise.patches.starlight.chunk.StarlightChunk)ret).starlight$setBlockNibbles(blockNibbles);
|
||||
+ ((ca.spottedleaf.moonrise.patches.starlight.chunk.StarlightChunk)ret).starlight$setSkyNibbles(skyNibbles);
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ ((ca.spottedleaf.moonrise.patches.starlight.chunk.StarlightChunk)ret).starlight$setBlockNibbles(blockNibbles);
|
||||
+ ((ca.spottedleaf.moonrise.patches.starlight.chunk.StarlightChunk)ret).starlight$setSkyNibbles(skyNibbles);
|
||||
+ try {
|
||||
+ for (final SerializableChunkData.SectionData sectionData : this.sectionData) {
|
||||
+ final int y = sectionData.y();
|
||||
+ final DataLayer blockLight = sectionData.blockLight();
|
||||
+ final DataLayer skyLight = sectionData.skyLight();
|
||||
+
|
||||
+ final int blockState = ((ca.spottedleaf.moonrise.patches.starlight.storage.StarlightSectionData)(Object)sectionData).starlight$getBlockLightState();
|
||||
+ final int skyState = ((ca.spottedleaf.moonrise.patches.starlight.storage.StarlightSectionData)(Object)sectionData).starlight$getSkyLightState();
|
||||
+
|
||||
+ if (blockState >= 0) {
|
||||
+ if (blockLight != null) {
|
||||
+ blockNibbles[y - minSection] = new ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray(ca.spottedleaf.moonrise.common.util.MixinWorkarounds.clone(blockLight.getData()), blockState); // clone for data safety
|
||||
+ } else {
|
||||
+ blockNibbles[y - minSection] = new ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray(null, blockState);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ if (skyState >= 0 && hasSkyLight) {
|
||||
+ if (skyLight != null) {
|
||||
+ skyNibbles[y - minSection] = new ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray(ca.spottedleaf.moonrise.common.util.MixinWorkarounds.clone(skyLight.getData()), skyState); // clone for data safety
|
||||
+ } else {
|
||||
+ skyNibbles[y - minSection] = new ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray(null, skyState);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ ((ca.spottedleaf.moonrise.patches.starlight.chunk.StarlightChunk)ret).starlight$setBlockNibbles(blockNibbles);
|
||||
+ ((ca.spottedleaf.moonrise.patches.starlight.chunk.StarlightChunk)ret).starlight$setSkyNibbles(skyNibbles);
|
||||
+ } catch (final Throwable thr) {
|
||||
+ ret.setLightCorrect(false);
|
||||
+
|
||||
+ LOGGER.error("Failed to parse light data for chunk " + ret.getPos() + " in world '" + ca.spottedleaf.moonrise.common.util.WorldUtil.getWorldName(world) + "'", thr);
|
||||
+ }
|
||||
+
|
||||
+ return ret;
|
||||
+ }
|
||||
@@ -33410,21 +33422,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ final LevelChunkSection[] chunkSections = chunk.getSections();
|
||||
+ final ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray[] blockNibbles = ((ca.spottedleaf.moonrise.patches.starlight.chunk.StarlightChunk)chunk).starlight$getBlockNibbles();
|
||||
+ final ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray[] skyNibbles = ((ca.spottedleaf.moonrise.patches.starlight.chunk.StarlightChunk)chunk).starlight$getSkyNibbles();
|
||||
|
||||
- if (flag || nibblearray2 != null || nibblearray3 != null) {
|
||||
- LevelChunkSection chunksection = flag ? achunksection[j].copy() : null;
|
||||
+
|
||||
+ for (int lightSection = minLightSection; lightSection <= maxLightSection; ++lightSection) {
|
||||
+ final int lightSectionIdx = lightSection - minLightSection;
|
||||
+ final int blockSectionIdx = lightSection - minBlockSection;
|
||||
|
||||
- list.add(new SerializableChunkData.SectionData(i, chunksection, nibblearray2, nibblearray3));
|
||||
- if (flag || nibblearray2 != null || nibblearray3 != null) {
|
||||
- LevelChunkSection chunksection = flag ? achunksection[j].copy() : null;
|
||||
+ final LevelChunkSection chunkSection = (blockSectionIdx >= 0 && blockSectionIdx < chunkSections.length) ? chunkSections[blockSectionIdx].copy() : null;
|
||||
+ final ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray.SaveState blockNibble = blockNibbles[lightSectionIdx].getSaveState();
|
||||
+ final ca.spottedleaf.moonrise.patches.starlight.light.SWMRNibbleArray.SaveState skyNibble = skyNibbles[lightSectionIdx].getSaveState();
|
||||
+
|
||||
|
||||
- list.add(new SerializableChunkData.SectionData(i, chunksection, nibblearray2, nibblearray3));
|
||||
+ if (chunkSection == null && blockNibble == null && skyNibble == null) {
|
||||
+ continue;
|
||||
+ }
|
||||
}
|
||||
+
|
||||
+ final SerializableChunkData.SectionData sectionData = new SerializableChunkData.SectionData(
|
||||
+ lightSection, chunkSection,
|
||||
@@ -33434,7 +33446,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+ if (blockNibble != null) {
|
||||
+ ((ca.spottedleaf.moonrise.patches.starlight.storage.StarlightSectionData)(Object)sectionData).starlight$setBlockLightState(blockNibble.state);
|
||||
}
|
||||
+ }
|
||||
+
|
||||
+ if (skyNibble != null) {
|
||||
+ ((ca.spottedleaf.moonrise.patches.starlight.storage.StarlightSectionData)(Object)sectionData).starlight$setSkyLightState(skyNibble.state);
|
||||
|
||||
Reference in New Issue
Block a user