This brings the logic for delta movement (velocity) and
rotation in-line with Vanilla.
This is aimed to fix issues with wither skulls stacking with
end portals, as previously the velocity was set to zero which
prevented them from colliding and blowing up.
This fixes a possible problem where later the server will try to
apply movement to blocks which may be off-region. This also
correctly adhere's to Vanillas behavior, which is to clear
movementThisTick when teleporting.
We need to verify that the methods are only being invoked
on the global region.
Additionally, do not use CraftWorld#getChunk for retrieving
the Chunk object as it would trip a thread check. Rather,
we construct the CraftChunk manually as it is simply
a world+coordinates wrapper. The call never needed to block
until the chunk was loaded either.
Note that this requires the caller to be on a ticking region
or the global region, otherwise it will throw
UnsupportedOperationException.
Now the function returns the TPS for the current region.
Fixes flickering of entities without passengers when teleporting
them with teleportAsync.
We do not need to untrack/track the entity when there are no
passengers, so we should not.
There are several problems that were solved:
1. Spectating failed to follow players through cross-region/cross-world
teleporting.
2. Inability to set camera to off-region entity
3. Various crashes involved with off-region camera entity
4. Spectator does not always follow entities through portals
We fix#1 by sending ClientboundSetCameraPacket when the spectated
entity becomes in tracked, as the client appears to be unable to
correctly handle when the camera entity is removed, even temporarily.
We fix#2 by allowing off-region entities that are not dead.
However, this required the teleportation code in both setCamera
and the ServerPlayer#tick method to be modified to correctly
handle off-region camera targets.
We fix#3 by correctly teleporting to off-region locations
when needed.
We fix#4 by following the Bukkit entity. This allows spectator
mode to properly follow non-player entities through portals.
Issues #1 (cross-world) and #4 are probably present in Paper/Vanilla, however
solving #2 and #3 required a solution for these.
Fixes https://github.com/PaperMC/Folia/issues/324
Instead of relying on COLLISION_FLAG_COLLIDE_WITH_UNLOADED_CHUNKS,
we will force a chunk not owned by the current region to collide
so that entities moving at high speed cannot move out of region.
The owner of the projectile would need to be retrieved, which
may trip a thread check. We do not track ender pearls anyways,
so the registration logic does nothing regardless.
Fixes https://github.com/PaperMC/Folia/issues/315
We cannot guarantee that the current region owns the chunk
associated with the ChunkData. As a result, more than 1 region
may write to the field.
Additionally, we did not include any logic to adjust the field during
a region merge or split - which would leave invalid data in the field.
As a result, the nearbyPlayers data retrieved from the ChunkData
was possibly invalid which may have lead to entity tracker desync
problems.
Fixes https://github.com/PaperMC/Folia/issues/317
It is possible that when the reference count is retrieved that
the ticket updates have not yet been processed, which means
that the region section at the queued position may not exist or may
become nonexistant while or after the task is being added.
This restructures the reference counting code to now refer to
both a reference counter and a flag indicating whether ticket
updates are processed.
Fixes https://github.com/PaperMC/Folia/issues/262
This issue shows the race condition where the region becomes
nonexistant.
If we cannot find a spawn pos in the spawn radius,
use the same fallback logic as when the world type or player's
gamemode does not support spawn selection. This adjusts the spawn
position to not be inside a wall or on water.