2021-11-27 08:00:00 +11:00
|
|
|
From a9f638f9142b096a0ce4e1ab17df251911cb734a Mon Sep 17 00:00:00 2001
|
2018-07-15 10:00:00 +10:00
|
|
|
From: md_5 <md_5@live.com.au>
|
|
|
|
Date: Fri, 21 Jun 2013 17:29:54 +1000
|
|
|
|
Subject: [PATCH] Fix Mob Spawning Relative to View Distance
|
|
|
|
|
|
|
|
Changes the mob spawning algorithm to properly account for view distance and the range around players.
|
|
|
|
|
|
|
|
Needs better documentation.
|
|
|
|
|
2021-03-16 09:00:00 +11:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ChunkProviderServer.java b/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
|
2021-11-25 08:00:00 +11:00
|
|
|
index c90cede56..72eed18ab 100644
|
2021-03-16 09:00:00 +11:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
|
2021-11-25 08:00:00 +11:00
|
|
|
@@ -448,7 +448,7 @@ public class ChunkProviderServer extends IChunkProvider {
|
2020-06-25 10:00:00 +10:00
|
|
|
|
2021-11-22 09:00:00 +11:00
|
|
|
if (this.level.isPositionEntityTicking(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkcoordintpair)) {
|
|
|
|
chunk1.incrementInhabitedTime(j);
|
|
|
|
- if (flag2 && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair)) {
|
|
|
|
+ if (flag2 && (this.spawnEnemies || this.spawnFriendlies) && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair) && !this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkcoordintpair, true)) { // Spigot
|
|
|
|
SpawnerCreature.spawnForChunk(this.level, chunk1, spawnercreature_d, this.spawnFriendlies, this.spawnEnemies, flag1);
|
|
|
|
}
|
2019-05-29 19:39:32 +10:00
|
|
|
|
2021-03-16 09:00:00 +11:00
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
2021-11-27 08:00:00 +11:00
|
|
|
index b6237f3ab..bd1b9f866 100644
|
2021-03-16 09:00:00 +11:00
|
|
|
--- a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
|
2021-11-27 08:00:00 +11:00
|
|
|
@@ -1006,6 +1006,17 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.e {
|
2019-04-23 12:00:00 +10:00
|
|
|
}
|
2018-07-15 10:00:00 +10:00
|
|
|
|
2021-11-22 09:00:00 +11:00
|
|
|
boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair) {
|
2019-07-20 09:00:00 +10:00
|
|
|
+ // Spigot start
|
2021-11-22 09:00:00 +11:00
|
|
|
+ return anyPlayerCloseEnoughForSpawning(chunkcoordintpair, false);
|
2019-07-20 09:00:00 +10:00
|
|
|
+ }
|
|
|
|
+
|
2021-11-22 09:00:00 +11:00
|
|
|
+ boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair, boolean reducedRange) {
|
2021-06-11 15:00:00 +10:00
|
|
|
+ int chunkRange = level.spigotConfig.mobSpawnRange;
|
|
|
|
+ chunkRange = (chunkRange > level.spigotConfig.viewDistance) ? (byte) level.spigotConfig.viewDistance : chunkRange;
|
2019-04-23 12:00:00 +10:00
|
|
|
+ chunkRange = (chunkRange > 8) ? 8 : chunkRange;
|
|
|
|
+
|
2019-05-29 19:39:32 +10:00
|
|
|
+ double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D;
|
2019-04-23 12:00:00 +10:00
|
|
|
+ // Spigot end
|
2021-11-22 09:00:00 +11:00
|
|
|
long i = chunkcoordintpair.toLong();
|
2019-06-21 20:00:00 +10:00
|
|
|
|
2021-11-22 09:00:00 +11:00
|
|
|
if (!this.distanceManager.hasPlayersNearby(i)) {
|
2021-11-27 08:00:00 +11:00
|
|
|
@@ -1021,7 +1032,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.e {
|
2021-11-22 09:00:00 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
entityplayer = (EntityPlayer) iterator.next();
|
|
|
|
- } while (!this.playerIsCloseEnoughForSpawning(entityplayer, chunkcoordintpair));
|
|
|
|
+ } while (!this.playerIsCloseEnoughForSpawning(entityplayer, chunkcoordintpair, blockRange)); // Spigot
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2021-11-27 08:00:00 +11:00
|
|
|
@@ -1039,7 +1050,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.e {
|
2021-11-22 09:00:00 +11:00
|
|
|
while (iterator.hasNext()) {
|
|
|
|
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
|
|
|
|
|
|
|
|
- if (this.playerIsCloseEnoughForSpawning(entityplayer, chunkcoordintpair)) {
|
|
|
|
+ if (this.playerIsCloseEnoughForSpawning(entityplayer, chunkcoordintpair, 16384.0D)) { // Spigot
|
|
|
|
builder.add(entityplayer);
|
|
|
|
}
|
|
|
|
}
|
2021-11-27 08:00:00 +11:00
|
|
|
@@ -1048,13 +1059,13 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.e {
|
2021-11-22 09:00:00 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- private boolean playerIsCloseEnoughForSpawning(EntityPlayer entityplayer, ChunkCoordIntPair chunkcoordintpair) {
|
|
|
|
+ private boolean playerIsCloseEnoughForSpawning(EntityPlayer entityplayer, ChunkCoordIntPair chunkcoordintpair, double range) { // Spigot
|
|
|
|
if (entityplayer.isSpectator()) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
double d0 = euclideanDistanceSquared(chunkcoordintpair, entityplayer);
|
|
|
|
|
|
|
|
- return d0 < 16384.0D;
|
|
|
|
+ return d0 < range; // Spigot
|
|
|
|
}
|
2019-04-23 12:00:00 +10:00
|
|
|
}
|
2018-07-15 10:00:00 +10:00
|
|
|
|
|
|
|
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
2021-11-22 09:00:00 +11:00
|
|
|
index e5df553a9..55af2f874 100644
|
2018-07-15 10:00:00 +10:00
|
|
|
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
|
|
|
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
|
2021-11-22 09:00:00 +11:00
|
|
|
@@ -174,4 +174,11 @@ public class SpigotWorldConfig
|
|
|
|
|
|
|
|
log( "Simulation Distance: " + simulationDistance );
|
2018-07-15 10:00:00 +10:00
|
|
|
}
|
|
|
|
+
|
|
|
|
+ public byte mobSpawnRange;
|
|
|
|
+ private void mobSpawnRange()
|
|
|
|
+ {
|
2018-08-06 10:32:15 +10:00
|
|
|
+ mobSpawnRange = (byte) getInt( "mob-spawn-range", 6 );
|
2018-07-15 10:00:00 +10:00
|
|
|
+ log( "Mob Spawn Range: " + mobSpawnRange );
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
--
|
2020-05-09 18:48:11 +10:00
|
|
|
2.25.1
|
2018-07-15 10:00:00 +10:00
|
|
|
|