Fix villager brain initialization before destination world is applied during async portal teleport#446
Open
nekoneko2872 wants to merge 1 commit intoPaperMC:ver/1.21.11from
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a Folia villager Nether portal bug where villager AI could be initialized before the destination world was fully applied during async portal teleportation.
As a result,
Villager.makeBrain()andBrain.updateActivityFromSchedule()could run while the villager was still in a temporary world-mismatch state.What changed
How it works
Entity.transformForAsyncTeleport(...)now exposes the destination world context during async teleport restore.Villager.makeBrain()detects that async teleport destination context and marks brain initialization as deferred.Brain.updateActivityFromSchedule(...)call is skipped while the villager is still waiting for the destination world to be fully applied.Root cause
The async portal flow could reach the villager brain setup path in this order:
netherPortalLogicAsync -> portalToAsync -> Entity.transformForAsyncTeleport -> Villager.makeBrain -> Brain.updateActivityFromScheduleAt that point, the destination world was not always fully reflected on the entity yet, which made villager AI initialization observe the wrong world state.
Result
With this change, villager brain initialization no longer runs before the destination world is applied, and temporary world mismatches are handled safely by deferring initialization until a later tick.
Testing