spigot/CraftBukkit-Patches/0010-Fix-Mob-Spawning-Relative-to-View-Distance.patch

69 lines
3.7 KiB
Diff
Raw Normal View History

2019-06-02 19:56:20 +10:00
From 08402796889970f21cc411b489f64da9ee2ebde0 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.
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
2019-06-02 19:56:20 +10:00
index 417704a77..dcf2d38df 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -319,9 +319,9 @@ public class ChunkProviderServer extends IChunkProvider {
this.world.getMethodProfiler().exit();
ChunkCoordIntPair chunkcoordintpair = playerchunk.h();
2019-06-02 19:56:20 +10:00
- if (!this.playerChunkMap.isOutsideOfRange(chunkcoordintpair)) {
+ if (!this.playerChunkMap.isOutsideOfRange(chunkcoordintpair, false)) { // Spigot
chunk.b(chunk.q() + j);
- if (flag1 && (this.allowMonsters || this.allowAnimals) && this.world.getWorldBorder().isInBounds(chunk.getPos())) {
2019-06-02 19:56:20 +10:00
+ if (flag1 && (this.allowMonsters || this.allowAnimals) && this.world.getWorldBorder().isInBounds(chunk.getPos()) && !this.playerChunkMap.isOutsideOfRange(chunkcoordintpair, true)) { // Spigot
this.world.getMethodProfiler().enter("spawner");
this.world.timings.mobSpawn.startTiming(); // Spigot
EnumCreatureType[] aenumcreaturetype1 = aenumcreaturetype;
2019-04-23 12:00:00 +10:00
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
2019-06-02 19:56:20 +10:00
index 19de8c19f..9b9f70182 100644
2019-04-23 12:00:00 +10:00
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -739,9 +739,17 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
return nbttagcompound == null ? null : this.getChunkData(this.world.getWorldProvider().getDimensionManager(), this.m, nbttagcompound, chunkcoordintpair, world); // CraftBukkit
2019-04-23 12:00:00 +10:00
}
2018-07-15 10:00:00 +10:00
2019-06-02 19:56:20 +10:00
- boolean isOutsideOfRange(ChunkCoordIntPair chunkcoordintpair) {
+ // Spigot Start
2019-06-02 19:56:20 +10:00
+ boolean isOutsideOfRange(ChunkCoordIntPair chunkcoordintpair, boolean reducedRange) {
2019-04-23 12:00:00 +10:00
+ int chunkRange = world.spigotConfig.mobSpawnRange;
+ chunkRange = (chunkRange > world.spigotConfig.viewDistance) ? (byte) world.spigotConfig.viewDistance : chunkRange;
+ chunkRange = (chunkRange > 8) ? 8 : chunkRange;
+
+ double blockRange = (reducedRange) ? Math.pow(chunkRange << 4, 2) : 16384.0D;
2019-04-23 12:00:00 +10:00
+ // Spigot end
2018-07-15 10:00:00 +10:00
+
2019-05-14 10:00:00 +10:00
return this.playerMap.a(chunkcoordintpair.pair()).noneMatch((entityplayer) -> {
2019-04-23 12:00:00 +10:00
- return !entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < 16384.0D;
+ return !entityplayer.isSpectator() && a(chunkcoordintpair, (Entity) entityplayer) < blockRange; // Spigot
});
}
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
index 47e959af0..fc592d814 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
@@ -148,4 +148,11 @@ public class SpigotWorldConfig
viewDistance = Math.max( viewDistance, 3 );
2018-07-15 10:00:00 +10:00
log( "View Distance: " + viewDistance );
}
+
+ 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 );
+ }
}
--
2019-04-23 09:33:25 +10:00
2.20.1
2018-07-15 10:00:00 +10:00