Fix rotate and ride command region threading safety
While technically region-threading safe, the rotate command should be scheduled to the `target` argument in the `rotate` command, rather than the command source. The `target` entity is the object we are modifying the rotation of, so we should schedule to that region if not in that region already.
This also adds a utility method, `Entity#runAtOrScheduleToImmediately`, which will run the `Consumer<Entity>` task immediately if it is the correct tick thread for the entity, otherwise, it will schedule to the entity scheduler immediately.
When using the `/ride` command in 1.21.11 on an entity in the same region, it works fine. However, when attempting to ride an entity out of region, it causes a crash due to how the `Entity#startRiding` command is written, making it not region threading safe when attempting to ride an entity out of the current region.
This was tested and is replicatable in the latest Folia 1.21.11 commit by forceloading a chunk(or chunk*s*) far outside the current region, and then running the command:
```
/ride @s mount @e[limit=1,type=!player,sort=furthest]
```
This effectively tries to teleport the mounter -> mount target, where the mount target and mounter are not in the same region. The fix in this PR provides a fix for the entirety of the `Entity#startRiding` method, and also a thread check at the HEAD of the method to ensure that `Entity#startRiding` is called on the region of the mounter entity.
This also includes a fix in `Entity#teleportAsync`, making `Leashable` entities drop their leash upon being teleported
合并状态:未合并 关闭于 2025-12-25 1 条评论