Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Add option to throttle spawn attempts after several failures

Open froobynooby opened this issue 1 year ago • 7 comments

This patch adds an option to use a longer ticks-per-spawn for given mob types in chunks where previous spawn attempts have consecutively failed (e.g. spawnproofed chunks). The ticks-per-spawn and the number of failed attempts before they kick in are both configurable (the setting is disabled by default). The number of failed spawn attempts is stored with the chunk so it persists across unloads. As soon as a mob is able to spawn in a chunk, the failed spawn attempt counter resets and the chunk starts using the default ticks-per-spawn again.

This behaviour is useful on servers where players use mob farms. Mob farms typically require spawnproofing the surrounding chunks to improve rates, which causes the server to waste CPU cycles trying to find suitable spawn locations. By identifying suspected spawnproof chunks and throttling attempts at spawning mobs in them, it is possible to improve performance without noticeably affecting overall mob spawning behaviour.

I've been using a similar patch on my reasonably busy survival server for nearly a year without any complaints from players.

For illustrative purposes I ran a simple test spending 5 minutes AFK at standard spawning-tower mob farm which had been properly spawnproofed.

Without patch (default ticks-per-spawn): image With patch (multiplying default ticks-per-spawn by 10 after 1200 failed attempts): Screenshot from 2024-07-17 22-08-00

froobynooby avatar Jul 17 '24 13:07 froobynooby

It looks a bit like https://github.com/PaperMC/Paper/pull/9400

molor avatar Jul 17 '24 13:07 molor

Similar concept, but different implementations targeted at different problems. The other PR relates to spawn attempts that are failing due to plugins cancelling or aborting the PreCreatureSpawnEvent, while this one primarily relates to chunks where mobs have repeatedly failed to spawn for other reasons (e.g. no suitable spawning locations)

froobynooby avatar Jul 17 '24 21:07 froobynooby

This patch makes creeper farms not work. Can you fix this? https://www.youtube.com/watch?v=qyUZ0iXkdBA

Potothingi avatar Aug 10 '24 11:08 Potothingi

This patch makes creeper farms not work. Can you fix this? https://www.youtube.com/watch?v=qyUZ0iXkdBA

Do you have a world download/schematic and configuration you could share?

The patch slows down spawn attempts in chunks that have repeatedly failed to spawn mobs - it shouldn't be stopping spawn attempts altogether. Make sure you're not configuring failed-attempts-threshold too low (I recommend setting it to 1200) or the throttled-ticks-per-spawn settings too high (I recommend setting them to 10x the normal ticks-per-spawn settings)

froobynooby avatar Aug 10 '24 12:08 froobynooby

This patch makes creeper farms not work. Can you fix this? https://www.youtube.com/watch?v=qyUZ0iXkdBA

Do you have a world download/schematic and configuration you could share?

The patch slows down spawn attempts in chunks that have repeatedly failed to spawn mobs - it shouldn't be stopping spawn attempts altogether. Make sure you're not configuring failed-attempts-threshold too low (I recommend setting it to 1200) or the throttled-ticks-per-spawn settings too high (I recommend setting them to 10x the normal ticks-per-spawn settings)

I have already set it as you said. I think it happens because the Creeper Farm prevents zombies, spiders and skeletons from spawning and only allows Creepers to be spawned.

Potothingi avatar Aug 10 '24 12:08 Potothingi

Do you have a world download/schematic and configuration you could share?

https://www.planetminecraft.com/project/creeper-farm-6175218/

Potothingi avatar Aug 11 '24 16:08 Potothingi

I would imagine that anything relying on spawn proofing is generally going to suck hard with this sort of feature, the concepts are pretty much incompatible, IMHO.

electronicboy avatar Aug 11 '24 22:08 electronicboy