1
0

Suggestions

This commit is contained in:
Tiger Wang 2014-07-23 21:12:59 +01:00
parent a28b0dc120
commit 1156914dd6
6 changed files with 28 additions and 24 deletions

View File

@ -1034,11 +1034,13 @@ bool cEntity::DetectPortal()
{ {
if (GetWorld()->GetNetherWorldName().empty() && GetWorld()->GetEndWorldName().empty()) if (GetWorld()->GetNetherWorldName().empty() && GetWorld()->GetEndWorldName().empty())
{ {
// Teleportation to either dimension not enabled, don't bother proceeding
return false; return false;
} }
} }
else if (GetWorld()->GetLinkedOverworldName().empty()) else if (GetWorld()->GetLinkedOverworldName().empty())
{ {
// Overworld teleportation disabled, abort
return false; return false;
} }
@ -1051,11 +1053,13 @@ bool cEntity::DetectPortal()
{ {
if (m_PortalCooldownData.m_ShouldPreventTeleportation) if (m_PortalCooldownData.m_ShouldPreventTeleportation)
{ {
// Just exited a portal, don't teleport again
return false; return false;
} }
if (IsPlayer() && !((cPlayer *)this)->IsGameModeCreative() && m_PortalCooldownData.m_TicksDelayed != 80) 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++; m_PortalCooldownData.m_TicksDelayed++;
return false; return false;
} }
@ -1074,7 +1078,7 @@ bool cEntity::DetectPortal()
if (IsPlayer()) 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); return MoveToWorld(cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()), false);
@ -1086,7 +1090,7 @@ bool cEntity::DetectPortal()
return false; return false;
} }
m_PortalCooldownData.m_ShouldPreventTeleportation = true; // Stop portals from working on respawn m_PortalCooldownData.m_ShouldPreventTeleportation = true;
if (IsPlayer()) if (IsPlayer())
{ {
@ -1115,7 +1119,7 @@ bool cEntity::DetectPortal()
return false; return false;
} }
m_PortalCooldownData.m_ShouldPreventTeleportation = true; // Stop portals from working on respawn m_PortalCooldownData.m_ShouldPreventTeleportation = true;
if (IsPlayer()) if (IsPlayer())
{ {
@ -1133,7 +1137,7 @@ bool cEntity::DetectPortal()
return false; return false;
} }
m_PortalCooldownData.m_ShouldPreventTeleportation = true; // Stop portals from working on respawn m_PortalCooldownData.m_ShouldPreventTeleportation = true;
if (IsPlayer()) if (IsPlayer())
{ {
@ -1152,7 +1156,7 @@ bool cEntity::DetectPortal()
// Allow portals to work again // Allow portals to work again
m_PortalCooldownData.m_ShouldPreventTeleportation = false; m_PortalCooldownData.m_ShouldPreventTeleportation = false;
m_PortalCooldownData.m_ShouldPreventTeleportation = 0; m_PortalCooldownData.m_TicksDelayed = 0;
return false; 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); UNUSED(a_ShouldSendRespawn);
ASSERT(a_World != NULL); ASSERT(a_World != NULL);
@ -1172,11 +1176,12 @@ bool cEntity::MoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn)
} }
// Remove all links to the old world // Remove all links to the old world
SetWorldTravellingFrom(GetWorld()); // cChunk handles entity removal SetWorldTravellingFrom(GetWorld()); // cChunk::Tick() handles entity removal
GetWorld()->BroadcastDestroyEntity(*this); GetWorld()->BroadcastDestroyEntity(*this);
// Queue add to new world // Queue add to new world
a_World->AddEntity(this); a_World->AddEntity(this);
SetWorld(a_World);
return true; return true;
} }
@ -1194,7 +1199,7 @@ bool cEntity::MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn)
return false; return false;
} }
return MoveToWorld(World, a_ShouldSendRespawn); return DoMoveToWorld(World, a_ShouldSendRespawn);
} }

View File

@ -385,15 +385,17 @@ public:
virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ); virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ);
/** Moves entity to specified world, taking a world pointer */ /** 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 */ /** Moves entity to specified world, taking a world name */
bool MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn = true); bool MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn = true);
// tolua_end // tolua_end
virtual bool DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn);
/** Returns if the entity is travelling away from a specified world */ /** 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 */ /** Sets the world the entity will be leaving */
void SetWorldTravellingFrom(cWorld * a_World) { m_WorldTravellingFrom = a_World; } void SetWorldTravellingFrom(cWorld * a_World) { m_WorldTravellingFrom = a_World; }
@ -500,7 +502,7 @@ protected:
bool m_IsInitialized; bool m_IsInitialized;
/** World entity is travelling from /** 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 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; cWorld * m_WorldTravellingFrom;

View File

@ -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); ASSERT(a_World != NULL);

View File

@ -333,7 +333,7 @@ public:
/** Moves the player to the specified world. /** Moves the player to the specified world.
Returns true if successful, false on failure (world not found). */ 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 */ /** Saves all player data, such as inventory, to JSON */
bool SaveToDisk(void); bool SaveToDisk(void);
@ -341,13 +341,13 @@ public:
typedef cWorld * cWorldPtr; typedef cWorld * cWorldPtr;
/** Loads the player data from the disk file /** 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 Returns true on success, false on failure
*/ */
bool LoadFromDisk(cWorldPtr & a_World); bool LoadFromDisk(cWorldPtr & a_World);
/** Loads the player data from the specified file /** 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 Returns true on success, false on failure
*/ */
bool LoadFromFile(const AString & a_FileName, cWorldPtr & a_World); bool LoadFromFile(const AString & a_FileName, cWorldPtr & a_World);

View File

@ -66,9 +66,6 @@ const int TIME_NIGHT_END = 22812;
const int TIME_SUNRISE = 23999; const int TIME_SUNRISE = 23999;
const int TIME_SPAWN_DIVISOR = 148; const int TIME_SPAWN_DIVISOR = 148;
#define DEFAULT_NETHER_NAME GetName() + "_nether"
#define DEFAULT_END_NAME GetName() + "_end"
@ -580,8 +577,8 @@ void cWorld::Start(void)
if (GetDimension() == dimOverworld) if (GetDimension() == dimOverworld)
{ {
m_NetherWorldName = IniFile.GetValueSet("LinkedWorlds", "NetherWorldName", DEFAULT_NETHER_NAME); m_NetherWorldName = IniFile.GetValueSet("LinkedWorlds", "NetherWorldName", GetName() + "_nether");
m_EndWorldName = IniFile.GetValueSet("LinkedWorlds", "EndWorldName", DEFAULT_END_NAME); m_EndWorldName = IniFile.GetValueSet("LinkedWorlds", "EndWorldName", GetName() + "_end");
} }
else else
{ {