diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2022-02-07 01:53:44 +0100 |
---|---|---|
committer | Alexander Harkness <me@bearbin.net> | 2022-02-08 22:47:19 +0100 |
commit | 4b60d55d8d97da113dbb2e90c2a4834e8e813629 (patch) | |
tree | fa8d2eefa28b54c364752253c031e250e95c4d4a /src/Entities/Entity.cpp | |
parent | Custom 25565 port page (#5369) (diff) | |
download | cuberite-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.cpp | 29 |
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(); |