From 1abc111403c61d83d1920e6ab954fecd97497995 Mon Sep 17 00:00:00 2001
From: Astralchroma <astralchroma@proton.me>
Date: Thu, 27 Oct 2022 22:19:31 +0100
Subject: [PATCH] Configurable Region Compression Format

---
 .../level/chunk/storage/RegionFile.java.patch  |  9 +++++++++
 .../chunk/storage/RegionFileVersion.java.patch | 18 ++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 paper-server/patches/sources/net/minecraft/world/level/chunk/storage/RegionFileVersion.java.patch

diff --git a/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/RegionFile.java.patch b/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/RegionFile.java.patch
index 22f16d1b64..3955a59294 100644
--- a/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/RegionFile.java.patch
+++ b/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/RegionFile.java.patch
@@ -5,6 +5,15 @@
  package net.minecraft.world.level.chunk.storage;
  
  import com.google.common.annotations.VisibleForTesting;
+@@ -49,7 +50,7 @@
+     protected final RegionBitmap usedSectors;
+ 
+     public RegionFile(RegionStorageInfo storageKey, Path directory, Path path, boolean dsync) throws IOException {
+-        this(storageKey, directory, path, RegionFileVersion.getSelected(), dsync);
++        this(storageKey, directory, path, RegionFileVersion.getCompressionFormat(), dsync); // Paper - Configurable region compression format
+     }
+ 
+     public RegionFile(RegionStorageInfo storageKey, Path path, Path directory, RegionFileVersion compressionFormat, boolean dsync) throws IOException {
 @@ -63,8 +64,8 @@
          } else {
              this.externalFileDir = directory;
diff --git a/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/RegionFileVersion.java.patch b/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/RegionFileVersion.java.patch
new file mode 100644
index 0000000000..65bf070d12
--- /dev/null
+++ b/paper-server/patches/sources/net/minecraft/world/level/chunk/storage/RegionFileVersion.java.patch
@@ -0,0 +1,18 @@
+--- a/net/minecraft/world/level/chunk/storage/RegionFileVersion.java
++++ b/net/minecraft/world/level/chunk/storage/RegionFileVersion.java
+@@ -58,6 +58,15 @@
+     private final RegionFileVersion.StreamWrapper<InputStream> inputWrapper;
+     private final RegionFileVersion.StreamWrapper<OutputStream> outputWrapper;
+ 
++    // Paper start - Configurable region compression format
++    public static RegionFileVersion getCompressionFormat() {
++        return switch (io.papermc.paper.configuration.GlobalConfiguration.get().unsupportedSettings.compressionFormat) {
++            case GZIP -> VERSION_GZIP;
++            case ZLIB -> VERSION_DEFLATE;
++            case NONE -> VERSION_NONE;
++        };
++    }
++    // Paper end - Configurable region compression format
+     private RegionFileVersion(
+         int id,
+         @Nullable String name,