Fix villager brain initialization before destination world is applied during async portal teleport #446
No reviewers
Labels
No labels
documentation
good first issue
help wanted
resolution: duplicate
resolution: invalid
resolution: won't fix
status: needs triage
type: bug
type: feature
type: performance
type: question
version: 1.19.4
version: 1.20
version: 1.20.1
version: 1.20.2
version: 1.20.4
version: 1.20.6
version: 1.21.11
version: 1.21.4
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Minecraft/Folia!446
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "nekoneko2872/ver/1.21.11-fixed"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.