aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0094-Configurable-Keep-Spawn-Loaded-range-per-world.patch
blob: bb86e832ef079dd3edea09bcc8a0185d276911f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
From f4e4fe03783d2f79376e0dfb9254d398d1635a2f 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 6b74f810a..260c55016 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -258,4 +258,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 ee45d3705..01c5d3c57 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -486,13 +486,21 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
             List<ChunkCoordIntPair> list = Lists.newArrayList();
             Set<ChunkCoordIntPair> set = Sets.newConcurrentHashSet();
 
-            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
                     list.add(new ChunkCoordIntPair(blockposition.getX() + i >> 4, blockposition.getZ() + j >> 4));
                 }
+            } // Paper
+            if (this.isRunning()) { // Paper
+                int expected = list.size(); // Paper
+
 
                 CompletableFuture completablefuture = worldserver.getChunkProvider().a((Iterable) list, (chunk) -> {
                     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()) {
@@ -507,11 +515,11 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati
 
                         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
             }
         }
 
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 34b5ca3a7..8a445a1fa 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -2853,8 +2853,9 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
         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 LongSet ag() {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 5e821b84d..b0ae0365e 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1007,7 +1007,7 @@ public final class CraftServer implements Server {
         System.out.println("Preparing start region for level " + (console.worldServer.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 262c3f910..a8c7e7931 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -1419,8 +1419,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.21.0