From 4cb47d83fc9d7ab055fdc4d4476fa2087c5629d8 Mon Sep 17 00:00:00 2001 From: md_5 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/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java index cfb6b679b..bf6801bae 100644 --- a/src/main/java/net/minecraft/server/PlayerChunkMap.java +++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java @@ -740,8 +740,16 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d { } boolean d(ChunkCoordIntPair chunkcoordintpair) { + // Spigot Start + int chunkRange = world.spigotConfig.mobSpawnRange; + chunkRange = (chunkRange > world.spigotConfig.viewDistance) ? (byte) world.spigotConfig.viewDistance : chunkRange; + chunkRange = (chunkRange > 8) ? 8 : chunkRange; + + double blockRange = Math.pow(chunkRange << 4, 2); + // Spigot end + return this.playerMap.a(chunkcoordintpair.pair()).noneMatch((entityplayer) -> { - return !entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < 16384.0D; + return !entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange; // Spigot }); } diff --git a/src/main/java/org/spigotmc/SpigotWorldConfig.java b/src/main/java/org/spigotmc/SpigotWorldConfig.java index 47e959af0..fc592d814 100644 --- a/src/main/java/org/spigotmc/SpigotWorldConfig.java +++ b/src/main/java/org/spigotmc/SpigotWorldConfig.java @@ -148,4 +148,11 @@ public class SpigotWorldConfig viewDistance = Math.max( viewDistance, 3 ); log( "View Distance: " + viewDistance ); } + + public byte mobSpawnRange; + private void mobSpawnRange() + { + mobSpawnRange = (byte) getInt( "mob-spawn-range", 6 ); + log( "Mob Spawn Range: " + mobSpawnRange ); + } } -- 2.20.1