From 028a5735c5f98aa10718c94de07d2f4b4c1fa6b3 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 29 Sep 2021 23:17:03 +0100 Subject: Spectation: add dedicated pathway for spectator mode (#5303) * Spectation: add dedicated pathway for spectator mode + Sync player rotation with spectated entity. + Add dedicated infrastructure to cPlayer for handling spectation, instead of misusing entity riding. * Avoid infinite recursion when exiting spectation, fixes #5296 * AttachTo: Change parameter to reference --- src/Entities/Entity.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src/Entities/Entity.cpp') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index e9605fe5a..a5b1fae8f 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1994,26 +1994,25 @@ cEntity * cEntity::GetAttached() -void cEntity::AttachTo(cEntity * a_AttachTo) +void cEntity::AttachTo(cEntity & a_AttachTo) { - if (m_AttachedTo == a_AttachTo) + if (m_AttachedTo == &a_AttachTo) { - // Already attached to that entity, nothing to do here + // Already attached to that entity, nothing to do here: return; } + if (m_AttachedTo != nullptr) { // Detach from any previous entity: Detach(); } - // Update state information - m_AttachedTo = a_AttachTo; - a_AttachTo->m_Attachee = this; - if (a_AttachTo != nullptr) - { - m_World->BroadcastAttachEntity(*this, *a_AttachTo); - } + // Update state information: + m_AttachedTo = &a_AttachTo; + a_AttachTo.m_Attachee = this; + + m_World->BroadcastAttachEntity(*this, a_AttachTo); } @@ -2024,13 +2023,16 @@ void cEntity::Detach(void) { if (m_AttachedTo == nullptr) { - // Already not attached to any entity, our work is done + // Already not attached to any entity, our work is done: return; } + m_World->BroadcastDetachEntity(*this, *m_AttachedTo); m_AttachedTo->m_Attachee = nullptr; m_AttachedTo = nullptr; + + OnDetach(); } @@ -2306,6 +2308,14 @@ void cEntity::BroadcastLeashedMobs() +void cEntity::OnDetach() +{ +} + + + + + void cEntity::BroadcastDeathMessage(TakeDamageInfo & a_TDI) { cPluginManager * PluginManager = cRoot::Get()->GetPluginManager(); -- cgit v1.2.3