diff options
Diffstat (limited to '')
-rw-r--r-- | src/Entities/Player.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 767ee2061..5606e9668 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -176,6 +176,7 @@ cPlayer::~cPlayer(void) void cPlayer::Destroyed() { CloseWindow(false); + super::Destroyed(); } @@ -1681,7 +1682,6 @@ void cPlayer::FreezeInternal(const Vector3d & a_Location, bool a_ManuallyFrozen) bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d a_NewPosition) { ASSERT(a_World != nullptr); - if (GetWorld() == a_World) { // Don't move to same world @@ -1695,6 +1695,23 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d return false; } + // Remove player from chunk + if (!GetWorld()->DoWithChunk(GetChunkX(), GetChunkZ(), [this](cChunk & a_Chunk) -> bool + { + a_Chunk.SafeRemoveEntity(this); + return true; + })) + { + LOGD("Entity Teleportation failed! Didn't find the source chunk!\n"); + return false; + } + + // Remove player from world + GetWorld()->RemovePlayer(this, false); + // Stop all mobs from targeting this player + + StopEveryoneFromTargetingMe(); + // Send the respawn packet: if (a_ShouldSendRespawn && (m_ClientHandle != nullptr)) { @@ -1704,12 +1721,11 @@ bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d // Broadcast for other people that the player is gone. GetWorld()->BroadcastDestroyEntity(*this); - // Remove player from the old world - SetWorldTravellingFrom(GetWorld()); // cChunk handles entity removal - GetWorld()->RemovePlayer(this, false); - SetPosition(a_NewPosition); + // Stop all mobs from targeting this player + StopEveryoneFromTargetingMe(); + // Queue adding player to the new world, including all the necessary adjustments to the object a_World->AddPlayer(this); cWorld * OldWorld = cRoot::Get()->GetWorld(GetWorld()->GetName()); // Required for the hook HOOK_ENTITY_CHANGED_WORLD |