summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
authorPablo Beltrán <spekdrum@gmail.com>2017-08-21 10:46:41 +0200
committerMattes D <github@xoft.cz>2017-08-21 10:46:41 +0200
commitb18f6637b6c58db20353cd3e77584b646ab36b5c (patch)
tree77b1dcf42aec23ef4aa64a04c906282c5f61ba19 /src/Entities/Entity.cpp
parentChanged MoveToWorld to ScheduleMoveToWorld in cPlayer::Respawn (#3922) (diff)
downloadcuberite-b18f6637b6c58db20353cd3e77584b646ab36b5c.tar
cuberite-b18f6637b6c58db20353cd3e77584b646ab36b5c.tar.gz
cuberite-b18f6637b6c58db20353cd3e77584b646ab36b5c.tar.bz2
cuberite-b18f6637b6c58db20353cd3e77584b646ab36b5c.tar.lz
cuberite-b18f6637b6c58db20353cd3e77584b646ab36b5c.tar.xz
cuberite-b18f6637b6c58db20353cd3e77584b646ab36b5c.tar.zst
cuberite-b18f6637b6c58db20353cd3e77584b646ab36b5c.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index a38a6552d..56f7b33a3 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -159,6 +159,15 @@ bool cEntity::Initialize(OwnedEntity a_Self, cWorld & a_EntityWorld)
// Spawn the entity on the clients:
a_EntityWorld.BroadcastSpawnEntity(*this);
+ // If has any mob leashed broadcast every leashed entity to this
+ if (HasAnyMobLeashed())
+ {
+ for (auto LeashedMob : m_LeashedMobs)
+ {
+ m_World->BroadcastLeashEntity(*LeashedMob, *this);
+ }
+ }
+
return true;
}
@@ -218,6 +227,12 @@ void cEntity::Destroy(bool a_ShouldBroadcast)
ASSERT(GetParentChunk() != nullptr);
SetIsTicking(false);
+ // Unleash leashed mobs
+ while (!m_LeashedMobs.empty())
+ {
+ m_LeashedMobs.front()->Unleash(true, true);
+ }
+
if (a_ShouldBroadcast)
{
m_World->BroadcastDestroyEntity(*this);
@@ -2195,3 +2210,24 @@ void cEntity::SetPosition(const Vector3d & a_Position)
+
+void cEntity::AddLeashedMob(cMonster * a_Monster)
+{
+ // Not there already
+ ASSERT(std::find(m_LeashedMobs.begin(), m_LeashedMobs.end(), a_Monster) == m_LeashedMobs.end());
+
+ m_LeashedMobs.push_back(a_Monster);
+}
+
+
+
+
+void cEntity::RemoveLeashedMob(cMonster * a_Monster)
+{
+ ASSERT(a_Monster->GetLeashedTo() == this);
+
+ // Must exists
+ ASSERT(std::find(m_LeashedMobs.begin(), m_LeashedMobs.end(), a_Monster) != m_LeashedMobs.end());
+
+ m_LeashedMobs.remove(a_Monster);
+}