Fix keep spawn loaded patch

Needs to be in blocks
This commit is contained in:
Spottedleaf 2022-06-11 07:58:17 -07:00
parent 46954ee75b
commit dfc10448bb
4 changed files with 17 additions and 17 deletions

View File

@ -6,7 +6,7 @@ Subject: [PATCH] Configurable Keep Spawn Loaded range per world
This lets you disable it for some worlds and lower it for others. This lets you disable it for some worlds and lower it for others.
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 97e964030a5cc449543252933f8a7b4800833e69..feba451e86ef49e5edcc5dc60fae18537a95ee71 100644 index 97e964030a5cc449543252933f8a7b4800833e69..40aa6abf0d3a814de194d754d5b136f3ef67d378 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java --- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -726,31 +726,34 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa @@ -726,31 +726,34 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@ -38,7 +38,7 @@ index 97e964030a5cc449543252933f8a7b4800833e69..feba451e86ef49e5edcc5dc60fae1853
- } - }
- } - }
+ // Paper start - configurable spawn reason + // Paper start - configurable spawn reason
+ int radiusBlocks = worldserver.paperConfig().spawn.keepSpawnLoadedRange; + int radiusBlocks = worldserver.paperConfig().spawn.keepSpawnLoadedRange * 16;
+ int radiusChunks = radiusBlocks / 16 + ((radiusBlocks & 15) != 0 ? 1 : 0); + int radiusChunks = radiusBlocks / 16 + ((radiusBlocks & 15) != 0 ? 1 : 0);
+ int totalChunks = ((radiusChunks) * 2 + 1); + int totalChunks = ((radiusChunks) * 2 + 1);
+ totalChunks *= totalChunks; + totalChunks *= totalChunks;
@ -64,7 +64,7 @@ index 97e964030a5cc449543252933f8a7b4800833e69..feba451e86ef49e5edcc5dc60fae1853
// CraftBukkit start // CraftBukkit start
// this.updateMobSpawningFlags(); // this.updateMobSpawningFlags();
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 40a0f98acf26e104912ff2db71aab744a6c727cb..c20d6f1d328ec6946a00488880a296f582dcf212 100644 index 40a0f98acf26e104912ff2db71aab744a6c727cb..af52ccf87e1c6901cc56ff01bda3750e808b736f 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java --- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java +++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -63,6 +63,7 @@ import net.minecraft.network.protocol.game.ClientboundSoundEntityPacket; @@ -63,6 +63,7 @@ import net.minecraft.network.protocol.game.ClientboundSoundEntityPacket;
@ -157,8 +157,8 @@ index 40a0f98acf26e104912ff2db71aab744a6c727cb..c20d6f1d328ec6946a00488880a296f5
- this.getChunkSource().addRegionTicket(TicketType.START, new ChunkPos(pos), 11, Unit.INSTANCE); - this.getChunkSource().addRegionTicket(TicketType.START, new ChunkPos(pos), 11, Unit.INSTANCE);
+ if (this.keepSpawnInMemory) { + if (this.keepSpawnInMemory) {
+ // if this keepSpawnInMemory is false a plugin has already removed our tickets, do not re-add + // if this keepSpawnInMemory is false a plugin has already removed our tickets, do not re-add
+ this.removeTicketsForSpawn(this.paperConfig().spawn.keepSpawnLoadedRange, prevSpawn); + this.removeTicketsForSpawn(this.paperConfig().spawn.keepSpawnLoadedRange * 16, prevSpawn);
+ this.addTicketsForSpawn(this.paperConfig().spawn.keepSpawnLoadedRange, pos); + this.addTicketsForSpawn(this.paperConfig().spawn.keepSpawnLoadedRange * 16, pos);
+ } + }
this.getServer().getPlayerList().broadcastAll(new ClientboundSetDefaultSpawnPositionPacket(pos, angle)); this.getServer().getPlayerList().broadcastAll(new ClientboundSetDefaultSpawnPositionPacket(pos, angle));
} }
@ -200,7 +200,7 @@ index 4d2348df25410a0b5364eec066880326d6667dad..286aad3205ef8a9e21a47ef07893844f
this.maxCount = i * i; this.maxCount = i * i;
} }
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 486e9e1d416021561d769d1f69b22d0a1e354342..d795014028cfa9ebd6f986b8ddd3d6477f189fa7 100644 index 486e9e1d416021561d769d1f69b22d0a1e354342..7489ac7569454560adcae2005317d83bbe7e98c5 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -1351,15 +1351,21 @@ public class CraftWorld extends CraftRegionAccessor implements World { @@ -1351,15 +1351,21 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@ -218,12 +218,12 @@ index 486e9e1d416021561d769d1f69b22d0a1e354342..d795014028cfa9ebd6f986b8ddd3d647
BlockPos chunkcoordinates = this.world.getSharedSpawnPos(); BlockPos chunkcoordinates = this.world.getSharedSpawnPos();
if (keepLoaded) { if (keepLoaded) {
- this.world.getChunkSource().addRegionTicket(TicketType.START, new ChunkPos(chunkcoordinates), 11, Unit.INSTANCE); - this.world.getChunkSource().addRegionTicket(TicketType.START, new ChunkPos(chunkcoordinates), 11, Unit.INSTANCE);
+ this.world.addTicketsForSpawn(this.world.paperConfig().spawn.keepSpawnLoadedRange, chunkcoordinates); + this.world.addTicketsForSpawn(this.world.paperConfig().spawn.keepSpawnLoadedRange * 16, chunkcoordinates);
} else { } else {
- // TODO: doesn't work well if spawn changed.... - // TODO: doesn't work well if spawn changed....
- this.world.getChunkSource().removeRegionTicket(TicketType.START, new ChunkPos(chunkcoordinates), 11, Unit.INSTANCE); - this.world.getChunkSource().removeRegionTicket(TicketType.START, new ChunkPos(chunkcoordinates), 11, Unit.INSTANCE);
+ // TODO: doesn't work well if spawn changed.... // Paper - resolved + // TODO: doesn't work well if spawn changed.... // Paper - resolved
+ this.world.removeTicketsForSpawn(this.world.paperConfig().spawn.keepSpawnLoadedRange, chunkcoordinates); + this.world.removeTicketsForSpawn(this.world.paperConfig().spawn.keepSpawnLoadedRange * 16, chunkcoordinates);
} }
+ // Paper end + // Paper end
} }

View File

@ -225,7 +225,7 @@ index 13a5062e539f6f43e6fe582318c36302bd6520ee..527b37e2740d6ca0d8d7695f069111d1
* Ported from MinecraftForge - author: LexManos <LexManos@gmail.com> - License: LGPLv2.1 * Ported from MinecraftForge - author: LexManos <LexManos@gmail.com> - License: LGPLv2.1
*/ */
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
index 162aa7718488a74980843944e0d026ccfd5a65a5..aebfcd07170109b9cf058df0d4e285b0d95fedb5 100644 index 162aa7718488a74980843944e0d026ccfd5a65a5..4e29c0a983727fc839a4bcde01d3286396b3587d 100644
--- a/src/main/java/net/minecraft/server/MCUtil.java --- a/src/main/java/net/minecraft/server/MCUtil.java
+++ b/src/main/java/net/minecraft/server/MCUtil.java +++ b/src/main/java/net/minecraft/server/MCUtil.java
@@ -9,13 +9,27 @@ import net.minecraft.core.BlockPos; @@ -9,13 +9,27 @@ import net.minecraft.core.BlockPos;
@ -363,7 +363,7 @@ index 162aa7718488a74980843944e0d026ccfd5a65a5..aebfcd07170109b9cf058df0d4e285b0
+ worldData.addProperty("name", world.getWorld().getName()); + worldData.addProperty("name", world.getWorld().getName());
+ worldData.addProperty("view-distance", world.spigotConfig.viewDistance); + worldData.addProperty("view-distance", world.spigotConfig.viewDistance);
+ worldData.addProperty("keep-spawn-loaded", world.keepSpawnInMemory); + worldData.addProperty("keep-spawn-loaded", world.keepSpawnInMemory);
+ worldData.addProperty("keep-spawn-loaded-range", world.paperConfig().spawn.keepSpawnLoadedRange); + worldData.addProperty("keep-spawn-loaded-range", world.paperConfig().spawn.keepSpawnLoadedRange * 16);
+ worldData.addProperty("visible-chunk-count", visibleChunks.size()); + worldData.addProperty("visible-chunk-count", visibleChunks.size());
+ worldData.addProperty("loaded-chunk-count", chunkMap.entitiesInLevel.size()); + worldData.addProperty("loaded-chunk-count", chunkMap.entitiesInLevel.size());
+ worldData.addProperty("verified-fully-loaded-chunks", fullLoadedChunks); + worldData.addProperty("verified-fully-loaded-chunks", fullLoadedChunks);

View File

@ -5,7 +5,7 @@ Subject: [PATCH] Fix SpawnChangeEvent not firing for all use-cases
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 69611eaafe2edc0e937f54b63bfbf3a23ca7a857..924fbf224ae04cba02cf41f37caa9424dfa69d1d 100644 index 980eda5fb86381f0c54e22e94d273bd5639f1a3b..b763d925a9db7deb5d6a0090498370355bc17554 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java --- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java +++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -1850,6 +1850,7 @@ public class ServerLevel extends Level implements WorldGenLevel { @@ -1850,6 +1850,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
@ -15,9 +15,9 @@ index 69611eaafe2edc0e937f54b63bfbf3a23ca7a857..924fbf224ae04cba02cf41f37caa9424
+ new org.bukkit.event.world.SpawnChangeEvent(getWorld(), MCUtil.toLocation(this, prevSpawn)).callEvent(); // Paper + new org.bukkit.event.world.SpawnChangeEvent(getWorld(), MCUtil.toLocation(this, prevSpawn)).callEvent(); // Paper
if (this.keepSpawnInMemory) { if (this.keepSpawnInMemory) {
// if this keepSpawnInMemory is false a plugin has already removed our tickets, do not re-add // if this keepSpawnInMemory is false a plugin has already removed our tickets, do not re-add
this.removeTicketsForSpawn(this.paperConfig().spawn.keepSpawnLoadedRange, prevSpawn); this.removeTicketsForSpawn(this.paperConfig().spawn.keepSpawnLoadedRange * 16, prevSpawn);
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 324498a6add5288f175510ddd754ea2199d37cb7..880aeefbda1cba04accf9075240c88c027b5763c 100644 index cb89a0c83a3c307f99581b7838308f70eccb774d..edf538cfa6f73bce65b5d50d014d8fd2fbca5d3d 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -258,11 +258,13 @@ public class CraftWorld extends CraftRegionAccessor implements World { @@ -258,11 +258,13 @@ public class CraftWorld extends CraftRegionAccessor implements World {

View File

@ -1272,7 +1272,7 @@ index 0e5f05d091710da9078021eb6e1a26a22e2d63dd..c1e8d8674738eebaaf7bd918eacb5227
// Paper end // Paper end
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
index 48ec2f7a3813f8ce2baf32667a09f377e2764710..33ccab88b93f93993b6e17d5e0a2539b08235f78 100644 index 1eb71004a19866590a3d27fa6e72842934989177..7034af8ad42940c5af6b9032b9873ce36c55a2a7 100644
--- a/src/main/java/net/minecraft/server/MCUtil.java --- a/src/main/java/net/minecraft/server/MCUtil.java
+++ b/src/main/java/net/minecraft/server/MCUtil.java +++ b/src/main/java/net/minecraft/server/MCUtil.java
@@ -647,7 +647,8 @@ public final class MCUtil { @@ -647,7 +647,8 @@ public final class MCUtil {
@ -1283,7 +1283,7 @@ index 48ec2f7a3813f8ce2baf32667a09f377e2764710..33ccab88b93f93993b6e17d5e0a2539b
+ worldData.addProperty("view-distance", world.getChunkSource().chunkMap.playerChunkManager.getTargetNoTickViewDistance()); // Paper - replace chunk loader system + worldData.addProperty("view-distance", world.getChunkSource().chunkMap.playerChunkManager.getTargetNoTickViewDistance()); // Paper - replace chunk loader system
+ worldData.addProperty("tick-view-distance", world.getChunkSource().chunkMap.playerChunkManager.getTargetTickViewDistance()); // Paper - replace chunk loader system + worldData.addProperty("tick-view-distance", world.getChunkSource().chunkMap.playerChunkManager.getTargetTickViewDistance()); // Paper - replace chunk loader system
worldData.addProperty("keep-spawn-loaded", world.keepSpawnInMemory); worldData.addProperty("keep-spawn-loaded", world.keepSpawnInMemory);
worldData.addProperty("keep-spawn-loaded-range", world.paperConfig().spawn.keepSpawnLoadedRange); worldData.addProperty("keep-spawn-loaded-range", world.paperConfig().spawn.keepSpawnLoadedRange * 16);
worldData.addProperty("visible-chunk-count", visibleChunks.size()); worldData.addProperty("visible-chunk-count", visibleChunks.size());
diff --git a/src/main/java/net/minecraft/server/level/ChunkHolder.java b/src/main/java/net/minecraft/server/level/ChunkHolder.java diff --git a/src/main/java/net/minecraft/server/level/ChunkHolder.java b/src/main/java/net/minecraft/server/level/ChunkHolder.java
index 5482be03a667939ff009b6810d5cc90c8601e983..11cd31691307749e925930c4b6e10e3f3b4fad25 100644 index 5482be03a667939ff009b6810d5cc90c8601e983..11cd31691307749e925930c4b6e10e3f3b4fad25 100644
@ -1855,7 +1855,7 @@ index 96a232f22b1c270b91635ce9c7c6cacc63b026cc..59acbf6249f8f5285504c0ddea448a34
return true; return true;
} else { } else {
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 3b2a3f5e6db4685c3f8d95dc46c85a2ba7b5ec7c..bcfa1959c2ffd9ee31804c5a00a84133599cbbc4 100644 index 68267114d6e54323258483d59e8971b0e031218c..da1533ade2d51a6a978ba4334d07b07681421693 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java --- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java +++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -676,7 +676,7 @@ public class ServerLevel extends Level implements WorldGenLevel { @@ -676,7 +676,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
@ -2079,7 +2079,7 @@ index 0de0519c01886a39399233b275db44b95e2f3d96..c46cbbf9ac4c5661933b03bc0b2559f7
@Nullable @Nullable
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index d908eb6b1208cf69f2f1282ddf1c20dc04d092d1..bc387765a9d96f3901dd2e1db751262b1fdd4829 100644 index 6594d7dd2d21cca438530af7cc789bfbac265238..131f40a7defc87a01f6a554f7c7819d34e84fe1d 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -2201,43 +2201,56 @@ public class CraftWorld extends CraftRegionAccessor implements World { @@ -2201,43 +2201,56 @@ public class CraftWorld extends CraftRegionAccessor implements World {