summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2020-04-10 22:08:19 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2020-04-18 20:51:30 +0200
commit50893667db7d158918a2fd2dd30f68591b4d46ac (patch)
treefa182e3e4f4171c8dc766eada816d072cadc62a4 /src/Entities/Entity.cpp
parentOnly store IDs across ticks (diff)
downloadcuberite-50893667db7d158918a2fd2dd30f68591b4d46ac.tar
cuberite-50893667db7d158918a2fd2dd30f68591b4d46ac.tar.gz
cuberite-50893667db7d158918a2fd2dd30f68591b4d46ac.tar.bz2
cuberite-50893667db7d158918a2fd2dd30f68591b4d46ac.tar.lz
cuberite-50893667db7d158918a2fd2dd30f68591b4d46ac.tar.xz
cuberite-50893667db7d158918a2fd2dd30f68591b4d46ac.tar.zst
cuberite-50893667db7d158918a2fd2dd30f68591b4d46ac.zip
Diffstat (limited to 'src/Entities/Entity.cpp')
-rw-r--r--src/Entities/Entity.cpp32
1 files changed, 17 insertions, 15 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);
}