Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement optional per player mobspawning #2171

Merged
merged 52 commits into from
Aug 21, 2019

Conversation

kickash32
Copy link
Contributor

@kickash32 kickash32 commented Jun 12, 2019

Note this Patch essentially reimplements #2127 if disabled.
Implements requests from #245 and #1653.

If enabled, the chunks(with range taken from spigot.yml's mob-spawn-range) around players who have the sufficient amount of mobs of a type (limit taken from bukkit.yml's mob limits), will not have chunks around them eligible to spawn mobs of the same type. Additionally the global limit is ignored (although in most circumstances the number of mobs will be the same if mob-spawn-range is 8).

Benefits include more balanced/fair mob spawning, a player on the other side of the world will not be able to affect mob spawning to other players, etc. Essentially makes mob spawning behave as each player was in single player and so it includes all the additional benefits that come with that.

It works by creating a map of player, entity type to counts which is recreated every tick and updated as mobs are spawned. For each potential chunk available for spawning, the map is queried with all the players in range to determine how many mobs should be spawned in the chunk. See below.

kickash32 and others added 13 commits June 11, 2019 22:25
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

CraftBukkit Changes:
9e95da1 SPIGOT-5052: PlayerPortalEvent not called when nether is disabled
28ea3fd SPIGOT-5062: end_portal on an non-default end world crashes the server
4a07dc6 SPIGOT-5058: ClassCastException when getting InventoryHolder of lectern when it's destroyed
* Updated Upstream (Bukkit/CraftBukkit)

Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
45690fe9 SPIGOT-5047: Correct slot types for 1.14 inventories

CraftBukkit Changes:
4090d01 SPIGOT-5047: Correct slot types for 1.14 inventories
e8c0836 SPIGOT-5046: World#getLoadedChunks returning inaccessible cached chunks.
d445af3 SPIGOT-5067: Add item meta for 1.14 spawn eggs

* Bring Chunk load checks in-line with spigot

As of the last upstream merge spigot now checks ticket level status
when returning loaded chunks for a world from api. Now our checks
will respect that decision.

* Fix spawn ticket levels

Vanilla would keep the inner chunks of spawn available for ticking,
however my changes made all chunks non-ticking. Resolve by changing
ticket levels for spawn chunks inside the border to respect this
behavior.


* Make World#getChunkIfLoadedImmediately return only entity ticking chunks

Mojang appears to be using chunks with level > 33 (non-ticking chunks)
as cached chunks and not actually loaded chunks.

* Bring all loaded checks in line with spigot

Loaded chunks must be at least border  chunks, or level <= 33
Used so that server owners can tell what types of chunks are loaded
without requiring to use a tool to analyse a debug report
@paul-maxime
Copy link

👍

I've been using this patch for a while on my server and most players are happy with it.
It fixes the common spawning problem, where a single player has all monsters around their location and the remaining players cannot find a single entity.
It also reduces the lag quite a bit since we need less entities overall for the same results.

@paul-maxime
Copy link

Looks like this patch needs to be updated for 1.14.3.

@kickash32
Copy link
Contributor Author

Updated for 1.14.3

kickash32 and others added 8 commits August 3, 2019 13:54
Instead use `l(true)` for future compatability where `l()` may be called in other places.
Adds a distance map where players are tracked to coordinates in which
they are close to. The class contains a validatePlayer() method
which was used for testing.

The class uses pooled hash tables to reduce object churning, and was
tested via the following:

https://gist.github.com/Spottedleaf/a93bb7a8993d6ce142d3efc5932bf573

With the distance map, looking up players in a specific location will be
approximately constant time, which makes this patch scale much better with
more players, at the cost of some performance at lower playercounts.
@kickash32
Copy link
Contributor Author

getNearbyPlayers method has now been optimized and pending a review of @Spottedleaf's new classes (PlayerMobDistanceMap.java and PooledHashSets.java), the patch should be ready to merge.

@electronicboy electronicboy self-requested a review August 7, 2019 03:18
@duplexsystem
Copy link

@electronicboy please merge this. Since the phantom block fix, this is the last thing to make 1.14 better than 1.13.

@electronicboy
Copy link
Member

Only thing that gets me is the usage of view distance vs the min(mob spawn range, view distance) that the server does to determine where it should try to spawn?

@kickash32
Copy link
Contributor Author

kickash32 commented Aug 19, 2019

Only thing that gets me is the usage of view distance vs the min(mob spawn range, view distance) that the server does to determine where it should try to spawn?

@electronicboy It's supposed to emulate single player mob spawning so it should count all the mobs that a player can render in their area just like in single player

@electronicboy electronicboy merged commit 21faf82 into PaperMC:ver/1.14 Aug 21, 2019
@kickash32 kickash32 deleted the mob-spawning-rework branch August 21, 2019 01:19
@Sikatsu
Copy link

Sikatsu commented Aug 26, 2019

I have mob-spawn-range on 4, should I make that higher if I enable this patch or keep it as it is?

@kickash32
Copy link
Contributor Author

You can keep it as is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet