Understanding mob spawn limits

Discussion in 'Spigot Discussion' started by DerFlash, Jul 5, 2013.

  1. Hey… I just went through the code of SpawnCreature.java to understand how the mobSpawn limits in spigot/bukkit per world are working and saw this line:
    https://github.com/EcoCityCraft/Spi...et/minecraft/server/SpawnerCreature.java#L120

    Since the size/count of chunks in this.a is based on the mobSpawnRange, wouldn't it make more sense to change this static 265 to be based on mobSpawnRange too? because when you (like the default in spigot) set the range to only 4, this whole calculation is a bit off, or am I wrong here?

    Example: I have a world with some players on it who actually keep 2306 chunks loaded with 1688 entities. Mostly those entities are animals in farms in the users zones. So in this case the default limit of ...
    Code (Text):
    spawn-limits:
      monsters: 50
      animals: 15
      water-animals: 4
      ambient: 15
     
    ... would be useless and no NEW mobs would spawn while walking through the world, right?

    Also… do I understand correctly, that the mobSpawn limits are per world and so it counts the actual mobs in all the chunks around the player in some world and subtracts that from the given limit… and so the limit needs to be greater than the mob/animal count in the world to spawn new mobs around those players???

    Thanks!
     
  2. Hm k. Anyone?! ;-)

    [edit]

    So I took some more time now to understand it myself using the actual code. Correct me if I'm wrong here!

    The final formula for the line #120 is:

    Code (Text):
    spawnableMobs = ( spawn-limits * (playerCount * (mob-spawn-range * 2)^2 / 256) ) - currentMobCount + 1
    All this is per world and per mob type (animal, monster, watercreature, ambient)!
    So in the case of default settings and actual readings from one of my worlds using /mvwho (Multiverse) and /wg report (WorldGuard):
    Code (Text):
    = ( 15 * ( 9 * (8 * 2)^2 / 256) ) - 1500 + 1
    = ( 15 * 9 ) - 1500 + 1
    = -1364
     
    Since the result is the number the function would spawn randomly in the loaded chunks, you can see there's not much left ;-) It's way over limit...
    So what I think I need to do now is to raise the spawn-limits for this world to be >150. So the formula would then be:
    Code (Text):
    = ( 170 * 9 ) - 1500 + 1
    = 31
     
    Now I just need to find out how to change the mob-spawn-limit per world ;-) Spigot Configuration guide says nothing about it, but the code seems to show that this setting is kind of per-world....

    Btw. As you can also see here: with a default setting of 4 for the mob-spawn-range in spigot and without also modifying the static 256, you'd get even lower numbers while you just want to decrease the spawn area surrounding the player. I think I will create a PR for a patch later. This should be fixed!
     
    #2 DerFlash, Jul 7, 2013
    Last edited: Jul 7, 2013
  3. Talking to myself is n1 ;-)
    (sry for triple post, but I think it wouldn't make sense to edit the posts hours after, right?)

    Anyway, just FYI: https://github.com/EcoCityCraft/Spigot-Server/pull/62 (per world mob spawn limits + spawn range modifier fix which I mentioned above)
     
  4. Yea, but if it makes you feel better I have read each post. I have nothing to add as this is above me though :)