Paper/Spigot-Server-Patches/0103-Configurable-Keep-Spawn-Loaded-range-per-world.patch
2017-06-18 20:37:08 -05:00

88 lines
4.6 KiB
Diff

From b23a445e2c33927e5ea376614dc0054e231d158c Mon Sep 17 00:00:00 2001
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
index 74a49a5f..3a942c76 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -284,4 +284,10 @@ public class PaperWorldConfig {
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
index 6e11ba5b..71b66bbd 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -356,8 +356,11 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IAs
long j = aw();
i = 0;
- for (int k = -192; k <= 192 && this.isRunning(); k += 16) {
- for (int l = -192; l <= 192 && this.isRunning(); l += 16) {
+ // Paper start
+ short radius = worldserver.paperConfig.keepLoadedRange;
+ for (int k = -radius; k <= radius && this.isRunning(); k += 16) {
+ for (int l = -radius; l <= radius && this.isRunning(); l += 16) {
+ // Paper end
long i1 = aw();
if (i1 - j > 1000L) {
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 553d9724..e9446b9c 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -3208,8 +3208,9 @@ public abstract class World implements IBlockAccess {
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
}
public void a(Packet<?> packet) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 52293656..a7dd7988 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -955,7 +955,7 @@ public final class CraftServer implements Server {
System.out.print("Preparing start region for level " + (console.worlds.size() - 1) + " (Seed: " + internal.getSeed() + ")");
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
index 843a3415..24b4a7ea 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -1275,8 +1275,9 @@ public class CraftWorld implements World {
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 {
--
2.13.1.windows.2