Mob spawning issues - 'fix'. See below for ideal reasoning from MikePrimm, however until ideal reasoning we must live with the CraftBukkit / Vanilla behaviour since this causes far too many issues.

IIRC, the main item I was driving towards was a consequence of persistent passive mobs - specifically, the fact that allowing a population limit of N (independent of view distance, which is what vanilla does) when your view distance limits actual loaded chunks to a much smaller area than default (say a view of 4, which would be 9 x 9 chunks loaded per player - and spawnable - versus default, which is 8 radius spawn, or 17 x 17 chunks) tends to result in more mobs per chunk. For persistent mobs, this is bad - since they count for server load and for population just by being loaded, versus being despawned beyond 128 blocks (8 chunk radius - unconditional of view distance, as well) - so they can cause the population limit to be reached more easily, cutting off spawning nearer to players. The goal was to make it so that the mobs-per-loaded-chunk was about the same for all view distances, versus having low view distances cause higher mob concentrations.

    Now, all of this assumes that loaded chunks beyond those around players are modest (since they could contain passive mobs that would count towards the limits) - which they should be, except that recent CBs leak chunks like mad, from what I can see (chunk-gc has become more required than optional), and I think there may be some issues with even hostile mobs "lurking" around - possibly even after their chunks are unloaded. Anything that causes more mobs to be in places players don't see them is going to drive population limit issues, and resulting low spawn behaviors. The trick for us, trying to make big servers as practical as possible, is to shift the math the other way - given low view distances, how to best make sure that folks get reasonable spawn behavior while minimizing the time/resources spent on the server on mobs that don't help that. Realistically, I think we need to analyse the mob demographics better - especially as it relates to lower view distances (our changes have no net impact on view distances above 7) - particularly to understand how the proportion of "useful" mobs is working out (ones close enough to players to be considered contributing to game play). One thought is to manage the population limit based on mobs that are 'tickable' - if they aren't close enough to be ticking, they aren't interesting. This is likely a big issue for view distance 5 folks, since mobs cannot spawn closer than 24 (approx 1 chunk radius, given that middle chunk is 0), and don't tick when any of the chunks within a 2 chunk radius aren't loaded) - so, effectively, they "live" within a zone of 7 x 7 with the middle 3 x 3 removed (so, about 40 chunks) out of a total load zone of 11 x 11 (121) - so about 2/3 of the area containing mobs has idle mobs. Normal view distance would result in mobs ticking as far out as they can spawn (radius 8 versus a load radius of 11), so 100% of the mobs that spawn are ticking when they spawn, and all hostile mobs that are loaded are ticking (since they always despawn beyond 128 blocks / 8 chunks from a player). One interesting thought would be to limit the chunks we spawn mobs in to those where they would be ticking initially (that is, view-distance minus 2 or 3).

By: md_5 <md_5@live.com.au>
This commit is contained in:
Spigot
2013-01-29 16:54:36 +11:00
parent af2e7e60fb
commit ddfda2753f
14 changed files with 16 additions and 111 deletions

View File

@@ -1,6 +1,6 @@
From 1f766e4a465e4eed65061fd7a908ea22e8c0d6fa Mon Sep 17 00:00:00 2001
From 47c9f07d091d4669fd669569ee924ba083c19b21 Mon Sep 17 00:00:00 2001
From: md_5 <md_5@live.com.au>
Date: Tue, 22 Jan 2013 15:56:54 +1100
Date: Tue, 29 Jan 2013 16:51:35 +1100
Subject: [PATCH] Spigot changes.
---
@@ -24,7 +24,6 @@ Subject: [PATCH] Spigot changes.
.../java/net/minecraft/server/MinecraftServer.java | 51 +--
.../net/minecraft/server/PlayerConnection.java | 18 +-
src/main/java/net/minecraft/server/PlayerList.java | 10 +-
.../java/net/minecraft/server/SpawnerCreature.java | 23 +-
.../net/minecraft/server/ThreadLoginVerifier.java | 23 +
src/main/java/net/minecraft/server/World.java | 200 ++++++++-
.../java/net/minecraft/server/WorldServer.java | 122 +++++-
@@ -44,7 +43,7 @@ Subject: [PATCH] Spigot changes.
.../org/bukkit/craftbukkit/util/TimedThread.java | 37 ++
.../bukkit/craftbukkit/util/WatchdogThread.java | 88 ++++
src/main/resources/configurations/bukkit.yml | 30 ++
40 files changed, 1444 insertions(+), 137 deletions(-)
39 files changed, 1424 insertions(+), 134 deletions(-)
create mode 100644 src/main/java/org/bukkit/craftbukkit/Spigot.java
create mode 100644 src/main/java/org/bukkit/craftbukkit/command/RestartCommand.java
create mode 100644 src/main/java/org/bukkit/craftbukkit/command/TicksPerSecondCommand.java
@@ -613,72 +612,6 @@ index f669a00..dee6579 100644
}
}
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
index 9b3e262..61721c4 100644
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
+++ b/src/main/java/net/minecraft/server/SpawnerCreature.java
@@ -16,6 +16,7 @@ public final class SpawnerCreature {
private static LongObjectHashMap<Boolean> b = new LongObjectHashMap<Boolean>(); // CraftBukkit - HashMap -> LongObjectHashMap
protected static final Class[] a = new Class[] { EntitySpider.class, EntityZombie.class, EntitySkeleton.class};
+ private static byte spawnRadius = 0; // Spigot
protected static ChunkPosition getRandomPosition(World world, int i, int j) {
Chunk chunk = world.getChunkAt(i, j);
@@ -34,13 +35,21 @@ public final class SpawnerCreature {
int i;
int j;
+ // Spigot start - limit radius to spawn distance (chunks aren't loaded)
+ if (spawnRadius == 0) {
+ spawnRadius = (byte) worldserver.getServer().getViewDistance();
+ if (spawnRadius > 8) {
+ spawnRadius = 8;
+ }
+ }
+ // Spigot end
for (i = 0; i < worldserver.players.size(); ++i) {
EntityHuman entityhuman = (EntityHuman) worldserver.players.get(i);
int k = MathHelper.floor(entityhuman.locX / 16.0D);
j = MathHelper.floor(entityhuman.locZ / 16.0D);
- byte b0 = 8;
+ byte b0 = spawnRadius; // Spigot - replace 8 with view distance constrained value
for (int l = -b0; l <= b0; ++l) {
for (int i1 = -b0; i1 <= b0; ++i1) {
@@ -88,13 +97,15 @@ public final class SpawnerCreature {
if (limit == 0) {
continue;
}
+ int mobcnt = 0;
// CraftBukkit end
- if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && (!enumcreaturetype.e() || flag2) && worldserver.a(enumcreaturetype.a()) <= limit * b.size() / 256) { // CraftBukkit - use per-world limits
+ if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && (!enumcreaturetype.e() || flag2) && (mobcnt = worldserver.a(enumcreaturetype.a())) <= limit * b.size() / 256) { // CraftBukkit - use per-world limits
Iterator iterator = b.keySet().iterator();
+ int moblimit = (limit * b.size() / 256) - mobcnt + 1; // CraftBukkit - up to 1 more than limit
label110:
- while (iterator.hasNext()) {
+ while (iterator.hasNext() && (moblimit > 0)) { // Spigot - while more allowed
// CraftBukkit start
long key = ((Long) iterator.next()).longValue();
@@ -158,6 +169,12 @@ public final class SpawnerCreature {
a(entityliving, worldserver, f, f1, f2);
worldserver.addEntity(entityliving, SpawnReason.NATURAL);
// CraftBukkit end
+ // Spigot start
+ moblimit--;
+ if (moblimit <= 0) { // If we're past limit, stop spawn
+ continue label110;
+ }
+ // Spigot end
if (j2 >= entityliving.bv()) {
continue label110;
}
diff --git a/src/main/java/net/minecraft/server/ThreadLoginVerifier.java b/src/main/java/net/minecraft/server/ThreadLoginVerifier.java
index 0686ba0..58d30eb 100644
--- a/src/main/java/net/minecraft/server/ThreadLoginVerifier.java