summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp32
-rw-r--r--src/Entities/Entity.h8
-rw-r--r--src/Entities/Player.cpp2
-rw-r--r--src/NetherPortalScanner.cpp42
-rw-r--r--src/NetherPortalScanner.h4
5 files changed, 45 insertions, 43 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index e0ea32e78..e7b1c469f 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1407,7 +1407,7 @@ bool cEntity::DetectPortal()
cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName());
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());
- new cNetherPortalScanner(*this, TargetWorld, TargetPos, cChunkDef::Height);
+ new cNetherPortalScanner(*this, *TargetWorld, TargetPos, cChunkDef::Height);
return true;
}
// Nether portal in the overworld
@@ -1439,7 +1439,7 @@ bool cEntity::DetectPortal()
cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedNetherWorldName());
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());
- new cNetherPortalScanner(*this, TargetWorld, TargetPos, (cChunkDef::Height / 2));
+ new cNetherPortalScanner(*this, *TargetWorld, TargetPos, (cChunkDef::Height / 2));
return true;
}
}
@@ -1487,7 +1487,7 @@ bool cEntity::DetectPortal()
cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName());
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());
- return MoveToWorld(TargetWorld, false);
+ return MoveToWorld(*TargetWorld, false);
}
// End portal in the overworld
else
@@ -1513,7 +1513,7 @@ bool cEntity::DetectPortal()
cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedEndWorldName());
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());
- return MoveToWorld(TargetWorld, false);
+ return MoveToWorld(*TargetWorld, false);
}
}
@@ -1577,26 +1577,28 @@ 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
- 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
return false;
}
- if (m_WorldChangeInfo.m_NewWorld != nullptr)
+ const auto OldWorld = m_WorldChangeInfo.m_NewWorld;
+
+ // Create new world change info
+ // (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;
}
- // Create new world change info
- m_WorldChangeInfo = { a_World, a_NewPosition, a_SetPortalCooldown, a_ShouldSendRespawn };
-
// TODO: move to capture when C++14
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 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);
}
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index 573bc34cf..2d9781edb 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -465,21 +465,21 @@ public:
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 */
- 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");
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);
}
/** 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 */
bool MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn = true);
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 40486d39e..55139f65e 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1222,7 +1222,7 @@ void cPlayer::Respawn(void)
if (GetWorld() != m_SpawnWorld)
{
- MoveToWorld(m_SpawnWorld, GetLastBedPos(), false, false);
+ MoveToWorld(*m_SpawnWorld, GetLastBedPos(), false, false);
}
else
{
diff --git a/src/NetherPortalScanner.cpp b/src/NetherPortalScanner.cpp
index 386da61fb..10ea64f02 100644
--- a/src/NetherPortalScanner.cpp
+++ b/src/NetherPortalScanner.cpp
@@ -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_SourceWorld(*a_MovingEntity.GetWorld()),
m_World(a_DestinationWorld),
@@ -39,7 +39,7 @@ cNetherPortalScanner::cNetherPortalScanner(cEntity & a_MovingEntity, cWorld * a_
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)
{
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
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++)
{
- 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))
{
return false;
@@ -101,7 +101,7 @@ bool cNetherPortalScanner::IsValidBuildLocation(Vector3i a_BlockPos)
// Check the airspace
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)
{
return false;
@@ -121,15 +121,15 @@ bool cNetherPortalScanner::OnAllChunksAvailable(void)
if (m_FoundPortal)
{
// 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;
// Figure out which way the portal is facing
- 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 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);
if ((BXP == E_BLOCK_NETHER_PORTAL) || (BXM == E_BLOCK_NETHER_PORTAL))
{
// The long axis is along X
@@ -208,11 +208,11 @@ void cNetherPortalScanner::BuildNetherPortal(Vector3i a_Location, Direction a_Di
{
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)
{
- 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
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)
{
- 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)
{
- 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, E_BLOCK_OBSIDIAN, 0);
+ m_World.SetBlock(x + 1, y + i, z + 3, E_BLOCK_OBSIDIAN, 0);
}
else if (a_Direction == Direction::X)
{
- 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, 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++)
{
if (a_Direction == Direction::Y)
{
- 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 + 4, z + i, E_BLOCK_OBSIDIAN, 0);
+ m_World.SetBlock(x + 1, y, z + i, E_BLOCK_OBSIDIAN, 0);
}
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, 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);
}
}
// 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);
}
diff --git a/src/NetherPortalScanner.h b/src/NetherPortalScanner.h
index 3d285053a..b6d66a088 100644
--- a/src/NetherPortalScanner.h
+++ b/src/NetherPortalScanner.h
@@ -15,7 +15,7 @@ class cWorld;
class cNetherPortalScanner : public cChunkStay
{
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 bool OnAllChunksAvailable(void) override;
virtual void OnDisabled(void) override;
@@ -55,7 +55,7 @@ private:
cWorld & m_SourceWorld;
/** 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. */
bool m_FoundPortal;