mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 02:25:28 +01:00
Simple patch changes for chunk system
Major ones soon
This commit is contained in:
parent
2cab6963a7
commit
2a74071bcb
@ -7,14 +7,16 @@ Currently a placeholder patch.
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/util/TickThread.java b/src/main/java/io/papermc/paper/util/TickThread.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..c92f7e59f490f7b289325d9cc2bf7c2cf1750c7a
|
||||
index 0000000000000000000000000000000000000000..be130b03ca116fd6d104df26c32312db1655b09e
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/util/TickThread.java
|
||||
@@ -0,0 +1,41 @@
|
||||
@@ -0,0 +1,78 @@
|
||||
+package io.papermc.paper.util;
|
||||
+
|
||||
+import net.minecraft.server.MinecraftServer;
|
||||
+import net.minecraft.world.entity.Entity;
|
||||
+import org.bukkit.Bukkit;
|
||||
+import java.util.concurrent.atomic.AtomicInteger;
|
||||
+
|
||||
+public final class TickThread extends Thread {
|
||||
+
|
||||
@ -33,9 +35,22 @@ index 0000000000000000000000000000000000000000..c92f7e59f490f7b289325d9cc2bf7c2c
|
||||
+ ensureTickThread(reason);
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ public static void ensureTickThread(final String reason) {
|
||||
+ if (!Bukkit.isPrimaryThread()) {
|
||||
+ if (!isTickThread()) {
|
||||
+ MinecraftServer.LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable());
|
||||
+ throw new IllegalStateException(reason);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public static void ensureTickThread(final int chunkX, final int chunkZ, final String reason) {
|
||||
+ if (!isTickThreadFor(chunkX, chunkZ)) {
|
||||
+ MinecraftServer.LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable());
|
||||
+ throw new IllegalStateException(reason);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ public static void ensureTickThread(final Entity entity, final String reason) {
|
||||
+ if (!isTickThreadFor(entity.chunkPosition().x, entity.chunkPosition().z)) {
|
||||
+ MinecraftServer.LOGGER.error("Thread " + Thread.currentThread().getName() + " failed main thread check: " + reason, new Throwable());
|
||||
+ throw new IllegalStateException(reason);
|
||||
+ }
|
||||
@ -43,7 +58,17 @@ index 0000000000000000000000000000000000000000..c92f7e59f490f7b289325d9cc2bf7c2c
|
||||
+
|
||||
+ public final int id; /* We don't override getId as the spec requires that it be unique (with respect to all other threads) */
|
||||
+
|
||||
+ public TickThread(final Runnable run, final String name, final int id) {
|
||||
+ private static final AtomicInteger ID_GENERATOR = new AtomicInteger();
|
||||
+
|
||||
+ public TickThread(final String name) {
|
||||
+ this(null, name);
|
||||
+ }
|
||||
+
|
||||
+ public TickThread(final Runnable run, final String name) {
|
||||
+ this(run, name, ID_GENERATOR.incrementAndGet());
|
||||
+ }
|
||||
+
|
||||
+ private TickThread(final Runnable run, final String name, final int id) {
|
||||
+ super(run, name);
|
||||
+ this.id = id;
|
||||
+ }
|
||||
@ -51,6 +76,18 @@ index 0000000000000000000000000000000000000000..c92f7e59f490f7b289325d9cc2bf7c2c
|
||||
+ public static TickThread getCurrentTickThread() {
|
||||
+ return (TickThread)Thread.currentThread();
|
||||
+ }
|
||||
+
|
||||
+ public static boolean isTickThread() {
|
||||
+ return Bukkit.isPrimaryThread();
|
||||
+ }
|
||||
+
|
||||
+ public static boolean isTickThreadFor(final int chunkX, final int chunkZ) {
|
||||
+ return Bukkit.isPrimaryThread();
|
||||
+ }
|
||||
+
|
||||
+ public static boolean isTickThreadFor(final Entity entity) {
|
||||
+ return Bukkit.isPrimaryThread();
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/spigotmc/AsyncCatcher.java b/src/main/java/org/spigotmc/AsyncCatcher.java
|
||||
index bbf0d9d9c44fe8d7add2f978994ec129420814c7..78669fa035b7537ff7e533cf32aaf2995625424f 100644
|
||||
|
@ -8,17 +8,27 @@ This ensures at least a valid version of the chunk exists
|
||||
on disk, even if outdated
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
|
||||
index 8ff8855c5267379b3a5f5d8baa4a275ffee2c4bf..6704ae5c2ee01f8b319f4d425fe08c16d7b1b212 100644
|
||||
index 8ff8855c5267379b3a5f5d8baa4a275ffee2c4bf..fc3442b4c7e1f22080fe6bf36d4fade162d6709e 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.java
|
||||
@@ -1019,6 +1019,24 @@ public class RegionFile implements AutoCloseable {
|
||||
@@ -1004,6 +1004,9 @@ public class RegionFile implements AutoCloseable {
|
||||
}
|
||||
|
||||
}
|
||||
+
|
||||
+ public static final int MAX_CHUNK_SIZE = 500 * 1024 * 1024; // Paper - don't write garbage data to disk if writing serialization fails
|
||||
+
|
||||
// Paper end
|
||||
private class ChunkBuffer extends ByteArrayOutputStream {
|
||||
|
||||
@@ -1019,6 +1022,24 @@ public class RegionFile implements AutoCloseable {
|
||||
this.pos = chunkcoordintpair;
|
||||
}
|
||||
|
||||
+ // Paper start - don't write garbage data to disk if writing serialization fails
|
||||
+ @Override
|
||||
+ public void write(final int b) {
|
||||
+ if (this.count > 500_000_000) {
|
||||
+ if (this.count > MAX_CHUNK_SIZE) {
|
||||
+ throw new RegionFileStorage.RegionFileSizeException("Region file too large: " + this.count);
|
||||
+ }
|
||||
+ super.write(b);
|
||||
@ -26,7 +36,7 @@ index 8ff8855c5267379b3a5f5d8baa4a275ffee2c4bf..6704ae5c2ee01f8b319f4d425fe08c16
|
||||
+
|
||||
+ @Override
|
||||
+ public void write(final byte[] b, final int off, final int len) {
|
||||
+ if (this.count + len > 500_000_000) {
|
||||
+ if (this.count + len > MAX_CHUNK_SIZE) {
|
||||
+ throw new RegionFileStorage.RegionFileSizeException("Region file too large: " + (this.count + len));
|
||||
+ }
|
||||
+ super.write(b, off, len);
|
||||
|
Loading…
Reference in New Issue
Block a user