summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ClientHandle.cpp4
-rw-r--r--src/Entities/Entity.cpp23
-rw-r--r--src/Entities/Entity.h8
-rw-r--r--src/Entities/Player.cpp2
-rw-r--r--src/Entities/Player.h6
-rw-r--r--src/World.cpp9
6 files changed, 28 insertions, 24 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index af53d3623..aaed483e2 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -120,8 +120,8 @@ cClientHandle::~cClientHandle()
}
if (World != NULL)
{
- m_Player->SetWorldTravellingFrom(NULL); // Make sure that the player entity is actually removed
- World->RemovePlayer(m_Player); // Must be called before cPlayer::Destroy() as otherwise cChunk tries to delete the player, and then we do it again
+ m_Player->SetWorldTravellingFrom(NULL); // Make sure that the player entity is actually removed
+ World->RemovePlayer(m_Player); // Must be called before cPlayer::Destroy() as otherwise cChunk tries to delete the player, and then we do it again
m_Player->Destroy();
}
delete m_Player;
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 68bfabb30..45c347aeb 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1034,11 +1034,13 @@ bool cEntity::DetectPortal()
{
if (GetWorld()->GetNetherWorldName().empty() && GetWorld()->GetEndWorldName().empty())
{
+ // Teleportation to either dimension not enabled, don't bother proceeding
return false;
}
}
else if (GetWorld()->GetLinkedOverworldName().empty())
{
+ // Overworld teleportation disabled, abort
return false;
}
@@ -1051,11 +1053,13 @@ bool cEntity::DetectPortal()
{
if (m_PortalCooldownData.m_ShouldPreventTeleportation)
{
+ // Just exited a portal, don't teleport again
return false;
}
if (IsPlayer() && !((cPlayer *)this)->IsGameModeCreative() && m_PortalCooldownData.m_TicksDelayed != 80)
{
+ // Delay teleportation for four seconds if the entity is a non-creative player
m_PortalCooldownData.m_TicksDelayed++;
return false;
}
@@ -1070,11 +1074,11 @@ bool cEntity::DetectPortal()
return false;
}
- m_PortalCooldownData.m_ShouldPreventTeleportation = true; // Stop portals from working on respawn
+ m_PortalCooldownData.m_ShouldPreventTeleportation = true; // Stop portals from working on respawn
if (IsPlayer())
{
- ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimOverworld);
+ ((cPlayer *)this)->GetClientHandle()->SendRespawn(dimOverworld); // Send a respawn packet before world is loaded/generated so the client isn't left in limbo
}
return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false);
@@ -1086,7 +1090,7 @@ bool cEntity::DetectPortal()
return false;
}
- m_PortalCooldownData.m_ShouldPreventTeleportation = true; // Stop portals from working on respawn
+ m_PortalCooldownData.m_ShouldPreventTeleportation = true;
if (IsPlayer())
{
@@ -1115,7 +1119,7 @@ bool cEntity::DetectPortal()
return false;
}
- m_PortalCooldownData.m_ShouldPreventTeleportation = true; // Stop portals from working on respawn
+ m_PortalCooldownData.m_ShouldPreventTeleportation = true;
if (IsPlayer())
{
@@ -1133,7 +1137,7 @@ bool cEntity::DetectPortal()
return false;
}
- m_PortalCooldownData.m_ShouldPreventTeleportation = true; // Stop portals from working on respawn
+ m_PortalCooldownData.m_ShouldPreventTeleportation = true;
if (IsPlayer())
{
@@ -1152,7 +1156,7 @@ bool cEntity::DetectPortal()
// Allow portals to work again
m_PortalCooldownData.m_ShouldPreventTeleportation = false;
- m_PortalCooldownData.m_ShouldPreventTeleportation = 0;
+ m_PortalCooldownData.m_TicksDelayed = 0;
return false;
}
@@ -1160,7 +1164,7 @@ bool cEntity::DetectPortal()
-bool cEntity::MoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
+bool cEntity::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
{
UNUSED(a_ShouldSendRespawn);
ASSERT(a_World != NULL);
@@ -1172,11 +1176,12 @@ bool cEntity::MoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
}
// Remove all links to the old world
- SetWorldTravellingFrom(GetWorld()); // cChunk handles entity removal
+ SetWorldTravellingFrom(GetWorld()); // cChunk::Tick() handles entity removal
GetWorld()->BroadcastDestroyEntity(*this);
// Queue add to new world
a_World->AddEntity(this);
+ SetWorld(a_World);
return true;
}
@@ -1194,7 +1199,7 @@ bool cEntity::MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn)
return false;
}
- return MoveToWorld(World, a_ShouldSendRespawn);
+ return DoMoveToWorld(World, a_ShouldSendRespawn);
}
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index 62a4097f3..4b096b475 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -385,15 +385,17 @@ public:
virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ);
/** Moves entity to specified world, taking a world pointer */
- virtual bool MoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn = true);
+ bool MoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn = true) { return DoMoveToWorld(a_World, a_ShouldSendRespawn); }
/** Moves entity to specified world, taking a world name */
bool MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn = true);
// tolua_end
+ virtual bool DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn);
+
/** Returns if the entity is travelling away from a specified world */
- bool IsWorldTravellingFrom(cWorld * a_World) const { return m_WorldTravellingFrom == a_World; }
+ bool IsWorldTravellingFrom(cWorld * a_World) const { return (m_WorldTravellingFrom == a_World); }
/** Sets the world the entity will be leaving */
void SetWorldTravellingFrom(cWorld * a_World) { m_WorldTravellingFrom = a_World; }
@@ -500,7 +502,7 @@ protected:
bool m_IsInitialized;
/** World entity is travelling from
- Set by MoveToWorld and back to NULL when the entity is removed by the old chunk
+ Set to a valid world pointer by MoveToWorld; reset to NULL when the entity is removed from the old world
Can't be a simple boolean as context switches between worlds may leave the new chunk processing (and therefore immediately removing) the entity before the old chunk could remove it
*/
cWorld * m_WorldTravellingFrom;
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 087ac448f..406da8baa 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1609,7 +1609,7 @@ void cPlayer::TossItems(const cItems & a_Items)
-bool cPlayer::MoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
+bool cPlayer::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
{
ASSERT(a_World != NULL);
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index d1b3a0339..c28802eec 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -333,7 +333,7 @@ public:
/** Moves the player to the specified world.
Returns true if successful, false on failure (world not found). */
- virtual bool MoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn = true) override; // tolua_export
+ virtual bool DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn) override;
/** Saves all player data, such as inventory, to JSON */
bool SaveToDisk(void);
@@ -341,13 +341,13 @@ public:
typedef cWorld * cWorldPtr;
/** Loads the player data from the disk file
- Takes a (NULL) cWorld pointer which it will assign a value to based on either the loaded world or default world by calling LoadFromFile()
+ Sets a_World to the world where the player will spawn, based on the stored world name or the default world by calling LoadFromFile()
Returns true on success, false on failure
*/
bool LoadFromDisk(cWorldPtr & a_World);
/** Loads the player data from the specified file
- Takes a (NULL) cWorld pointer which it will assign a value to based on either the loaded world or default world
+ Sets a_World to the world where the player will spawn, based on the stored world name or the default world
Returns true on success, false on failure
*/
bool LoadFromFile(const AString & a_FileName, cWorldPtr & a_World);
diff --git a/src/World.cpp b/src/World.cpp
index 9cbaf48fb..bcb2fa88d 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -66,9 +66,6 @@ const int TIME_NIGHT_END = 22812;
const int TIME_SUNRISE = 23999;
const int TIME_SPAWN_DIVISOR = 148;
-#define DEFAULT_NETHER_NAME GetName() + "_nether"
-#define DEFAULT_END_NAME GetName() + "_end"
-
@@ -255,7 +252,7 @@ cWorld::cWorld(const AString & a_WorldName, eDimension a_Dimension, const AStrin
m_Scoreboard(this),
m_MapManager(this),
m_GeneratorCallbacks(*this),
- m_TickThread(*this)
+ m_TickThread(*this)
{
LOGD("cWorld::cWorld(\"%s\")", a_WorldName.c_str());
@@ -580,8 +577,8 @@ void cWorld::Start(void)
if (GetDimension() == dimOverworld)
{
- m_NetherWorldName = IniFile.GetValueSet("LinkedWorlds", "NetherWorldName", DEFAULT_NETHER_NAME);
- m_EndWorldName = IniFile.GetValueSet("LinkedWorlds", "EndWorldName", DEFAULT_END_NAME);
+ m_NetherWorldName = IniFile.GetValueSet("LinkedWorlds", "NetherWorldName", GetName() + "_nether");
+ m_EndWorldName = IniFile.GetValueSet("LinkedWorlds", "EndWorldName", GetName() + "_end");
}
else
{