summaryrefslogtreecommitdiffstats
path: root/src/Entities
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
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')
-rw-r--r--src/Entities/Entity.cpp32
-rw-r--r--src/Entities/Entity.h8
-rw-r--r--src/Entities/Player.cpp2
3 files changed, 22 insertions, 20 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
{