Skip to content

Apply respawn radius game rule when respawning at world spawn - #3526

Open
spa77k wants to merge 3 commits into
Multiverse:v5.9from
spa77k:fix/respawn-radius
Open

spa77k wants to merge 3 commits into
Multiverse:v5.9from
spa77k:fix/respawn-radius

Conversation

@spa77k

@spa77k spa77k commented Oct 26, 2026

Copy link
Copy Markdown

Fixes #2821

When Multiverse overrides the respawn location with the world spawn, players always land exactly on the spawn block, so the respawn_radius (spawnRadius on older versions) game rule has no effect. This spreads the respawn location around the world spawn in that case, similar to vanilla:

  • No spreading when the radius is 0 or the world's game mode is adventure.
  • The radius is limited by the distance to the world border (minimum 1).
  • Candidates are checked in a random order without repeats, up to 1024.
  • For worlds with a ceiling (e.g. the nether), it searches up and down from the spawn height instead of using the highest block.
  • To avoid loading many chunks during the respawn event, candidates more than one chunk away from the spawn chunk are only used if their chunk is already loaded.
  • Falls back to the spawn location if no safe spot is found.

The game rule is looked up with GameRule.getByName, trying respawn_radius first and then spawnRadius, so older servers keep working.

Tested on Paper 26.2: with respawn_radius 10, eight respawns all landed at different spots within 10 blocks of the spawn; with 0, every respawn was at the spawn location. Also added tests in MVPlayerListenerTest.

@benwoo1110
benwoo1110 changed the base branch from main to v5.9 October 26, 2026 05:59
@benwoo1110
benwoo1110 changed the base branch from v5.9 to main October 26, 2026 06:02
@benwoo1110
benwoo1110 changed the base branch from main to v5.9 October 26, 2026 06:02

@benwoo1110 benwoo1110 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I think it's a good start, but I will have to request some improvements before this can be merged.

  1. I would prefer the logic for spawn radius to be a separate class, most likely a separate class within the teleportation package and maybe have some integration with BlockSafety and LocationManipulation (since we need to ensure the random spawn lookup location is safe for teleport). I'm open to other ideas, but definitely having all the logic just in MVPlayerListener is a no-go for me.

  2. This may be a behavioural change that some servers do not want. So applying spawn radius on respawn needs to be a config option that defaults to false for all existing installs (via config migration). Im ok with it being true for new installs.

@spa77k

spa77k commented Oct 26, 2026

Copy link
Copy Markdown
Author

Thanks for the review! I've pushed an update:

  1. Moved the spawn radius logic into a new SpawnRadiusLocator class in the teleportation package. It uses BlockSafety for the safety checks, and MVPlayerListener now only calls it.
  2. Added a spawn.use-respawn-radius config option. It defaults to true for new installs, and the config migration to version 5.3 sets it to false for existing installs.

I also made it skip worlds without sky light (e.g. the nether and the end), same as vanilla, and added tests for the config migration and the respawn behavior.

.comment("When this option is enabled and players respawn at the world's spawn location,")
.comment("they will be spread to a random safe location around it based on the `respawn_radius` game rule")
.comment("(`spawnRadius` on older versions), mimicking the vanilla behavior.")
.comment("Same as vanilla, this does not apply if the respawn radius is 0 or the world's game mode is adventure.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also something about spawn radius not applicable for worlds without sky light right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good catch. Updated the comment to mention that it also doesn't apply in worlds without sky light (e.g. the nether and the end).

.comment("----")
.comment("Set this to false if you want players to always respawn exactly at the world's spawn location.")
.defaultValue(true)
.name("use-respawn-radius")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if apply-respawn-radius fits better?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, renamed it to spawn.apply-respawn-radius (and the getter/setter to get/setApplyRespawnRadius).

* @return A safe location within the respawn radius of the spawn, or the spawn location itself if none is found.
*/
@ApiStatus.AvailableSince("5.9")
public @NotNull Location getLocationWithinSpawnRadius(@NotNull Location spawnLocation, @NotNull GameMode gameMode) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes more sense to pass in a LoadedMultiverseWorld instead of the 2 parameters separately?

Maybe as an extension we can have a method that only takes in location and does the spawn location calculation without any prechecks of gamemode and sky light?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to take a LoadedMultiverseWorld, which checks the game mode and sky light before spreading. I also added an overload that takes just a Location and does the spawn radius calculation without those checks (it still returns the location as is when the radius is 0), plus a test for it.

@github-actions

Copy link
Copy Markdown

✅ multiverse-core test build ready

Last updated for: 93a3a53a41a7f6d18ef86060751602a31c9562e5
Download: multiverse-core-pr3526.zip

View CI build and checks for more details.

@spa77k
spa77k requested a review from benwoo1110 October 28, 2026 07:23

This branch has not been deployed

No deployments
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.

[Bug]: spawnRadius isn't accounted for when a player is spawned.

2 participants