You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -1447,7 +1447,7 @@ public final class MoonriseRegionFileIO {
17
+
18
+
public abstract void finishWrite(final int chunkX, final int chunkZ, final WriteData writeData) throws IOException;
19
+
20
+
- public static record ReadData(ReadResult result, DataInputStream input, CompoundTag syncRead) {
21
+
+ public static record ReadData(ReadResult result, DataInputStream input, CompoundTag syncRead, int recalculateCount) { // Paper - Attempt to recalculate regionfile header if it is corrupt
@@ -137,6 +156,8 @@ index dea2823a9d1d69dcb0a4759d8ea9b3015ede20dc..0c41177462cca5c4bbab6490e323b953
137
156
+ return false;
138
157
+ }
139
158
+ synchronized (this) {
159
+
+ this.recalculateCount.getAndIncrement();
160
+
+
140
161
+ LOGGER.warn("Corrupt regionfile header detected! Attempting to re-calculate header offsets for regionfile " + this.path.toAbsolutePath(), new Throwable());
141
162
+
142
163
+ // try to backup file so maybe it could be sent to us for further investigation
@@ -401,15 +422,15 @@ index dea2823a9d1d69dcb0a4759d8ea9b3015ede20dc..0c41177462cca5c4bbab6490e323b953
401
422
// Paper start - rewrite chunk system
402
423
@Override
403
424
public final ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.WriteData moonrise$startWrite(final net.minecraft.nbt.CompoundTag data, final ChunkPos pos) throws IOException {
404
-
@@ -74,6 +423,7 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
425
+
@@ -74,6 +431,7 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
405
426
throw new IllegalArgumentException("Expected directory, got " + externalFileDir.toAbsolutePath());
406
427
} else {
407
428
this.externalFileDir = externalFileDir;
408
429
+ this.canRecalcHeader = RegionFileStorage.isChunkDataFolder(this.externalFileDir); // Paper - add can recalc flag
409
430
this.offsets = this.header.asIntBuffer();
410
431
this.offsets.limit(1024);
411
432
this.header.position(4096);
412
-
@@ -94,11 +444,13 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
433
+
@@ -94,11 +452,13 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
413
434
414
435
long size = Files.size(path);
415
436
@@ -426,7 +447,7 @@ index dea2823a9d1d69dcb0a4759d8ea9b3015ede20dc..0c41177462cca5c4bbab6490e323b953
426
447
// Spigot start
427
448
if (numSectors == 255) {
428
449
// We're maxed out, so we need to read the proper length from the section
429
-
@@ -109,18 +461,62 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
450
+
@@ -109,18 +469,62 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
430
451
// Spigot end
431
452
if (sectorNumber < 2) {
432
453
LOGGER.warn("Region file {} has invalid sector at index: {}; sector {} overlaps with header", path, i1, sectorNumber);
@@ -493,7 +514,7 @@ index dea2823a9d1d69dcb0a4759d8ea9b3015ede20dc..0c41177462cca5c4bbab6490e323b953
493
514
}
494
515
}
495
516
}
496
-
@@ -130,10 +526,35 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
517
+
@@ -130,10 +534,35 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
+ ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.ReadData.ReadResult.NO_DATA, null, null, regionFile == null ? 0 : regionFile.getRecalculateCount() // Paper - Attempt to recalculate regionfile header if it is corrupt
687
+
);
688
+
}
689
+
690
+
final ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.ReadData ret = new ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.ReadData(
+ ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.ReadData.ReadResult.HAS_DATA, input, null, regionFile.getRecalculateCount() // Paper - Attempt to recalculate regionfile header if it is corrupt
693
+
);
694
+
695
+
if (!(input instanceof ca.spottedleaf.moonrise.patches.chunk_system.util.stream.ExternalChunkStreamMarker)) {
696
+
@@ -190,7 +220,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
697
+
}
698
+
699
+
return new ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.ReadData(
+ ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.ReadData.ReadResult.SYNC_READ, null, syncRead, regionFile.getRecalculateCount() // Paper - Attempt to recalculate regionfile header if it is corrupt
702
+
);
703
+
}
704
+
705
+
@@ -200,7 +230,32 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
706
+
final int chunkX, final int chunkZ, final ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.ReadData readData
707
+
) throws IOException {
708
+
try {
709
+
- return NbtIo.read(readData.input());
710
+
+ // Paper start - Attempt to recalculate regionfile header if it is corrupt
711
+
+ final CompoundTag ret = NbtIo.read(readData.input());
712
+
+ if (!this.isChunkData) {
713
+
+ return ret;
714
+
+ }
715
+
+
716
+
+ final ChunkPos pos = new ChunkPos(chunkX, chunkZ);
717
+
+ final ChunkPos headerChunkPos = SerializableChunkData.getChunkCoordinate(ret);
718
+
+ final RegionFile regionFile = this.getRegionFile(pos);
719
+
+
720
+
+ if (regionFile.getRecalculateCount() != readData.recalculateCount()) {
721
+
+ return null;
722
+
+ }
723
+
+
724
+
+ if (!headerChunkPos.equals(pos)) {
725
+
+ LOGGER.error("Attempting to read chunk data at " + pos + " but got chunk data for " + headerChunkPos + " instead! Attempting regionfile recalculation " + regionFile.getPath().toAbsolutePath());
0 commit comments