Skip to content

Commit 8c5be16

Browse files
committed
Only write chunk data to disk if it serializes without throwing
This ensures at least a valid version of the chunk exists on disk, even if outdated
1 parent 8c189d0 commit 8c5be16

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
3+
Date: Sun, 19 Dec 2021 09:13:41 -0800
4+
Subject: [PATCH] Only write chunk data to disk if it serializes without
5+
throwing
6+
7+
This ensures at least a valid version of the chunk exists
8+
on disk, even if outdated
9+
10+
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
11+
index 2dde10324e515bd58fc6ba7e93156ae783492cc2..c7216cf3317cbd49b032c44feb370c50928dd21e 100644
12+
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
13+
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
14+
@@ -298,10 +298,11 @@ public class RegionFileStorage implements AutoCloseable {
15+
NbtIo.write(nbt, (DataOutput) dataoutputstream);
16+
regionfile.setStatus(pos.x, pos.z, ChunkSerializer.getStatus(nbt)); // Paper - cache status on disk
17+
regionfile.setOversized(pos.x, pos.z, false); // Paper - We don't do this anymore, mojang stores differently, but clear old meta flag if it exists to get rid of our own meta file once last oversized is gone
18+
+ dataoutputstream.close(); // Paper - only write if successful
19+
} catch (Throwable throwable) {
20+
if (dataoutputstream != null) {
21+
try {
22+
- dataoutputstream.close();
23+
+ //dataoutputstream.close(); // Paper - don't write garbage data to disk if writing serialization fails
24+
} catch (Throwable throwable1) {
25+
throwable.addSuppressed(throwable1);
26+
}
27+
@@ -309,10 +310,7 @@ public class RegionFileStorage implements AutoCloseable {
28+
29+
throw throwable;
30+
}
31+
-
32+
- if (dataoutputstream != null) {
33+
- dataoutputstream.close();
34+
- }
35+
+ // Paper - move into try block to only write if successfully serialized
36+
}
37+
38+
// Paper start

0 commit comments

Comments
 (0)