summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-06-01 19:46:59 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-06-01 19:46:59 +0200
commit576f89c1d5bdb067c0ca06237440f754d80bd13c (patch)
treecae685487d49fd420d68c850e87cbdec467e5fca /src/Entities
parentImplemented end and nether portals (diff)
downloadcuberite-576f89c1d5bdb067c0ca06237440f754d80bd13c.tar
cuberite-576f89c1d5bdb067c0ca06237440f754d80bd13c.tar.gz
cuberite-576f89c1d5bdb067c0ca06237440f754d80bd13c.tar.bz2
cuberite-576f89c1d5bdb067c0ca06237440f754d80bd13c.tar.lz
cuberite-576f89c1d5bdb067c0ca06237440f754d80bd13c.tar.xz
cuberite-576f89c1d5bdb067c0ca06237440f754d80bd13c.tar.zst
cuberite-576f89c1d5bdb067c0ca06237440f754d80bd13c.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp6
-rw-r--r--src/Entities/Player.cpp35
-rw-r--r--src/Entities/Player.h15
3 files changed, 40 insertions, 16 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index b5c272cf2..de6c628e9 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1093,6 +1093,12 @@ void cEntity::DetectPortal()
File.WriteFile(OverworldName + "/world.ini");
MoveToWorld(OverworldName, cRoot::Get()->CreateAndInitializeWorld(OverworldName));
+
+ if (IsPlayer())
+ {
+ cPlayer * Player = (cPlayer *)this;
+ Player->TeleportToCoords(Player->GetLastBedPos().x, Player->GetLastBedPos().y, Player->GetLastBedPos().z);
+ }
break;
}
case dimOverworld:
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 140b98d5d..3058d6e94 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -82,13 +82,13 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
m_PlayerName = a_PlayerName;
- if (!LoadFromDisk())
+ cWorld * World;
+ if (!LoadFromDisk(World))
{
m_Inventory.Clear();
- cWorld * DefaultWorld = cRoot::Get()->GetDefaultWorld();
- SetPosX(DefaultWorld->GetSpawnX());
- SetPosY(DefaultWorld->GetSpawnY());
- SetPosZ(DefaultWorld->GetSpawnZ());
+ SetPosX(World->GetSpawnX());
+ SetPosY(World->GetSpawnY());
+ SetPosZ(World->GetSpawnZ());
LOGD("Player \"%s\" is connecting for the first time, spawning at default world spawn {%.2f, %.2f, %.2f}",
a_PlayerName.c_str(), GetPosX(), GetPosY(), GetPosZ()
@@ -101,11 +101,6 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
if (m_GameMode == gmNotSet)
{
- cWorld * World = cRoot::Get()->GetWorld(GetLoadedWorldName());
- if (World == NULL)
- {
- World = cRoot::Get()->GetDefaultWorld();
- }
if (World->IsGameModeCreative())
{
m_CanFly = true;
@@ -955,7 +950,7 @@ void cPlayer::Respawn(void)
// Extinguish the fire:
StopBurning();
- TeleportToCoords(GetWorld()->GetSpawnX(), GetWorld()->GetSpawnY(), GetWorld()->GetSpawnZ());
+ TeleportToCoords(GetLastBedPos().x, GetLastBedPos().y, GetLastBedPos().z);
SetVisible(true);
}
@@ -1614,6 +1609,8 @@ bool cPlayer::MoveToWorld(const AString & a_WorldName, cWorld * a_World)
if (SendRespawn)
{
GetClientHandle()->SendPlayerMoveLook();
+ GetClientHandle()->SendHealth();
+ GetClientHandle()->SendWholeInventory((cWindow &)GetInventory());
}
return true;
@@ -1662,8 +1659,14 @@ void cPlayer::LoadPermissionsFromDisk()
-bool cPlayer::LoadFromDisk()
+bool cPlayer::LoadFromDisk(cWorld * a_World)
{
+ a_World = cRoot::Get()->GetWorld(GetLoadedWorldName());
+ if (a_World == NULL)
+ {
+ a_World = cRoot::Get()->GetDefaultWorld();
+ }
+
LoadPermissionsFromDisk();
// Log player permissions, cause it's what the cool kids do
@@ -1724,6 +1727,9 @@ bool cPlayer::LoadFromDisk()
m_LifetimeTotalXp = (short) root.get("xpTotal", 0).asInt();
m_CurrentXp = (short) root.get("xpCurrent", 0).asInt();
m_IsFlying = root.get("isflying", 0).asBool();
+ 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();
m_GameMode = (eGameMode) root.get("gamemode", eGameMode_NotSet).asInt();
@@ -1742,7 +1748,7 @@ bool cPlayer::LoadFromDisk()
StatSerializer.Load();
LOGD("Player \"%s\" was read from file, spawning at {%.2f, %.2f, %.2f} in world \"%s\"",
- GetName().c_str(), GetPosX(), GetPosY(), GetPosZ(), m_LoadedWorldName.c_str()
+ GetName().c_str(), GetPosX(), GetPosY(), GetPosZ(), GetLoadedWorldName().c_str()
);
return true;
@@ -1784,6 +1790,9 @@ bool cPlayer::SaveToDisk()
root["foodExhaustion"] = m_FoodExhaustionLevel;
root["world"] = GetWorld()->GetName();
root["isflying"] = IsFlying();
+ root["SpawnX"] = GetLastBedPos().x;
+ root["SpawnY"] = GetLastBedPos().y;
+ root["SpawnZ"] = GetLastBedPos().z;
if (m_GameMode == GetWorld()->GetGameMode())
{
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 582f79b86..5c0b61064 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -331,7 +331,7 @@ public:
virtual bool MoveToWorld(const AString & a_WorldName, cWorld * a_World = NULL) override; // tolua_export
bool SaveToDisk(void);
- bool LoadFromDisk(void);
+ bool LoadFromDisk(cWorld * a_World);
void LoadPermissionsFromDisk(void); // tolua_export
const AString & GetLoadedWorldName() { return m_LoadedWorldName; }
@@ -391,11 +391,19 @@ public:
/** If true the player can fly even when he's not in creative. */
void SetCanFly(bool a_CanFly);
+ /** Gets the last position that the player slept in */
+ Vector3i GetLastBedPos(void) const { return m_LastBedPos; }
+
+ /** Sets the player's bed (home) position */
+ void SetBedPos(const Vector3i & a_Pos) { m_LastBedPos = a_Pos; }
+
/** Update movement-related statistics. */
void UpdateMovementStats(const Vector3d & a_DeltaPos);
/** Returns wheter the player can fly or not. */
virtual bool CanFly(void) const { return m_CanFly; }
+
+
// tolua_end
// cEntity overrides:
@@ -450,6 +458,9 @@ protected:
cWindow * m_CurrentWindow;
cWindow * m_InventoryWindow;
+ /** The player's last saved bed position */
+ Vector3i m_LastBedPos;
+
char m_Color;
eGameMode m_GameMode;
@@ -508,8 +519,6 @@ protected:
cStatManager m_Stats;
-
-
void ResolvePermissions(void);
void ResolveGroups(void);