mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
409 lines
26 KiB
Diff
409 lines
26 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: violetc <58360096+s-yh-china@users.noreply.github.com>
|
|
Date: Wed, 5 Feb 2025 22:04:41 +0800
|
|
Subject: [PATCH] More Region Format Support
|
|
|
|
|
|
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/io/ChunkSystemRegionFileStorage.java b/ca/spottedleaf/moonrise/patches/chunk_system/io/ChunkSystemRegionFileStorage.java
|
|
index a814512fcfb85312474ae2c2c21443843bf57831..2b0349568f38321c893a8ffa16607350ac64a599 100644
|
|
--- 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);
|
|
+ public org.leavesmc.leaves.region.IRegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ); // Leaves - more region format
|
|
|
|
- public RegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException;
|
|
+ public org.leavesmc.leaves.region.IRegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException; // Leaves - more region format
|
|
|
|
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
|
|
index f5ed467c0880e4bcdf1b9ae773a5aac21c4381c3..349741f48bf21777b640a4698a0ae8da0b2487c5 100644
|
|
--- a/ca/spottedleaf/moonrise/patches/chunk_system/io/MoonriseRegionFileIO.java
|
|
+++ b/ca/spottedleaf/moonrise/patches/chunk_system/io/MoonriseRegionFileIO.java
|
|
@@ -1260,7 +1260,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);
|
|
+ final org.leavesmc.leaves.region.IRegionFile regionFile = this.regionDataController.getCache().moonrise$getRegionFileIfLoaded(this.chunkX, this.chunkZ); // Leaves - more region format
|
|
if (regionFile != null) {
|
|
regionFile.flush();
|
|
} // else: evicted from cache, which should have called flush
|
|
@@ -1470,7 +1470,7 @@ public final class MoonriseRegionFileIO {
|
|
|
|
public static interface IORunnable {
|
|
|
|
- public void run(final RegionFile regionFile) throws IOException;
|
|
+ public void run(final org.leavesmc.leaves.region.IRegionFile regionFile) throws IOException; // Leaves - more region format
|
|
|
|
}
|
|
}
|
|
diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/storage/ChunkSystemChunkBuffer.java b/ca/spottedleaf/moonrise/patches/chunk_system/storage/ChunkSystemChunkBuffer.java
|
|
index 51c126735ace8fdde89ad97b5cab62f244212db0..a6573e327ace16b7ea320eb1440ffcbc09c7a0fd 100644
|
|
--- 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;
|
|
+ public void moonrise$write(final org.leavesmc.leaves.region.IRegionFile regionFile) throws IOException; // Leaves - more region format
|
|
}
|
|
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
|
|
index 25087f470db918dbca3ec582581d02822e5ff17d..7813085bec9f4b3a88ed2394ddc781ad7cf72439 100644
|
|
--- a/net/minecraft/server/MinecraftServer.java
|
|
+++ b/net/minecraft/server/MinecraftServer.java
|
|
@@ -944,10 +944,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
|
// CraftBukkit end
|
|
if (flush) {
|
|
for (ServerLevel serverLevel2 : this.getAllLevels()) {
|
|
- LOGGER.info("ThreadedAnvilChunkStorage ({}): All chunks are saved", serverLevel2.getChunkSource().chunkMap.getStorageName());
|
|
+ LOGGER.info("ThreadedChunkStorage ({}): All chunks are saved", serverLevel2.getChunkSource().chunkMap.getStorageName()); // Leaves - more region format
|
|
}
|
|
|
|
- LOGGER.info("ThreadedAnvilChunkStorage: All dimensions are saved");
|
|
+ LOGGER.info("ThreadedChunkStorage: All dimensions are saved"); // Leaves - more region format
|
|
}
|
|
|
|
return flag;
|
|
diff --git a/net/minecraft/util/worldupdate/WorldUpgrader.java b/net/minecraft/util/worldupdate/WorldUpgrader.java
|
|
index 79d57ca8a7870a02e95562d89cbd4341d8282660..ddb9296b6caac97079943812bcf1ef58a7c04e76 100644
|
|
--- a/net/minecraft/util/worldupdate/WorldUpgrader.java
|
|
+++ b/net/minecraft/util/worldupdate/WorldUpgrader.java
|
|
@@ -75,7 +75,7 @@ public class WorldUpgrader implements AutoCloseable {
|
|
volatile int skipped;
|
|
final Reference2FloatMap<ResourceKey<Level>> progressMap = Reference2FloatMaps.synchronize(new Reference2FloatOpenHashMap<>());
|
|
volatile Component status = Component.translatable("optimizeWorld.stage.counting");
|
|
- static final Pattern REGEX = Pattern.compile("^r\\.(-?[0-9]+)\\.(-?[0-9]+)\\.mca$");
|
|
+ static final Pattern REGEX = org.leavesmc.leaves.region.IRegionFileFactory.getRegionFileRegex(); // Leaves - more region format
|
|
final DimensionDataStorage overworldDataStorage;
|
|
|
|
public WorldUpgrader(
|
|
@@ -272,7 +272,7 @@ public class WorldUpgrader implements AutoCloseable {
|
|
}
|
|
|
|
private static List<WorldUpgrader.FileToUpgrade> getAllChunkPositions(RegionStorageInfo regionStorageInfo, Path path) {
|
|
- File[] files = path.toFile().listFiles((directory, filename) -> filename.endsWith(".mca"));
|
|
+ File[] files = path.toFile().listFiles((directory, filename) -> org.leavesmc.leaves.region.IRegionFileFactory.isRegionFile(filename)); // Leaves - more region format
|
|
if (files == null) {
|
|
return List.of();
|
|
} else {
|
|
@@ -285,7 +285,7 @@ public class WorldUpgrader implements AutoCloseable {
|
|
int i1 = Integer.parseInt(matcher.group(2)) << 5;
|
|
List<ChunkPos> list1 = Lists.newArrayList();
|
|
|
|
- try (RegionFile regionFile = new RegionFile(regionStorageInfo, file.toPath(), path, true)) {
|
|
+ try (org.leavesmc.leaves.region.IRegionFile regionFile = org.leavesmc.leaves.region.IRegionFileFactory.createRegionFile(regionStorageInfo, file.toPath(), path, true)) { // Leaves - more region format
|
|
for (int i2 = 0; i2 < 32; i2++) {
|
|
for (int i3 = 0; i3 < 32; i3++) {
|
|
ChunkPos chunkPos = new ChunkPos(i2 + i, i3 + i1);
|
|
@@ -333,7 +333,7 @@ public class WorldUpgrader implements AutoCloseable {
|
|
|
|
protected abstract boolean tryProcessOnePosition(T chunkStorage, ChunkPos chunkPos, ResourceKey<Level> dimension);
|
|
|
|
- private void onFileFinished(RegionFile regionFile) {
|
|
+ private void onFileFinished(org.leavesmc.leaves.region.IRegionFile regionFile) { // Leaves - more region format
|
|
if (WorldUpgrader.this.recreateRegionFiles) {
|
|
if (this.previousWriteFuture != null) {
|
|
this.previousWriteFuture.join();
|
|
@@ -438,7 +438,7 @@ public class WorldUpgrader implements AutoCloseable {
|
|
}
|
|
}
|
|
|
|
- record FileToUpgrade(RegionFile file, List<ChunkPos> chunksToUpgrade) {
|
|
+ record FileToUpgrade(org.leavesmc.leaves.region.IRegionFile file, List<ChunkPos> chunksToUpgrade) { // Leaves - more region format
|
|
}
|
|
|
|
class PoiUpgrader extends WorldUpgrader.SimpleRegionStorageUpgrader {
|
|
diff --git a/net/minecraft/world/level/chunk/storage/RegionFile.java b/net/minecraft/world/level/chunk/storage/RegionFile.java
|
|
index 22f3aa1674664906e8ec45372d758d79017e3987..1d9b2a315d3c18df3c0dfc0e8daac18c4d7462b7 100644
|
|
--- 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.util.profiling.jfr.JvmProfiler;
|
|
import net.minecraft.world.level.ChunkPos;
|
|
import org.slf4j.Logger;
|
|
|
|
-public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patches.chunk_system.storage.ChunkSystemRegionFile { // Paper - rewrite chunk system
|
|
+public class RegionFile implements org.leavesmc.leaves.region.IRegionFile { // Paper - rewrite chunk system // Leaves - more region format
|
|
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 {
|
|
+ public boolean recalculateHeader() throws IOException { // Leaves - more region format
|
|
if (!this.canRecalcHeader) {
|
|
return false;
|
|
}
|
|
@@ -794,7 +794,7 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
|
|
}
|
|
}
|
|
|
|
- protected synchronized void write(ChunkPos chunkPos, ByteBuffer chunkData) throws IOException {
|
|
+ public synchronized void write(ChunkPos chunkPos, ByteBuffer chunkData) throws IOException { // Leaves - more region format
|
|
int offsetIndex = getOffsetIndex(chunkPos);
|
|
int i = this.offsets.get(offsetIndex);
|
|
int sectorNumber = getSectorNumber(i);
|
|
@@ -912,7 +912,7 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
|
|
}
|
|
|
|
@Override
|
|
- public final void moonrise$write(final RegionFile regionFile) throws IOException {
|
|
+ public final void moonrise$write(final org.leavesmc.leaves.region.IRegionFile regionFile) throws IOException { // Leaves - more region format
|
|
regionFile.write(this.pos, ByteBuffer.wrap(this.buf, 0, this.count));
|
|
}
|
|
// Paper end - rewrite chunk system
|
|
@@ -978,11 +978,11 @@ public class RegionFile implements AutoCloseable, ca.spottedleaf.moonrise.patche
|
|
return (x & 31) + (z & 31) * 32;
|
|
}
|
|
|
|
- synchronized boolean isOversized(int x, int z) {
|
|
+ public synchronized boolean isOversized(int x, int z) { // Leaves - more region format
|
|
return this.oversized[getChunkIndex(x, z)] == 1;
|
|
}
|
|
|
|
- synchronized void setOversized(int x, int z, boolean oversized) throws IOException {
|
|
+ public synchronized void setOversized(int x, int z, boolean oversized) throws IOException { // Leaves - more region format
|
|
final int offset = getChunkIndex(x, z);
|
|
boolean previous = this.oversized[offset] == 1;
|
|
this.oversized[offset] = (byte) (oversized ? 1 : 0);
|
|
@@ -1021,7 +1021,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 {
|
|
+ public synchronized net.minecraft.nbt.CompoundTag getOversizedData(int x, int z) throws IOException { // Leaves - more region format
|
|
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
|
|
index 384f2cd090d6d23bd1308d6e82c24338f2bf55d1..7b86212082f49bef0c087c8e080874fe1d4f268d 100644
|
|
--- a/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
|
|
+++ b/net/minecraft/world/level/chunk/storage/RegionFileStorage.java
|
|
@@ -18,7 +18,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;
|
|
- public final Long2ObjectLinkedOpenHashMap<RegionFile> regionCache = new Long2ObjectLinkedOpenHashMap<>();
|
|
+ public final Long2ObjectLinkedOpenHashMap<org.leavesmc.leaves.region.IRegionFile> regionCache = new Long2ObjectLinkedOpenHashMap<>(); // Leaves - more region format
|
|
private final RegionStorageInfo info;
|
|
private final Path folder;
|
|
private final boolean sync;
|
|
@@ -33,7 +33,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")) {
|
|
+ if (!fileName.startsWith("r.") || !org.leavesmc.leaves.region.IRegionFileFactory.isRegionFile(fileName)) { // Leaves - more region format
|
|
return null;
|
|
}
|
|
|
|
@@ -54,7 +54,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
|
|
}
|
|
// Paper end
|
|
// Paper start - rewrite chunk system
|
|
- private static final int REGION_SHIFT = 5;
|
|
+ public static final int REGION_SHIFT = 5; // Leaves - private -> public
|
|
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) {
|
|
@@ -93,15 +93,15 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
|
|
}
|
|
|
|
@Override
|
|
- public synchronized final RegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ) {
|
|
+ public synchronized final org.leavesmc.leaves.region.IRegionFile moonrise$getRegionFileIfLoaded(final int chunkX, final int chunkZ) { // Leaves - more region format
|
|
return this.regionCache.getAndMoveToFirst(ChunkPos.asLong(chunkX >> REGION_SHIFT, chunkZ >> REGION_SHIFT));
|
|
}
|
|
|
|
@Override
|
|
- public synchronized final RegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException {
|
|
+ public synchronized final org.leavesmc.leaves.region.IRegionFile moonrise$getRegionFileIfExists(final int chunkX, final int chunkZ) throws IOException { // Leaves - more region format
|
|
final long key = ChunkPos.asLong(chunkX >> REGION_SHIFT, chunkZ >> REGION_SHIFT);
|
|
|
|
- RegionFile ret = this.regionCache.getAndMoveToFirst(key);
|
|
+ org.leavesmc.leaves.region.IRegionFile ret = this.regionCache.getAndMoveToFirst(key);
|
|
if (ret != null) {
|
|
return ret;
|
|
}
|
|
@@ -114,18 +114,28 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
|
|
this.regionCache.removeLast().close();
|
|
}
|
|
|
|
- final Path regionPath = this.folder.resolve(getRegionFileName(chunkX, chunkZ));
|
|
+ // Leaves start - more region format
|
|
+ Path regionPath = null;
|
|
+ for (String fileName : org.leavesmc.leaves.region.IRegionFileFactory.getRegionFileName(chunkX, chunkZ)) {
|
|
+ regionPath = this.folder.resolve(fileName);
|
|
+ if (java.nio.file.Files.exists(regionPath)) {
|
|
+ break;
|
|
+ } else {
|
|
+ regionPath = null;
|
|
+ }
|
|
+ }
|
|
|
|
- if (!java.nio.file.Files.exists(regionPath)) {
|
|
+ if (regionPath == null) {
|
|
this.markNonExisting(key);
|
|
return null;
|
|
}
|
|
+ // Leaves end - more region format
|
|
|
|
this.createRegionFile(key);
|
|
|
|
FileUtil.createDirectoriesSafe(this.folder);
|
|
|
|
- ret = new RegionFile(this.info, regionPath, this.folder, this.sync);
|
|
+ ret = org.leavesmc.leaves.region.IRegionFileFactory.createRegionFile(this.info, regionPath, this.folder, this.sync); // Leaves - more region format
|
|
|
|
this.regionCache.putAndMoveToFirst(key, ret);
|
|
|
|
@@ -144,7 +154,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
|
|
}
|
|
|
|
final ChunkPos pos = new ChunkPos(chunkX, chunkZ);
|
|
- final RegionFile regionFile = this.getRegionFile(pos);
|
|
+ final org.leavesmc.leaves.region.IRegionFile regionFile = this.getRegionFile(pos); // Leaves - more region format
|
|
|
|
// 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)
|
|
@@ -178,7 +188,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);
|
|
+ final org.leavesmc.leaves.region.IRegionFile regionFile = this.moonrise$getRegionFileIfExists(chunkX, chunkZ); // Leaves - more region format
|
|
if (regionFile != null) {
|
|
regionFile.clear(pos);
|
|
} // else: didn't exist
|
|
@@ -193,7 +203,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);
|
|
+ final org.leavesmc.leaves.region.IRegionFile regionFile = this.moonrise$getRegionFileIfExists(chunkX, chunkZ); // Leaves - more region format
|
|
|
|
final DataInputStream input = regionFile == null ? null : regionFile.getChunkDataInputStream(new ChunkPos(chunkX, chunkZ));
|
|
|
|
@@ -238,7 +248,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);
|
|
+ final org.leavesmc.leaves.region.IRegionFile regionFile = this.getRegionFile(pos);
|
|
|
|
if (regionFile.getRecalculateCount() != readData.recalculateCount()) {
|
|
return null;
|
|
@@ -262,7 +272,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
|
|
}
|
|
// Paper end - rewrite chunk system
|
|
// Paper start - rewrite chunk system
|
|
- public RegionFile getRegionFile(ChunkPos chunkcoordintpair) throws IOException {
|
|
+ public org.leavesmc.leaves.region.IRegionFile getRegionFile(ChunkPos chunkcoordintpair) throws IOException { // Leaves - more region format
|
|
return this.getRegionFile(chunkcoordintpair, false);
|
|
}
|
|
// Paper end - rewrite chunk system
|
|
@@ -274,7 +284,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
|
|
this.isChunkData = isChunkDataFolder(this.folder); // Paper - recalculate region file headers
|
|
}
|
|
|
|
- @org.jetbrains.annotations.Contract("_, false -> !null") @Nullable private RegionFile getRegionFile(ChunkPos chunkPos, boolean existingOnly) throws IOException { // CraftBukkit
|
|
+ @org.jetbrains.annotations.Contract("_, false -> !null") @Nullable private org.leavesmc.leaves.region.IRegionFile getRegionFile(ChunkPos chunkPos, boolean existingOnly) throws IOException { // CraftBukkit // Leaves - more region format
|
|
// Paper start - rewrite chunk system
|
|
if (existingOnly) {
|
|
return this.moonrise$getRegionFileIfExists(chunkPos.x, chunkPos.z);
|
|
@@ -282,7 +292,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
|
|
synchronized (this) {
|
|
final long key = ChunkPos.asLong(chunkPos.x >> REGION_SHIFT, chunkPos.z >> REGION_SHIFT);
|
|
|
|
- RegionFile ret = this.regionCache.getAndMoveToFirst(key);
|
|
+ org.leavesmc.leaves.region.IRegionFile ret = this.regionCache.getAndMoveToFirst(key); // Leaves - more region format
|
|
if (ret != null) {
|
|
return ret;
|
|
}
|
|
@@ -291,13 +301,22 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
|
|
this.regionCache.removeLast().close();
|
|
}
|
|
|
|
- final Path regionPath = this.folder.resolve(getRegionFileName(chunkPos.x, chunkPos.z));
|
|
+ // Leaves start - more region format
|
|
+ Path regionPath = this.folder.resolve(org.leavesmc.leaves.region.IRegionFileFactory.getFirstRegionFileName(chunkPos.x, chunkPos.z));
|
|
+ for (String fileName : org.leavesmc.leaves.region.IRegionFileFactory.getRegionFileName(chunkPos.x, chunkPos.z)) {
|
|
+ Path newRegionPath = this.folder.resolve(fileName);
|
|
+ if (java.nio.file.Files.exists(newRegionPath)) {
|
|
+ regionPath = newRegionPath;
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+ // Leaves end - more region format
|
|
|
|
this.createRegionFile(key);
|
|
|
|
FileUtil.createDirectoriesSafe(this.folder);
|
|
|
|
- ret = new RegionFile(this.info, regionPath, this.folder, this.sync);
|
|
+ ret = org.leavesmc.leaves.region.IRegionFileFactory.createRegionFile(this.info, regionPath, this.folder, this.sync); // Leaves - more region format
|
|
|
|
this.regionCache.putAndMoveToFirst(key, ret);
|
|
|
|
@@ -311,7 +330,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
|
|
org.apache.logging.log4j.LogManager.getLogger().fatal(msg + " (" + file.toString().replaceAll(".+[\\\\/]", "") + " - " + x + "," + z + ") Go clean it up to remove this message. /minecraft:tp " + (x<<4)+" 128 "+(z<<4) + " - 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.");
|
|
}
|
|
|
|
- private static CompoundTag readOversizedChunk(RegionFile regionfile, ChunkPos chunkCoordinate) throws IOException {
|
|
+ private static CompoundTag readOversizedChunk(org.leavesmc.leaves.region.IRegionFile regionfile, ChunkPos chunkCoordinate) throws IOException { // Leaves - more region format
|
|
synchronized (regionfile) {
|
|
try (DataInputStream datainputstream = regionfile.getChunkDataInputStream(chunkCoordinate)) {
|
|
CompoundTag oversizedData = regionfile.getOversizedData(chunkCoordinate.x, chunkCoordinate.z);
|
|
@@ -346,7 +365,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
|
|
@Nullable
|
|
public CompoundTag read(ChunkPos chunkPos) throws IOException {
|
|
// CraftBukkit start - SPIGOT-5680: There's no good reason to preemptively create files on read, save that for writing
|
|
- RegionFile regionFile = this.getRegionFile(chunkPos, true);
|
|
+ org.leavesmc.leaves.region.IRegionFile regionFile = this.getRegionFile(chunkPos, true); // Leaves - more region format
|
|
if (regionFile == null) {
|
|
return null;
|
|
}
|
|
@@ -385,7 +404,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
|
|
|
|
public void scanChunk(ChunkPos chunkPos, StreamTagVisitor visitor) throws IOException {
|
|
// CraftBukkit start - SPIGOT-5680: There's no good reason to preemptively create files on read, save that for writing
|
|
- RegionFile regionFile = this.getRegionFile(chunkPos, true);
|
|
+ org.leavesmc.leaves.region.IRegionFile regionFile = this.getRegionFile(chunkPos, true); // Leaves - more region format
|
|
if (regionFile == null) {
|
|
return;
|
|
}
|
|
@@ -399,7 +418,7 @@ public class RegionFileStorage implements AutoCloseable, ca.spottedleaf.moonrise
|
|
}
|
|
|
|
public void write(ChunkPos chunkPos, @Nullable CompoundTag chunkData) throws IOException { // Paper - rewrite chunk system - public
|
|
- RegionFile regionFile = this.getRegionFile(chunkPos, chunkData == null); // CraftBukkit // Paper - rewrite chunk system
|
|
+ org.leavesmc.leaves.region.IRegionFile regionFile = this.getRegionFile(chunkPos, chunkData == null); // CraftBukkit // Paper - rewrite chunk system // Leaves - more region format
|
|
// Paper start - rewrite chunk system
|
|
if (regionFile == null) {
|
|
// if the RegionFile doesn't exist, no point in deleting from it
|
|
@@ -429,7 +448,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()) {
|
|
+ for (final org.leavesmc.leaves.region.IRegionFile regionFile : this.regionCache.values()) { // Leaves - more region format
|
|
try {
|
|
regionFile.close();
|
|
} catch (final IOException ex) {
|
|
@@ -445,7 +464,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()) {
|
|
+ for (final org.leavesmc.leaves.region.IRegionFile regionFile : this.regionCache.values()) { // Leaves - more region format
|
|
try {
|
|
regionFile.flush();
|
|
} catch (final IOException ex) {
|