Files
Shiroha/shiroha-server/minecraft-patches/features/0002-Configurable-region-format-framework.patch
T

389 lines
26 KiB
Diff
Raw Normal View History

2026-07-09 00:03:09 +08:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MrHua269 <mrhua269@gmail.com>
Date: Wed, 8 Jul 2026 21:50:30 +0800
Subject: [PATCH] Configurable region format framework
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/io/ChunkSystemRegionFileStorage.java b/ca/spottedleaf/moonrise/patches/chunk_system/io/ChunkSystemRegionFileStorage.java
2026-07-14 15:09:17 +08:00
index a814512fcfb85312474ae2c2c21443843bf57831..2d5d63fa32e92cc2ef62bc66c54b2f4a75d8417a 100644
2026-07-09 00:03:09 +08:00
--- a/ca/spottedleaf/moonrise/patches/chunk_system/io/ChunkSystemRegionFileStorage.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/io/ChunkSystemRegionFileStorage.java
@@ -8,9 +8,9 @@ public interface ChunkSystemRegionFileStorage {
public boolean moonrise$doesRegionFileNotExistNoIO(final int chunkX, final int chunkZ);
- public RegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ);
2026-07-14 12:22:17 +08:00
+ public io.nanachiyo0721.shiroha.data.RegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
- public RegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException;
2026-07-14 12:22:17 +08:00
+ public io.nanachiyo0721.shiroha.data.RegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException; // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
public MoonriseRegionFileIO.RegionDataController.WriteData moonrise$startWrite(
final int chunkX, final int chunkZ, final CompoundTag compound
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/io/MoonriseRegionFileIO.java b/ca/spottedleaf/moonrise/patches/chunk_system/io/MoonriseRegionFileIO.java
2026-07-14 15:09:17 +08:00
index 3bb9b58ee97464687e348e23b99159226415c267..1700c84c3a494c019b8a4ef43b909a148c71c977 100644
2026-07-09 00:03:09 +08:00
--- a/ca/spottedleaf/moonrise/patches/chunk_system/io/MoonriseRegionFileIO.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/io/MoonriseRegionFileIO.java
@@ -1273,7 +1273,7 @@ public final class MoonriseRegionFileIO {
this.regionDataController.finishWrite(this.chunkX, this.chunkZ, writeData);
// Paper start - flush regionfiles on save
if (this.world.paperConfig().chunks.flushRegionsOnSave) {
- final RegionFile regionFile = this.regionDataController.getCache().moonrise$getRegionFileIfLoaded(this.chunkX, this.chunkZ);
2026-07-14 12:22:17 +08:00
+ final io.nanachiyo0721.shiroha.data.RegionFile regionFile = this.regionDataController.getCache().moonrise$getRegionFileIfLoaded(this.chunkX, this.chunkZ); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
if (regionFile != null) {
regionFile.flush();
} // else: evicted from cache, which should have called flush
@@ -1489,7 +1489,7 @@ public final class MoonriseRegionFileIO {
public static interface IORunnable {
- public void run(final RegionFile regionFile) throws IOException;
2026-07-14 12:22:17 +08:00
+ public void run(final io.nanachiyo0721.shiroha.data.RegionFile regionFile) throws IOException; // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
}
}
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/storage/ChunkSystemChunkBuffer.java b/ca/spottedleaf/moonrise/patches/chunk_system/storage/ChunkSystemChunkBuffer.java
2026-07-14 15:09:17 +08:00
index 51c126735ace8fdde89ad97b5cab62f244212db0..a2816add1137b05cba8ba0f4581df9598dd31d47 100644
2026-07-09 00:03:09 +08:00
--- a/ca/spottedleaf/moonrise/patches/chunk_system/storage/ChunkSystemChunkBuffer.java
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/storage/ChunkSystemChunkBuffer.java
@@ -8,5 +8,5 @@ public interface ChunkSystemChunkBuffer {
public void moonrise$setWriteOnClose(final boolean value);
- public void moonrise$write(final RegionFile regionFile) throws IOException;
2026-07-14 12:22:17 +08:00
+ public void moonrise$write(final io.nanachiyo0721.shiroha.data.RegionFile regionFile) throws IOException; // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
}
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 28a90b03bde5e2aafefe8d9a20160ef5e4c7e3e9..743b12af380c7026e741abd43f227f52207a5342 100644
2026-07-09 00:03:09 +08:00
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -986,10 +986,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
if (flush) {
for (ServerLevel level : this.getAllLevels()) {
String storageName = level.getChunkSource().chunkMap.getStorageName();
- LOGGER.info("ThreadedAnvilChunkStorage ({}): All chunks are saved", LEGACY_WORLD_NAMES_FOR_REALMS_LOG.getOrDefault(storageName, storageName));
2026-07-14 11:32:51 +08:00
+ LOGGER.info("ThreadedChunkStorage ({}): All chunks are saved", LEGACY_WORLD_NAMES_FOR_REALMS_LOG.getOrDefault(storageName, storageName)); // Shiroha - Configurable region format
2026-07-09 00:03:09 +08:00
}
- LOGGER.info("ThreadedAnvilChunkStorage: All dimensions are saved");
2026-07-14 11:32:51 +08:00
+ LOGGER.info("ThreadedChunkStorage: All dimensions are saved"); // Shiroha - configurable region format
2026-07-09 00:03:09 +08:00
}
return result;
diff --git a/net/minecraft/util/worldupdate/FileToUpgrade.java b/net/minecraft/util/worldupdate/FileToUpgrade.java
2026-07-14 15:09:17 +08:00
index a7f2cfa9277c898038f6b9e0a3401db51012b64c..fe2b2e13691193763a78f5efb78b14ac61c075e2 100644
2026-07-09 00:03:09 +08:00
--- a/net/minecraft/util/worldupdate/FileToUpgrade.java
+++ b/net/minecraft/util/worldupdate/FileToUpgrade.java
@@ -4,5 +4,5 @@ import java.util.List;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.storage.RegionFile;
-public record FileToUpgrade(RegionFile file, List<ChunkPos> chunksToUpgrade) {
2026-07-14 12:22:17 +08:00
+public record FileToUpgrade(io.nanachiyo0721.shiroha.data.RegionFile file, List<ChunkPos> chunksToUpgrade) { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
}
diff --git a/net/minecraft/util/worldupdate/RegionStorageUpgrader.java b/net/minecraft/util/worldupdate/RegionStorageUpgrader.java
2026-07-14 15:09:17 +08:00
index b228cd6c54e8c8998923ab332882d99092769c67..c41e6f8607134274268e4f1866d1b20f5681acb5 100644
2026-07-09 00:03:09 +08:00
--- a/net/minecraft/util/worldupdate/RegionStorageUpgrader.java
+++ b/net/minecraft/util/worldupdate/RegionStorageUpgrader.java
@@ -36,7 +36,7 @@ import org.slf4j.Logger;
public class RegionStorageUpgrader {
private static final Logger LOGGER = LogUtils.getLogger();
private static final String NEW_DIRECTORY_PREFIX = "new_";
- private static final Pattern REGEX = Pattern.compile("^r\\.(-?[0-9]+)\\.(-?[0-9]+)\\.mca$");
2026-07-14 12:22:17 +08:00
+ private static final Pattern REGEX = Pattern.compile("^r\\.(-?[0-9]+)\\.(-?[0-9]+)\\." + io.nanachiyo0721.shiroha.config.modules.function.RegionFormatConfig.regionFormat.getArgument() + "$"); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
private final DataFixer dataFixer;
private final UpgradeProgress upgradeProgress;
private final String type;
@@ -176,7 +176,8 @@ public class RegionStorageUpgrader {
int zOffset = Integer.parseInt(regex.group(2)) << 5;
List<ChunkPos> chunkPositions = Lists.newArrayList();
- try (RegionFile regionSource = new RegionFile(info, regionFile.toPath(), regionFolder, true)) {
2026-07-14 12:22:17 +08:00
+ var regionFileInfo = new io.nanachiyo0721.shiroha.utils.RegionCreatorInfo(info, regionFile.toPath(), regionFolder, true); // Shiroha - Configurable region file format
+ try (io.nanachiyo0721.shiroha.data.RegionFile regionSource = io.nanachiyo0721.shiroha.config.modules.function.RegionFormatConfig.regionFormat.getCreator().newFile(regionFileInfo)) { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
for (int x = 0; x < 32; x++) {
for (int z = 0; z < 32; z++) {
ChunkPos pos = new ChunkPos(x + xOffset, z + zOffset);
@@ -253,7 +254,7 @@ public class RegionStorageUpgrader {
return storage.upgradeChunkTag(chunkTag, this.defaultVersion, this.dataFixContextTag, targetVersion);
}
- private void onFileFinished(final RegionFile regionFile) {
2026-07-14 12:22:17 +08:00
+ private void onFileFinished(final io.nanachiyo0721.shiroha.data.RegionFile regionFile) { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
if (this.recreateRegionFiles) {
if (this.previousWriteFuture != null) {
this.previousWriteFuture.join();
diff --git a/net/minecraft/world/level/chunk/storage/RegionFile.java b/net/minecraft/world/level/chunk/storage/RegionFile.java
2026-07-14 15:09:17 +08:00
index 3de7fd2b084c38e72d7a6bc416880a881f514ad3..5816dd6438e84bf298cd93eb5b2ab2a25a975d3e 100644
2026-07-09 00:03:09 +08:00
--- a/net/minecraft/world/level/chunk/storage/RegionFile.java
+++ b/net/minecraft/world/level/chunk/storage/RegionFile.java
@@ -22,7 +22,7 @@ import net.minecraft.world.level.ChunkPos;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
-public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patches.chunk_system.storage.ChunkSystemRegionFile { // Paper - rewrite chunk system
2026-07-14 12:22:17 +08:00
+public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patches.chunk_system.storage.ChunkSystemRegionFile , io.nanachiyo0721.shiroha.data.RegionFile{ // Paper - rewrite chunk system // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
private static final Logger LOGGER = LogUtils.getLogger();
public static final int MAX_CHUNK_SIZE = 500 * 1024 * 1024; // Paper - don't write garbage data to disk if writing serialization fails
private static final int SECTOR_BYTES = 4096;
@@ -130,7 +130,7 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
return this.recalculateCount.get();
}
- boolean recalculateHeader() throws IOException {
2026-07-14 11:32:51 +08:00
+ public boolean recalculateHeader() throws IOException { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
if (!this.canRecalcHeader) {
return false;
}
@@ -789,7 +789,7 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
}
}
- protected synchronized void write(final ChunkPos pos, final ByteBuffer data) throws IOException {
2026-07-14 11:32:51 +08:00
+ public synchronized void write(final ChunkPos pos, final ByteBuffer data) throws IOException { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
int offsetIndex = getOffsetIndex(pos);
int offset = this.offsets.get(offsetIndex);
int sectorNumber = getSectorNumber(offset);
@@ -907,7 +907,7 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
}
@Override
- public final void moonrise$write(final RegionFile regionFile) throws IOException {
2026-07-14 12:22:17 +08:00
+ public final void moonrise$write(final io.nanachiyo0721.shiroha.data.RegionFile regionFile) throws IOException { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
regionFile.write(this.pos, ByteBuffer.wrap(this.buf, 0, this.count));
}
// Paper end - rewrite chunk system
@@ -973,11 +973,11 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
return (x & 31) + (z & 31) * 32;
}
- synchronized boolean isOversized(int x, int z) {
2026-07-14 11:32:51 +08:00
+ public synchronized boolean isOversized(int x, int z) { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
return this.oversized[getChunkIndex(x, z)] == 1;
}
- synchronized void setOversized(int x, int z, boolean oversized) throws IOException {
2026-07-14 11:32:51 +08:00
+ public synchronized void setOversized(int x, int z, boolean oversized) throws IOException { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
final int offset = getChunkIndex(x, z);
boolean previous = this.oversized[offset] == 1;
this.oversized[offset] = (byte) (oversized ? 1 : 0);
@@ -1016,7 +1016,7 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
return this.path.getParent().resolve(this.path.getFileName().toString().replaceAll("\\.mca$", "") + "_oversized_" + x + "_" + z + ".nbt");
}
- synchronized net.minecraft.nbt.CompoundTag getOversizedData(int x, int z) throws IOException {
2026-07-14 11:32:51 +08:00
+ public synchronized net.minecraft.nbt.CompoundTag getOversizedData(int x, int z) throws IOException { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
Path file = getOversizedFile(x, z);
try (DataInputStream out = new DataInputStream(new java.io.BufferedInputStream(new java.util.zip.InflaterInputStream(Files.newInputStream(file))))) {
return net.minecraft.nbt.NbtIo.read((java.io.DataInput) out);
diff --git a/net/minecraft/world/level/chunk/storage/RegionFileStorage.java b/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
2026-07-14 15:09:17 +08:00
index 63b40c420030d935bb81a219fb33defe0946e21f..182ebe94bce57a65e1947f4f96a93d15f7c7d02f 100644
2026-07-09 00:03:09 +08:00
--- a/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
+++ b/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
@@ -19,7 +19,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
private static final org.slf4j.Logger LOGGER = com.mojang.logging.LogUtils.getLogger(); // Paper
public static final String ANVIL_EXTENSION = ".mca";
private static final int MAX_CACHE_SIZE = 256;
- private final Long2ObjectLinkedOpenHashMap<RegionFile> regionCache = new Long2ObjectLinkedOpenHashMap<>();
2026-07-14 12:22:17 +08:00
+ private final Long2ObjectLinkedOpenHashMap<io.nanachiyo0721.shiroha.data.RegionFile> regionCache = new Long2ObjectLinkedOpenHashMap<>(); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
private final RegionStorageInfo info;
private final Path folder;
private final boolean sync;
@@ -30,7 +30,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
@Nullable
public static ChunkPos getRegionFileCoordinates(Path file) {
String fileName = file.getFileName().toString();
- if (!fileName.startsWith("r.") || !fileName.endsWith(".mca")) {
2026-07-14 11:32:51 +08:00
+ if (!fileName.startsWith("r.") || !fileName.endsWith(getExtensionName())) { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
return null;
}
@@ -55,8 +55,32 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
private static final int MAX_NON_EXISTING_CACHE = 1024 * 4;
private final it.unimi.dsi.fastutil.longs.LongLinkedOpenHashSet nonExistingRegionFiles = new it.unimi.dsi.fastutil.longs.LongLinkedOpenHashSet();
private static String getRegionFileName(final int chunkX, final int chunkZ) {
- return "r." + (chunkX >> REGION_SHIFT) + "." + (chunkZ >> REGION_SHIFT) + ".mca";
2026-07-14 11:32:51 +08:00
+ return "r." + (chunkX >> REGION_SHIFT) + "." + (chunkZ >> REGION_SHIFT) + getExtensionName(); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
}
2026-07-14 11:32:51 +08:00
+ // Shiroha start - Configurable region file format
2026-07-14 12:22:17 +08:00
+ public static io.nanachiyo0721.shiroha.data.RegionFile createNew(RegionStorageInfo info, Path filePath, Path folder, boolean sync) throws IOException{
+ final io.nanachiyo0721.shiroha.enums.EnumRegionFormat regionFormat = io.nanachiyo0721.shiroha.config.modules.function.RegionFormatConfig.regionFormat;
2026-07-09 00:03:09 +08:00
+ final String fullFileName = filePath.getFileName().toString();
+ final String[] fullNameSplit = fullFileName.split("\\.");
+ final String extensionName = fullNameSplit[fullNameSplit.length - 1];
+
+ if (!regionFormat.getArgument().equalsIgnoreCase(extensionName)) {
+ // raise a delayed crash
+ io.papermc.paper.threadedregions.RegionizedServer.getInstance().addTask(() -> {
+ throw new RuntimeException("Invalid region file format: " + extensionName + " expected " + regionFormat.getArgument());
+ });
+
+
+ throw new IOException("Invalid region file format: " + extensionName + " expected " + regionFormat.getArgument());
+ }
+
2026-07-14 12:22:17 +08:00
+ return regionFormat.getCreator().newFile(new io.nanachiyo0721.shiroha.utils.RegionCreatorInfo(info, filePath, folder, sync));
2026-07-09 00:03:09 +08:00
+ }
+
+ public static String getExtensionName() {
2026-07-14 12:22:17 +08:00
+ return "." + io.nanachiyo0721.shiroha.config.modules.function.RegionFormatConfig.regionFormat.getArgument();
2026-07-09 00:03:09 +08:00
+ }
2026-07-14 11:32:51 +08:00
+ // Shiroha end
2026-07-09 00:03:09 +08:00
private boolean doesRegionFilePossiblyExist(final long position) {
synchronized (this.nonExistingRegionFiles) {
@@ -90,15 +114,15 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
}
@Override
- public synchronized final RegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ) {
2026-07-14 12:22:17 +08:00
+ public synchronized final io.nanachiyo0721.shiroha.data.RegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ) { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
return this.regionCache.getAndMoveToFirst(ChunkPos.pack(chunkX >> REGION_SHIFT, chunkZ >> REGION_SHIFT));
}
@Override
- public synchronized final RegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException {
2026-07-14 12:22:17 +08:00
+ public synchronized final io.nanachiyo0721.shiroha.data.RegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
final long key = ChunkPos.pack(chunkX >> REGION_SHIFT, chunkZ >> REGION_SHIFT);
- RegionFile ret = this.regionCache.getAndMoveToFirst(key);
2026-07-14 12:22:17 +08:00
+ io.nanachiyo0721.shiroha.data.RegionFile ret = this.regionCache.getAndMoveToFirst(key); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
if (ret != null) {
return ret;
}
@@ -124,7 +148,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
FileUtil.createDirectoriesSafe(this.folder);
- ret = new RegionFile(this.info, regionPath, this.folder, this.sync);
2026-07-14 11:32:51 +08:00
+ ret = this.createNew(this.info, regionPath, this.folder, this.sync); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
this.regionCache.putAndMoveToFirst(key, ret);
@@ -143,7 +167,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
}
final ChunkPos pos = new ChunkPos(chunkX, chunkZ);
- final RegionFile regionFile = this.getRegionFile(pos);
2026-07-14 12:22:17 +08:00
+ final io.nanachiyo0721.shiroha.data.RegionFile regionFile = this.getRegionFile(pos); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
// note: not required to keep regionfile loaded after this call, as the write param takes a regionfile as input
// (and, the regionfile parameter is unused for writing until the write call)
@@ -177,7 +201,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
) throws IOException {
final ChunkPos pos = new ChunkPos(chunkX, chunkZ);
if (writeData.result() == ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.WriteData.WriteResult.DELETE) {
- final RegionFile regionFile = this.moonrise$getRegionFileIfExists(chunkX, chunkZ);
2026-07-14 12:22:17 +08:00
+ final io.nanachiyo0721.shiroha.data.RegionFile regionFile = this.moonrise$getRegionFileIfExists(chunkX, chunkZ); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
if (regionFile != null) {
regionFile.clear(pos);
} // else: didn't exist
@@ -192,7 +216,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
public final ca.spottedleaf.moonrise.patches.chunk_system.io.MoonriseRegionFileIO.RegionDataController.ReadData moonrise$readData(
final int chunkX, final int chunkZ
) throws IOException {
- final RegionFile regionFile = this.moonrise$getRegionFileIfExists(chunkX, chunkZ);
2026-07-14 12:22:17 +08:00
+ final io.nanachiyo0721.shiroha.data.RegionFile regionFile = this.moonrise$getRegionFileIfExists(chunkX, chunkZ); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
final DataInputStream input = regionFile == null ? null : regionFile.getChunkDataInputStream(new ChunkPos(chunkX, chunkZ));
@@ -237,7 +261,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
final ChunkPos pos = new ChunkPos(chunkX, chunkZ);
final ChunkPos headerChunkPos = SerializableChunkData.getChunkCoordinate(ret);
- final RegionFile regionFile = this.getRegionFile(pos);
2026-07-14 12:22:17 +08:00
+ final io.nanachiyo0721.shiroha.data.RegionFile regionFile = this.getRegionFile(pos); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
if (regionFile.getRecalculateCount() != readData.recalculateCount()) {
return null;
@@ -261,7 +285,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
}
// Paper end - rewrite chunk system
// Paper start - rewrite chunk system
- public RegionFile getRegionFile(ChunkPos pos) throws IOException {
2026-07-14 12:22:17 +08:00
+ public io.nanachiyo0721.shiroha.data.RegionFile getRegionFile(ChunkPos pos) throws IOException { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
return this.getRegionFile(pos, false);
}
// Paper end - rewrite chunk system
@@ -273,7 +297,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
this.isChunkData = info.dfuType()[0] == net.minecraft.util.datafix.DataFixTypes.CHUNK; // Paper - recalculate region file headers
}
- @org.jetbrains.annotations.Contract("_, false -> !null") private @Nullable RegionFile getRegionFile(final ChunkPos pos, boolean existingOnly) throws IOException { // CraftBukkit
2026-07-14 12:22:17 +08:00
+ @org.jetbrains.annotations.Contract("_, false -> !null") private io.nanachiyo0721.shiroha.data.RegionFile getRegionFile(final ChunkPos pos, boolean existingOnly) throws IOException { // CraftBukkit // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
// Paper start - rewrite chunk system
if (existingOnly) {
return this.moonrise$getRegionFileIfExists(pos.x(), pos.z());
@@ -281,7 +305,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
synchronized (this) {
final long key = ChunkPos.pack(pos.x() >> REGION_SHIFT, pos.z() >> REGION_SHIFT);
- RegionFile ret = this.regionCache.getAndMoveToFirst(key);
2026-07-14 12:22:17 +08:00
+ io.nanachiyo0721.shiroha.data.RegionFile ret = this.regionCache.getAndMoveToFirst(key); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
if (ret != null) {
return ret;
}
@@ -298,7 +322,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
FileUtil.createDirectoriesSafe(this.folder);
- ret = new RegionFile(this.info, regionPath, this.folder, this.sync);
2026-07-14 11:32:51 +08:00
+ ret = this.createNew(this.info, regionPath, this.folder, this.sync); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
this.regionCache.putAndMoveToFirst(key, ret);
@@ -312,7 +336,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
LOGGER.error("{} ({} - {},{}) Go clean it up to remove this message. /minecraft:tp {} 128 {} - DO NOT REPORT THIS TO PAPER - You may ask for help on Discord, but do not file an issue. These error messages can not be removed.", msg, file.toString().replaceAll(".+[\\\\/]", ""), x, z, x << 4, z << 4);
}
- private static CompoundTag readOversizedChunk(RegionFile regionfile, ChunkPos chunkCoordinate) throws IOException {
2026-07-14 12:22:17 +08:00
+ private static CompoundTag readOversizedChunk(io.nanachiyo0721.shiroha.data.RegionFile regionfile, ChunkPos chunkCoordinate) throws IOException { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
synchronized (regionfile) {
try (DataInputStream datainputstream = regionfile.getChunkDataInputStream(chunkCoordinate)) {
CompoundTag oversizedData = regionfile.getOversizedData(chunkCoordinate.x(), chunkCoordinate.z());
@@ -346,7 +370,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
public @Nullable CompoundTag read(final ChunkPos pos) throws IOException {
// CraftBukkit start - SPIGOT-5680: There's no good reason to preemptively create files on read, save that for writing
- RegionFile region = this.getRegionFile(pos, true);
2026-07-14 12:22:17 +08:00
+ io.nanachiyo0721.shiroha.data.RegionFile region = this.getRegionFile(pos, true); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
if (region == null) {
return null;
}
@@ -383,7 +407,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
public void scanChunk(final ChunkPos pos, final StreamTagVisitor scanner) throws IOException {
// CraftBukkit start - SPIGOT-5680: There's no good reason to preemptively create files on read, save that for writing
- RegionFile region = this.getRegionFile(pos, true);
2026-07-14 12:22:17 +08:00
+ io.nanachiyo0721.shiroha.data.RegionFile region = this.getRegionFile(pos, true); // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
if (region == null) {
return;
}
@@ -398,7 +422,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
public void write(final ChunkPos pos, final @Nullable CompoundTag value) throws IOException {
if (!SharedConstants.DEBUG_DONT_SAVE_WORLD) {
- RegionFile region = this.getRegionFile(pos, value == null); // CraftBukkit // Paper - rewrite chunk system
2026-07-14 12:22:17 +08:00
+ io.nanachiyo0721.shiroha.data.RegionFile region = this.getRegionFile(pos, value == null); // CraftBukkit // Paper - rewrite chunk system // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
// Paper start - rewrite chunk system
if (region == null) {
// if the RegionFile doesn't exist, no point in deleting from it
@@ -430,7 +454,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
// Paper start - rewrite chunk system
synchronized (this) {
final ExceptionCollector<IOException> exceptionCollector = new ExceptionCollector<>();
- for (final RegionFile regionFile : this.regionCache.values()) {
2026-07-14 12:22:17 +08:00
+ for (final io.nanachiyo0721.shiroha.data.RegionFile regionFile : this.regionCache.values()) { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
try {
regionFile.close();
} catch (final IOException ex) {
@@ -446,7 +470,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
// Paper start - rewrite chunk system
synchronized (this) {
final ExceptionCollector<IOException> exceptionCollector = new ExceptionCollector<>();
- for (final RegionFile regionFile : this.regionCache.values()) {
2026-07-14 12:22:17 +08:00
+ for (final io.nanachiyo0721.shiroha.data.RegionFile regionFile : this.regionCache.values()) { // Shiroha - Configurable region file format
2026-07-09 00:03:09 +08:00
try {
regionFile.flush();
} catch (final IOException ex) {