1
0
Fork 0

MoveToWorld must always be provided a world

This commit is contained in:
Tiger Wang 2020-04-10 21:08:19 +01:00
parent e98f93a079
commit 50893667db
5 changed files with 47 additions and 45 deletions

View File

@ -1407,7 +1407,7 @@ bool cEntity::DetectPortal()
cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName()); cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName());
ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start() ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start()
LOGD("Jumping %s -> %s", DimensionToString(dimNether).c_str(), DimensionToString(DestionationDim).c_str()); LOGD("Jumping %s -> %s", DimensionToString(dimNether).c_str(), DimensionToString(DestionationDim).c_str());
new cNetherPortalScanner(*this, TargetWorld, TargetPos, cChunkDef::Height); new cNetherPortalScanner(*this, *TargetWorld, TargetPos, cChunkDef::Height);
return true; return true;
} }
// Nether portal in the overworld // Nether portal in the overworld
@ -1439,7 +1439,7 @@ bool cEntity::DetectPortal()
cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedNetherWorldName()); cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedNetherWorldName());
ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start() ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start()
LOGD("Jumping %s -> %s", DimensionToString(dimOverworld).c_str(), DimensionToString(DestionationDim).c_str()); LOGD("Jumping %s -> %s", DimensionToString(dimOverworld).c_str(), DimensionToString(DestionationDim).c_str());
new cNetherPortalScanner(*this, TargetWorld, TargetPos, (cChunkDef::Height / 2)); new cNetherPortalScanner(*this, *TargetWorld, TargetPos, (cChunkDef::Height / 2));
return true; return true;
} }
} }
@ -1487,7 +1487,7 @@ bool cEntity::DetectPortal()
cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName()); cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName());
ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start() ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start()
LOGD("Jumping %s -> %s", DimensionToString(dimEnd).c_str(), DimensionToString(DestionationDim).c_str()); LOGD("Jumping %s -> %s", DimensionToString(dimEnd).c_str(), DimensionToString(DestionationDim).c_str());
return MoveToWorld(TargetWorld, false); return MoveToWorld(*TargetWorld, false);
} }
// End portal in the overworld // End portal in the overworld
else else
@ -1513,7 +1513,7 @@ bool cEntity::DetectPortal()
cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedEndWorldName()); cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedEndWorldName());
ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start() ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start()
LOGD("Jumping %s -> %s", DimensionToString(dimOverworld).c_str(), DimensionToString(DestionationDim).c_str()); LOGD("Jumping %s -> %s", DimensionToString(dimOverworld).c_str(), DimensionToString(DestionationDim).c_str());
return MoveToWorld(TargetWorld, false); return MoveToWorld(*TargetWorld, false);
} }
} }
@ -1577,25 +1577,27 @@ void cEntity::DoMoveToWorld(const sWorldChangeInfo & a_WorldChangeInfo)
bool cEntity::MoveToWorld(cWorld * a_World, Vector3d a_NewPosition, bool a_SetPortalCooldown, bool a_ShouldSendRespawn) bool cEntity::MoveToWorld(cWorld & a_World, Vector3d a_NewPosition, bool a_SetPortalCooldown, bool a_ShouldSendRespawn)
{ {
ASSERT(a_World != nullptr);
// Ask the plugins if the entity is allowed to change world // Ask the plugins if the entity is allowed to change world
if (cRoot::Get()->GetPluginManager()->CallHookEntityChangingWorld(*this, *a_World)) if (cRoot::Get()->GetPluginManager()->CallHookEntityChangingWorld(*this, a_World))
{ {
// A Plugin isn't allowing the entity to change world // A Plugin isn't allowing the entity to change world
return false; return false;
} }
if (m_WorldChangeInfo.m_NewWorld != nullptr) const auto OldWorld = m_WorldChangeInfo.m_NewWorld;
{
// Avoid scheduling multiple warp tasks
return true;
}
// Create new world change info // Create new world change info
m_WorldChangeInfo = { a_World, a_NewPosition, a_SetPortalCooldown, a_ShouldSendRespawn }; // (The last warp command always takes precedence)
m_WorldChangeInfo = { &a_World, a_NewPosition, a_SetPortalCooldown, a_ShouldSendRespawn };
if (OldWorld != nullptr)
{
// Avoid scheduling multiple warp tasks
// Only move ahead if we came from a "not warping" state
return true;
}
// TODO: move to capture when C++14 // TODO: move to capture when C++14
const auto EntityID = GetUniqueID(); const auto EntityID = GetUniqueID();
@ -1636,9 +1638,9 @@ bool cEntity::MoveToWorld(cWorld * a_World, Vector3d a_NewPosition, bool a_SetPo
bool cEntity::MoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn) bool cEntity::MoveToWorld(cWorld & a_World, bool a_ShouldSendRespawn)
{ {
return MoveToWorld(a_World, a_ShouldSendRespawn, Vector3d(a_World->GetSpawnX(), a_World->GetSpawnY(), a_World->GetSpawnZ())); return MoveToWorld(a_World, a_ShouldSendRespawn, Vector3d(a_World.GetSpawnX(), a_World.GetSpawnY(), a_World.GetSpawnZ()));
} }
@ -1654,7 +1656,7 @@ bool cEntity::MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn)
return false; return false;
} }
return MoveToWorld(World, Vector3d(World->GetSpawnX(), World->GetSpawnY(), World->GetSpawnZ()), false, a_ShouldSendRespawn); return MoveToWorld(*World, Vector3d(World->GetSpawnX(), World->GetSpawnY(), World->GetSpawnZ()), false, a_ShouldSendRespawn);
} }

View File

@ -465,21 +465,21 @@ 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);
/** Schedules a MoveToWorld call to occur on the next Tick of the entity */ /** Schedules a MoveToWorld call to occur on the next Tick of the entity */
OBSOLETE void ScheduleMoveToWorld(cWorld * a_World, Vector3d a_NewPosition, bool a_ShouldSetPortalCooldown = false, bool a_ShouldSendRespawn = true) OBSOLETE void ScheduleMoveToWorld(cWorld & a_World, Vector3d a_NewPosition, bool a_ShouldSetPortalCooldown = false, bool a_ShouldSendRespawn = true)
{ {
LOGWARNING("ScheduleMoveToWorld is deprecated, use MoveToWorld instead"); LOGWARNING("ScheduleMoveToWorld is deprecated, use MoveToWorld instead");
MoveToWorld(a_World, a_NewPosition, a_ShouldSetPortalCooldown, a_ShouldSendRespawn); MoveToWorld(a_World, a_NewPosition, a_ShouldSetPortalCooldown, a_ShouldSendRespawn);
} }
bool MoveToWorld(cWorld * a_World, Vector3d a_NewPosition, bool a_ShouldSetPortalCooldown = false, bool a_ShouldSendRespawn = true); bool MoveToWorld(cWorld & a_World, Vector3d a_NewPosition, bool a_ShouldSetPortalCooldown = false, bool a_ShouldSendRespawn = true);
bool MoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d a_NewPosition) bool MoveToWorld(cWorld & a_World, bool a_ShouldSendRespawn, Vector3d a_NewPosition)
{ {
return MoveToWorld(a_World, a_NewPosition, false, a_ShouldSendRespawn); return MoveToWorld(a_World, a_NewPosition, false, a_ShouldSendRespawn);
} }
/** Moves entity to specified world, taking a world pointer */ /** Moves entity to specified world, taking a world pointer */
bool MoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn = true); bool MoveToWorld(cWorld & a_World, bool a_ShouldSendRespawn = true);
/** 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);

View File

@ -1222,7 +1222,7 @@ void cPlayer::Respawn(void)
if (GetWorld() != m_SpawnWorld) if (GetWorld() != m_SpawnWorld)
{ {
MoveToWorld(m_SpawnWorld, GetLastBedPos(), false, false); MoveToWorld(*m_SpawnWorld, GetLastBedPos(), false, false);
} }
else else
{ {

View File

@ -17,7 +17,7 @@ const double cNetherPortalScanner::AcrossOffset = 0.5;
cNetherPortalScanner::cNetherPortalScanner(cEntity & a_MovingEntity, cWorld * a_DestinationWorld, Vector3d a_DestPosition, int a_MaxY) : cNetherPortalScanner::cNetherPortalScanner(cEntity & a_MovingEntity, cWorld & a_DestinationWorld, Vector3d a_DestPosition, int a_MaxY) :
m_EntityID(a_MovingEntity.GetUniqueID()), m_EntityID(a_MovingEntity.GetUniqueID()),
m_SourceWorld(*a_MovingEntity.GetWorld()), m_SourceWorld(*a_MovingEntity.GetWorld()),
m_World(a_DestinationWorld), m_World(a_DestinationWorld),
@ -39,7 +39,7 @@ cNetherPortalScanner::cNetherPortalScanner(cEntity & a_MovingEntity, cWorld * a_
Add(x, z); Add(x, z);
} }
} }
Enable(*a_DestinationWorld->GetChunkMap()); Enable(*a_DestinationWorld.GetChunkMap());
} }
@ -49,7 +49,7 @@ cNetherPortalScanner::cNetherPortalScanner(cEntity & a_MovingEntity, cWorld * a_
void cNetherPortalScanner::OnChunkAvailable(int a_ChunkX, int a_ChunkZ) void cNetherPortalScanner::OnChunkAvailable(int a_ChunkX, int a_ChunkZ)
{ {
cChunkDef::BlockTypes blocks; cChunkDef::BlockTypes blocks;
m_World->GetChunkBlockTypes(a_ChunkX, a_ChunkZ, blocks); m_World.GetChunkBlockTypes(a_ChunkX, a_ChunkZ, blocks);
// Iterate through all of the blocks in the chunk // Iterate through all of the blocks in the chunk
for (unsigned int i = 0; i < cChunkDef::NumBlocks; i++) for (unsigned int i = 0; i < cChunkDef::NumBlocks; i++)
@ -92,7 +92,7 @@ bool cNetherPortalScanner::IsValidBuildLocation(Vector3i a_BlockPos)
{ {
for (int j = 0; j < PortalLength; j++) for (int j = 0; j < PortalLength; j++)
{ {
BLOCKTYPE blocktype = m_World->GetBlock(a_BlockPos.x + i, a_BlockPos.y, a_BlockPos.z + j); BLOCKTYPE blocktype = m_World.GetBlock(a_BlockPos.x + i, a_BlockPos.y, a_BlockPos.z + j);
if (!cBlockInfo::IsSolid(blocktype)) if (!cBlockInfo::IsSolid(blocktype))
{ {
return false; return false;
@ -101,7 +101,7 @@ bool cNetherPortalScanner::IsValidBuildLocation(Vector3i a_BlockPos)
// Check the airspace // Check the airspace
for (int k = 1; k < PortalHeight; k++) for (int k = 1; k < PortalHeight; k++)
{ {
blocktype = m_World->GetBlock(a_BlockPos.x + i, a_BlockPos.y + k, a_BlockPos.z + j); blocktype = m_World.GetBlock(a_BlockPos.x + i, a_BlockPos.y + k, a_BlockPos.z + j);
if (blocktype != E_BLOCK_AIR) if (blocktype != E_BLOCK_AIR)
{ {
return false; return false;
@ -121,15 +121,15 @@ bool cNetherPortalScanner::OnAllChunksAvailable(void)
if (m_FoundPortal) if (m_FoundPortal)
{ {
// Find the bottom of this portal // Find the bottom of this portal
while (m_World->GetBlock(m_PortalLoc.x, m_PortalLoc.y, m_PortalLoc.z) == E_BLOCK_NETHER_PORTAL) while (m_World.GetBlock(m_PortalLoc.x, m_PortalLoc.y, m_PortalLoc.z) == E_BLOCK_NETHER_PORTAL)
{ {
m_PortalLoc.y -= 1; m_PortalLoc.y -= 1;
} }
m_PortalLoc.y += 1; m_PortalLoc.y += 1;
// Figure out which way the portal is facing // Figure out which way the portal is facing
int BXP = m_World->GetBlock(m_PortalLoc.x + 1, m_PortalLoc.y, m_PortalLoc.z); int BXP = m_World.GetBlock(m_PortalLoc.x + 1, m_PortalLoc.y, m_PortalLoc.z);
int BXM = m_World->GetBlock(m_PortalLoc.x - 1, m_PortalLoc.y, m_PortalLoc.z); int BXM = m_World.GetBlock(m_PortalLoc.x - 1, m_PortalLoc.y, m_PortalLoc.z);
if ((BXP == E_BLOCK_NETHER_PORTAL) || (BXM == E_BLOCK_NETHER_PORTAL)) if ((BXP == E_BLOCK_NETHER_PORTAL) || (BXM == E_BLOCK_NETHER_PORTAL))
{ {
// The long axis is along X // The long axis is along X
@ -208,11 +208,11 @@ void cNetherPortalScanner::BuildNetherPortal(Vector3i a_Location, Direction a_Di
{ {
if (a_Direction == Direction::Y) if (a_Direction == Direction::Y)
{ {
m_World->SetBlock(x + i, y + k, z + j, E_BLOCK_AIR, 0); m_World.SetBlock(x + i, y + k, z + j, E_BLOCK_AIR, 0);
} }
else if (a_Direction == Direction::X) else if (a_Direction == Direction::X)
{ {
m_World->SetBlock(x + j, y + k, z + i, E_BLOCK_AIR, 0); m_World.SetBlock(x + j, y + k, z + i, E_BLOCK_AIR, 0);
} }
} }
} }
@ -226,11 +226,11 @@ void cNetherPortalScanner::BuildNetherPortal(Vector3i a_Location, Direction a_Di
// +2 on the short axis because that's where we deposit the entity // +2 on the short axis because that's where we deposit the entity
if (a_Direction == Direction::Y) if (a_Direction == Direction::Y)
{ {
m_World->SetBlock(x + 2, y, z + j, E_BLOCK_OBSIDIAN, 0); m_World.SetBlock(x + 2, y, z + j, E_BLOCK_OBSIDIAN, 0);
} }
else if (a_Direction == Direction::X) else if (a_Direction == Direction::X)
{ {
m_World->SetBlock(x + j, y, z + 2, E_BLOCK_OBSIDIAN, 0); m_World.SetBlock(x + j, y, z + 2, E_BLOCK_OBSIDIAN, 0);
} }
} }
} }
@ -240,31 +240,31 @@ void cNetherPortalScanner::BuildNetherPortal(Vector3i a_Location, Direction a_Di
{ {
if (a_Direction == Direction::Y) if (a_Direction == Direction::Y)
{ {
m_World->SetBlock(x + 1, y + i, z, E_BLOCK_OBSIDIAN, 0); m_World.SetBlock(x + 1, y + i, z, E_BLOCK_OBSIDIAN, 0);
m_World->SetBlock(x + 1, y + i, z + 3, E_BLOCK_OBSIDIAN, 0); m_World.SetBlock(x + 1, y + i, z + 3, E_BLOCK_OBSIDIAN, 0);
} }
else if (a_Direction == Direction::X) else if (a_Direction == Direction::X)
{ {
m_World->SetBlock(x, y + i, z + 1, E_BLOCK_OBSIDIAN, 0); m_World.SetBlock(x, y + i, z + 1, E_BLOCK_OBSIDIAN, 0);
m_World->SetBlock(x + 3, y + i, z + 1, E_BLOCK_OBSIDIAN, 0); m_World.SetBlock(x + 3, y + i, z + 1, E_BLOCK_OBSIDIAN, 0);
} }
} }
for (int i = 0; i < PortalLength; i++) for (int i = 0; i < PortalLength; i++)
{ {
if (a_Direction == Direction::Y) if (a_Direction == Direction::Y)
{ {
m_World->SetBlock(x + 1, y + 4, z + i, E_BLOCK_OBSIDIAN, 0); m_World.SetBlock(x + 1, y + 4, z + i, E_BLOCK_OBSIDIAN, 0);
m_World->SetBlock(x + 1, y, z + i, E_BLOCK_OBSIDIAN, 0); m_World.SetBlock(x + 1, y, z + i, E_BLOCK_OBSIDIAN, 0);
} }
else if (a_Direction == Direction::X) else if (a_Direction == Direction::X)
{ {
m_World->SetBlock(x + i, y + 4, z + 1, E_BLOCK_OBSIDIAN, 0); m_World.SetBlock(x + i, y + 4, z + 1, E_BLOCK_OBSIDIAN, 0);
m_World->SetBlock(x + i, y, z + 1, E_BLOCK_OBSIDIAN, 0); m_World.SetBlock(x + i, y, z + 1, E_BLOCK_OBSIDIAN, 0);
} }
} }
// Fill the frame (place a fire in the bottom) // Fill the frame (place a fire in the bottom)
m_World->SetBlock(x + 1, y + 1, z + 1, E_BLOCK_FIRE, 0); m_World.SetBlock(x + 1, y + 1, z + 1, E_BLOCK_FIRE, 0);
} }

View File

@ -15,7 +15,7 @@ class cWorld;
class cNetherPortalScanner : public cChunkStay class cNetherPortalScanner : public cChunkStay
{ {
public: public:
cNetherPortalScanner(cEntity & a_MovingEntity, cWorld * a_DestinationWorld, Vector3d a_DestPosition, int a_MaxY); cNetherPortalScanner(cEntity & a_MovingEntity, cWorld & a_DestinationWorld, Vector3d a_DestPosition, int a_MaxY);
virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkY) override; virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkY) override;
virtual bool OnAllChunksAvailable(void) override; virtual bool OnAllChunksAvailable(void) override;
virtual void OnDisabled(void) override; virtual void OnDisabled(void) override;
@ -55,7 +55,7 @@ private:
cWorld & m_SourceWorld; cWorld & m_SourceWorld;
/** The world we're moving the entity to. */ /** The world we're moving the entity to. */
cWorld * m_World; cWorld & m_World;
/** Whether we found a portal during the loading of the chunks. */ /** Whether we found a portal during the loading of the chunks. */
bool m_FoundPortal; bool m_FoundPortal;