summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2022-02-07 01:53:44 +0100
committerAlexander Harkness <me@bearbin.net>2022-02-08 22:47:19 +0100
commit4b60d55d8d97da113dbb2e90c2a4834e8e813629 (patch)
treefa8d2eefa28b54c364752253c031e250e95c4d4a /src/Entities/Entity.cpp
parentCustom 25565 port page (#5369) (diff)
downloadcuberite-4b60d55d8d97da113dbb2e90c2a4834e8e813629.tar
cuberite-4b60d55d8d97da113dbb2e90c2a4834e8e813629.tar.gz
cuberite-4b60d55d8d97da113dbb2e90c2a4834e8e813629.tar.bz2
cuberite-4b60d55d8d97da113dbb2e90c2a4834e8e813629.tar.lz
cuberite-4b60d55d8d97da113dbb2e90c2a4834e8e813629.tar.xz
cuberite-4b60d55d8d97da113dbb2e90c2a4834e8e813629.tar.zst
cuberite-4b60d55d8d97da113dbb2e90c2a4834e8e813629.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 0bb8b97bc..b6a67859b 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -134,6 +134,15 @@ bool cEntity::Initialize(OwnedEntity a_Self, cWorld & a_EntityWorld)
+void cEntity::OnAcquireSpectator(cPlayer & a_Player)
+{
+ m_Spectators.push_back(&a_Player);
+}
+
+
+
+
+
void cEntity::OnAddToWorld(cWorld & a_World)
{
// Spawn the entity on the clients:
@@ -146,6 +155,19 @@ void cEntity::OnAddToWorld(cWorld & a_World)
+void cEntity::OnLoseSpectator(cPlayer & a_Player)
+{
+ const auto Spectator = std::find(m_Spectators.begin(), m_Spectators.end(), &a_Player);
+
+ ASSERT(Spectator != m_Spectators.end());
+ std::swap(*Spectator, m_Spectators.back());
+ m_Spectators.pop_back();
+}
+
+
+
+
+
void cEntity::OnRemoveFromWorld(cWorld & a_World)
{
// Remove all mobs from the leashed list of mobs:
@@ -154,6 +176,13 @@ void cEntity::OnRemoveFromWorld(cWorld & a_World)
m_LeashedMobs.front()->Unleash(false, true);
}
+ for (const auto Player : m_Spectators)
+ {
+ Player->OnLoseSpectated();
+ }
+
+ m_Spectators.clear();
+
if (m_AttachedTo != nullptr)
{
Detach();