Skip to content

Reset stored positions before placing entities during async teleport - #555

Open
Cherry7593 wants to merge 1 commit into
PaperMC:ver/26.3.xfrom
Cherry7593:fix/reset-stored-positions-before-place-sync
Open

Cherry7593 wants to merge 1 commit into
PaperMC:ver/26.3.xfrom
Cherry7593:fix/reset-stored-positions-before-place-sync

Conversation

@Cherry7593

Copy link
Copy Markdown

Cause

Entity#resetStoredPositions() clears cached physics positions (mainSupportingBlockPos, movementThisTick, and lastClimbablePos on LivingEntity) so they do not trip region thread checks after a teleport. While teleportSyncSameRegion calls resetStoredPositions() immediately after updating the position, async teleports and player respawns (Entity#transform, ServerPlayer#respawn, and Entity#placeInAsync) currently only reset them later in postChangeDimension() — after placeSingleSync() has already called destination.addDuringTeleport(this).

When an entity (for example, a player wearing Soul Speed boots) is placed into the destination region via placeInAsync while nearby players immediately start tracking it, the following call chain runs before postChangeDimension():

Entity#placeInAsync
  -> ServerPlayer#placeSingleSync
  -> ServerLevel#addDuringTeleport
  -> ChunkMap#addEntity
  -> ServerEntity#sendPairingData
  -> LivingEntity#detectEquipmentUpdates
  -> LivingEntity#collectEquipmentChanges
  -> EnchantmentHelper#runLocationChangedEffects
  -> MovementAffectedByPredicate#matches
  -> Entity#getBlockPosBelowThatAffectsMyMovement -> Entity#getOnPos
  -> LocationPredicate#matches -> TickThread.ensureTickThread ("Cannot test a location predicate off-region")

If the stale mainSupportingBlockPos from before the teleport/respawn still points to a loaded chunk in another region of the destination world, Entity#getOnPos returns that stale off-region position and LocationPredicate#matches throws an IllegalStateException, crashing the region tick task and triggering a server shutdown.

Fix

  • Call node.root.resetStoredPositions() before node.root.placeSingleSync(...) in Entity#placeInAsync, covering async teleports, portal transitions, player respawns, and passenger trees before addDuringTeleport runs.
  • Call this.resetStoredPositions() in Entity#transform(Vec3, Float, Float, Vec3) right after this.setOldPosAndRot(), matching teleportSyncSameRegion.
  • Keep the existing resetStoredPositions() call in postChangeDimension() as a safe no-op for other callers.

Verification

  • Verified all 28 Entity.java hunks and line-offset headers in 0001-Region-Threading-Base.patch.
  • Full patch application and build will be verified by GitHub Actions CI (Patch and Build) on this PR.

Copilot AI lite review requested due to automatic review settings December 4, 2026 19:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

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.

2 participants