0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/spigot.git synced 2024-11-21 22:06:13 +00:00
spigot/CraftBukkit-Patches/0009-Fix-Mob-Spawning-Relative-to-View-Distance.patch
2024-10-23 02:15:00 +11:00

109 lines
5.2 KiB
Diff

From ffec414a3f514d50b2213c14276f26e535ad59a0 Mon Sep 17 00:00:00 2001
From: md_5 <git@md-5.net>
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.
diff --git a/src/main/java/net/minecraft/server/level/ChunkProviderServer.java b/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
index 461b299a7e..156d359f2c 100644
--- a/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/level/ChunkProviderServer.java
@@ -469,7 +469,7 @@ public class ChunkProviderServer extends IChunkProvider {
ChunkCoordIntPair chunkcoordintpair = chunk.getPos();
chunk.incrementInhabitedTime(i);
- if (!list1.isEmpty() && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair)) {
+ if (!list1.isEmpty() && this.level.getWorldBorder().isWithinBounds(chunkcoordintpair) && this.chunkMap.anyPlayerCloseEnoughForSpawning(chunkcoordintpair, true)) { // Spigot
SpawnerCreature.spawnForChunk(this.level, chunk, spawnercreature_d, list1);
}
diff --git a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
index 5043631d14..54dcf22e5a 100644
--- a/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/PlayerChunkMap.java
@@ -1059,10 +1059,27 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.b, Gener
}
boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair) {
- return !this.distanceManager.hasPlayersNearby(chunkcoordintpair.toLong()) ? false : this.anyPlayerCloseEnoughForSpawningInternal(chunkcoordintpair);
+ // Spigot start
+ return anyPlayerCloseEnoughForSpawning(chunkcoordintpair, false);
+ }
+
+ boolean anyPlayerCloseEnoughForSpawning(ChunkCoordIntPair chunkcoordintpair, boolean reducedRange) {
+ return !this.distanceManager.hasPlayersNearby(chunkcoordintpair.toLong()) ? false : this.anyPlayerCloseEnoughForSpawningInternal(chunkcoordintpair, reducedRange);
+ // Spigot end
}
private boolean anyPlayerCloseEnoughForSpawningInternal(ChunkCoordIntPair chunkcoordintpair) {
+ // Spigot start
+ return anyPlayerCloseEnoughForSpawningInternal(chunkcoordintpair, false);
+ }
+
+ private boolean anyPlayerCloseEnoughForSpawningInternal(ChunkCoordIntPair chunkcoordintpair, boolean reducedRange) {
+ int chunkRange = level.spigotConfig.mobSpawnRange;
+ chunkRange = (chunkRange > level.spigotConfig.viewDistance) ? (byte) level.spigotConfig.viewDistance : chunkRange;
+ chunkRange = (chunkRange > 8) ? 8 : chunkRange;
+
+ double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D;
+ // Spigot end
Iterator iterator = this.playerMap.getAllPlayers().iterator();
EntityPlayer entityplayer;
@@ -1073,7 +1090,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.b, Gener
}
entityplayer = (EntityPlayer) iterator.next();
- } while (!this.playerIsCloseEnoughForSpawning(entityplayer, chunkcoordintpair));
+ } while (!this.playerIsCloseEnoughForSpawning(entityplayer, chunkcoordintpair, blockRange)); // Spigot
return true;
}
@@ -1090,7 +1107,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.b, Gener
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
- if (this.playerIsCloseEnoughForSpawning(entityplayer, chunkcoordintpair)) {
+ if (this.playerIsCloseEnoughForSpawning(entityplayer, chunkcoordintpair, 16384.0D)) { // Spigot
builder.add(entityplayer);
}
}
@@ -1099,13 +1116,13 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.b, Gener
}
}
- 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
}
}
diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java
index acaf903011..0c0c29efe5 100644
--- a/src/main/java/org/spigotmc/SpigotWorldConfig.java
+++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java
@@ -180,4 +180,11 @@ public class SpigotWorldConfig
log( "Simulation Distance: " + simulationDistance );
}
+
+ public byte mobSpawnRange;
+ private void mobSpawnRange()
+ {
+ mobSpawnRange = (byte) getInt( "mob-spawn-range", 6 );
+ log( "Mob Spawn Range: " + mobSpawnRange );
+ }
}
--
2.47.0