From 8b184e80830380f1c9425ee8383596e2726bccb0 Mon Sep 17 00:00:00 2001 From: LogicParrot Date: Thu, 24 Mar 2016 19:13:23 +0200 Subject: Bed's world is now saved --- src/Entities/Player.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- src/Entities/Player.h | 11 +++++++++-- 2 files changed, 47 insertions(+), 4 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 9d18cedc4..c94cec3c9 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -828,6 +828,27 @@ void cPlayer::SetCustomName(const AString & a_CustomName) +void cPlayer::SetBedPos(const Vector3i & a_Pos) +{ + m_LastBedPos = a_Pos; + m_SpawnWorld = m_World; +} + + + + + +void cPlayer::SetBedPos(const Vector3i & a_Pos, cWorld * a_World) +{ + m_LastBedPos = a_Pos; + ASSERT(a_World != nullptr); + m_SpawnWorld = a_World; +} + + + + + void cPlayer::SetFlying(bool a_IsFlying) { if (a_IsFlying == m_IsFlying) @@ -1078,12 +1099,19 @@ void cPlayer::Respawn(void) m_LifetimeTotalXp = 0; // ToDo: send score to client? How? - m_ClientHandle->SendRespawn(GetWorld()->GetDimension(), true); + m_ClientHandle->SendRespawn(m_SpawnWorld->GetDimension(), true); // Extinguish the fire: StopBurning(); - TeleportToCoords(GetLastBedPos().x, GetLastBedPos().y, GetLastBedPos().z); + if (GetWorld() != m_SpawnWorld) + { + MoveToWorld(m_SpawnWorld, false, GetLastBedPos()); + } + else + { + TeleportToCoords(GetLastBedPos().x, GetLastBedPos().y, GetLastBedPos().z); + } SetVisible(true); } @@ -1895,9 +1923,16 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World) a_World = cRoot::Get()->GetDefaultWorld(); } + m_LastBedPos.x = root.get("SpawnX", a_World->GetSpawnX()).asInt(); m_LastBedPos.y = root.get("SpawnY", a_World->GetSpawnY()).asInt(); m_LastBedPos.z = root.get("SpawnZ", a_World->GetSpawnZ()).asInt(); + AString SpawnWorldName = root.get("SpawnWorld", cRoot::Get()->GetDefaultWorld()->GetName()).asString(); + m_SpawnWorld = cRoot::Get()->GetWorld(SpawnWorldName); + if (m_SpawnWorld == nullptr) + { + m_SpawnWorld = cRoot::Get()->GetDefaultWorld(); + } // Load the player stats. // We use the default world name (like bukkit) because stats are shared between dimensions / worlds. @@ -1955,6 +1990,7 @@ bool cPlayer::SaveToDisk() root["SpawnX"] = GetLastBedPos().x; root["SpawnY"] = GetLastBedPos().y; root["SpawnZ"] = GetLastBedPos().z; + root["SpawnWorld"] = m_SpawnWorld->GetName(); if (m_World != nullptr) { diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 6d092eeb3..fae0e6177 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -459,8 +459,12 @@ public: */ Vector3i GetLastBedPos(void) const { return m_LastBedPos; } - /** Sets the player's bed (home) position */ - void SetBedPos(const Vector3i & a_Pos) { m_LastBedPos = a_Pos; } + /** Sets the player's bed (home / respawn) position to the specified position. + Sets the respawn world to the player's world. */ + void SetBedPos(const Vector3i & a_Pos); + + /** Sets the player's bed (home / respawn) position and respawn world to the specified parameters. */ + void SetBedPos(const Vector3i & a_Pos, cWorld * a_World); // tolua_end @@ -584,6 +588,9 @@ protected: /** The player's last saved bed position */ Vector3i m_LastBedPos; + /** The world which the player respawns in upon death */ + cWorld * m_SpawnWorld; + eGameMode m_GameMode; AString m_IP; -- cgit v1.2.3