Fix cross-region teleportation in SpreadPlayersCommand#35
Fix cross-region teleportation in SpreadPlayersCommand#35UnlimitedBytes wants to merge 2 commits intoMultiPaper:ver/1.21.11from
Conversation
|
Considering whether public boolean isSafe(BlockGetter level, int y) {
BlockPos blockPos = BlockPos.containing(this.x, this.getSpawnY(level, y) - 1, this.z);
BlockState blockState = level.getBlockState(blockPos);
return blockPos.getY() < y && !blockState.liquid() && !blockState.is(BlockTags.FIRE);
} |
Use teleportAsync to properly handle teleporting entities to positions that may be in different regions. This prevents "Cannot move entity off-main" errors when using /spreadplayers command.
|
I investigated this. However, we cannot practically synchronize it because:
I tested this and confirmed the deadlock - the server hung for 20+ seconds until the watchdog killed it. Resolution: Accept the minor race condition for For Options to make this thread-safe would require either:
|
57314e0 to
cd1df24
Compare
|
Many commands are already fully asynchronous such as |
Summary
/spreadplayerscommandteleportAsyncinstead of synchronousteleportToto properly handle cross-region teleportationProblem
The
/spreadplayerscommand was causing thread errors because it attempted to teleport entities synchronously to random positions that could be in different regions than the current thread owns. This resulted in moonrise thread check failures during the position update.Solution
Replaced the synchronous
entity.teleportTo()call withentity.getBukkitEntity().teleportAsync(), which schedules the teleport on the entity's task scheduler. This ensures the teleport executes when the entity is being ticked by the appropriate thread that owns both the source and destination regions.Test plan
/spreadplayers ~ ~ 5 1000 false @aexecutes without errors