From e48774fd728fb0f01c5f76932f4f3fd7e99aa585 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Wed, 10 Aug 2022 08:07:49 -0700 Subject: [PATCH] Simple patch changes for chunk system Major ones soon --- patches/server/Not-implemeneted.patch | 43 +++++++++++++++++-- ...-data-to-disk-if-it-serializes-witho.patch | 14 +++++- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/patches/server/Not-implemeneted.patch b/patches/server/Not-implemeneted.patch index bf42d659fd..cf3d0385f2 100644 --- a/patches/server/Not-implemeneted.patch +++ b/patches/server/Not-implemeneted.patch @@ -14,7 +14,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +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..00000000000000000000000000000000 + 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..00000000000000000000000000000000 + + 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..00000000000000000000000000000000 + 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 diff --git a/patches/server/Only-write-chunk-data-to-disk-if-it-serializes-witho.patch b/patches/server/Only-write-chunk-data-to-disk-if-it-serializes-witho.patch index 8b12bec56d..7e0c992d66 100644 --- a/patches/server/Only-write-chunk-data-to-disk-if-it-serializes-witho.patch +++ b/patches/server/Only-write-chunk-data-to-disk-if-it-serializes-witho.patch @@ -11,6 +11,16 @@ diff --git a/src/main/java/net/minecraft/world/level/chunk/storage/RegionFile.ja index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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 +@@ -0,0 +0,0 @@ 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 { + @@ -0,0 +0,0 @@ public class RegionFile implements AutoCloseable { this.pos = chunkcoordintpair; } @@ -18,7 +28,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // 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 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @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);