2019-04-05 04:52:02 +00:00
From cd9e9e53a805dc38a57d7f7dfcb939e2edc2f8b9 Mon Sep 17 00:00:00 2001
2018-07-15 01:53:17 +00:00
From: Aikar <aikar@aikar.co>
Date: Sat, 13 Sep 2014 23:14:43 -0400
Subject: [PATCH] Configurable Keep Spawn Loaded range per world
This lets you disable it for some worlds and lower it for others.
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2019-04-05 04:52:02 +00:00
index d190e5228..cd8ee8df8 100644
2018-07-15 01:53:17 +00:00
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
2019-04-05 04:52:02 +00:00
@@ -257,4 +257,10 @@ public class PaperWorldConfig {
2018-07-15 01:53:17 +00:00
grassUpdateRate = Math.max(0, getInt("grass-spread-tick-rate", grassUpdateRate));
log("Grass Spread Tick Rate: " + grassUpdateRate);
}
+
+ public short keepLoadedRange;
+ private void keepLoadedRange() {
+ keepLoadedRange = (short) (getInt("keep-spawn-loaded-range", Math.min(spigotConfig.viewDistance, 8)) * 16);
+ log( "Keep Spawn Loaded Range: " + (keepLoadedRange/16));
+ }
}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2019-04-05 04:52:02 +00:00
index ee45d3705..01c5d3c57 100644
2018-07-15 01:53:17 +00:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2019-01-06 17:15:21 +00:00
@@ -486,13 +486,21 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
2019-01-01 03:15:55 +00:00
List<ChunkCoordIntPair> list = Lists.newArrayList();
Set<ChunkCoordIntPair> set = Sets.newConcurrentHashSet();
2018-07-15 01:53:17 +00:00
- for (int i = -192; i <= 192 && this.isRunning(); i += 16) {
- for (int j = -192; j <= 192 && this.isRunning(); j += 16) {
+ // Paper start
+ short radius = worldserver.paperConfig.keepLoadedRange;
+ for (int i = -radius; i <= radius && this.isRunning(); i += 16) {
+ for (int j = -radius; j <= radius && this.isRunning(); j += 16) {
+ // Paper end
2019-01-01 03:15:55 +00:00
list.add(new ChunkCoordIntPair(blockposition.getX() + i >> 4, blockposition.getZ() + j >> 4));
2018-07-15 01:53:17 +00:00
}
2018-07-22 23:53:01 +00:00
+ } // Paper
2018-07-23 09:24:51 +00:00
+ if (this.isRunning()) { // Paper
2019-01-01 03:15:55 +00:00
+ int expected = list.size(); // Paper
2018-07-22 23:53:01 +00:00
+
2019-01-01 03:15:55 +00:00
CompletableFuture completablefuture = worldserver.getChunkProvider().a((Iterable) list, (chunk) -> {
2018-07-22 23:53:01 +00:00
set.add(chunk.getPos());
+ if (set.size() < expected && set.size() % 25 == 0) this.a(new ChatMessage("menu.preparingSpawn", new Object[0]), set.size() * 100 / expected); // Paper
});
while (!completablefuture.isDone()) {
2019-01-06 17:15:21 +00:00
@@ -507,11 +515,11 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
2018-07-22 23:53:01 +00:00
throw new RuntimeException(executionexception.getCause());
} catch (TimeoutException timeoutexception) {
- this.a(new ChatMessage("menu.preparingSpawn", new Object[0]), set.size() * 100 / 625);
+ this.a(new ChatMessage("menu.preparingSpawn", new Object[0]), set.size() * 100 / expected); // Paper
}
}
- this.a(new ChatMessage("menu.preparingSpawn", new Object[0]), set.size() * 100 / 625);
+ this.a(new ChatMessage("menu.preparingSpawn", new Object[0]), set.size() * 100 / expected); // Paper
}
}
2018-07-15 01:53:17 +00:00
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2019-04-05 04:52:02 +00:00
index 2e8485859..d77992640 100644
2018-07-15 01:53:17 +00:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2019-02-03 15:34:04 +00:00
@@ -2852,8 +2852,9 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
2018-07-15 01:53:17 +00:00
int k = i * 16 + 8 - blockposition.getX();
int l = j * 16 + 8 - blockposition.getZ();
boolean flag = true;
+ short keepLoadedRange = paperConfig.keepLoadedRange; // Paper
- return k >= -128 && k <= 128 && l >= -128 && l <= 128 && this.keepSpawnInMemory; // CraftBukkit - Added 'this.keepSpawnInMemory'
+ return k >= -keepLoadedRange && k <= keepLoadedRange && l >= -keepLoadedRange && l <= keepLoadedRange && this.keepSpawnInMemory; // CraftBukkit - Added 'this.keepSpawnInMemory' // Paper - Re-add range var
}
2018-08-26 18:11:49 +00:00
public LongSet ag() {
2018-07-15 01:53:17 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2019-04-05 04:52:02 +00:00
index 533dcd60d..e107ddcf7 100644
2018-07-15 01:53:17 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2019-01-31 04:49:52 +00:00
@@ -1006,7 +1006,7 @@ public final class CraftServer implements Server {
2018-08-26 18:11:49 +00:00
System.out.println("Preparing start region for level " + (console.worldServer.size() - 1) + " (Seed: " + internal.getSeed() + ")");
2018-07-15 01:53:17 +00:00
if (internal.getWorld().getKeepSpawnInMemory()) {
- short short1 = 196;
+ short short1 = internal.paperConfig.keepLoadedRange; // Paper
long i = System.currentTimeMillis();
for (int j = -short1; j <= short1; j += 16) {
for (int k = -short1; k <= short1; k += 16) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2019-04-05 04:52:02 +00:00
index 262c3f910..a8c7e7931 100644
2018-07-15 01:53:17 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2019-01-01 03:15:55 +00:00
@@ -1419,8 +1419,9 @@ public class CraftWorld implements World {
2018-07-15 01:53:17 +00:00
int chunkCoordX = chunkcoordinates.getX() >> 4;
int chunkCoordZ = chunkcoordinates.getZ() >> 4;
// Cycle through the 25x25 Chunks around it to load/unload the chunks.
- for (int x = -12; x <= 12; x++) {
- for (int z = -12; z <= 12; z++) {
+ int radius = world.paperConfig.keepLoadedRange / 16; // Paper
+ for (int x = -radius; x <= radius; x++) { // Paper
+ for (int z = -radius; z <= radius; z++) { // Paper
if (keepLoaded) {
loadChunk(chunkCoordX + x, chunkCoordZ + z);
} else {
--
2019-04-05 04:52:02 +00:00
2.21.0
2018-07-15 01:53:17 +00:00