From b2eddbed84d55978337d1b52f6a9a2eabb658017 Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 8 Apr 2021 06:17:24 -0400 Subject: Teleport off of mount when throwing enderpearl (#5179) * Teleport off of mount when throwing enderpearl * Simplify returning boolean * Oops forgot a semicolon * Fix code conventions in Player.h --- src/Entities/ThrownEnderPearlEntity.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src/Entities/ThrownEnderPearlEntity.cpp') diff --git a/src/Entities/ThrownEnderPearlEntity.cpp b/src/Entities/ThrownEnderPearlEntity.cpp index 4f1029b27..ec4af7a7c 100644 --- a/src/Entities/ThrownEnderPearlEntity.cpp +++ b/src/Entities/ThrownEnderPearlEntity.cpp @@ -34,12 +34,29 @@ void cThrownEnderPearlEntity::OnHitSolidBlock(Vector3d a_HitPos, eBlockFace a_Hi void cThrownEnderPearlEntity::OnHitEntity(cEntity & a_EntityHit, Vector3d a_HitPos) { int TotalDamage = 0; + + bool isAttachedEntity = GetWorld()->FindAndDoWithPlayer(m_CreatorData.m_Name, [& a_EntityHit](cPlayer & a_Entity) + { + const cEntity * attachedEntity = a_Entity.GetAttached(); + if (attachedEntity == nullptr) + { + // nothing attached + return false; + } + + return attachedEntity->GetUniqueID() == a_EntityHit.GetUniqueID(); + } + ); // TODO: If entity is Ender Crystal, destroy it - TeleportCreator(a_HitPos); - a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); - m_DestroyTimer = 5; + if (!isAttachedEntity) + { + TeleportCreator(a_HitPos); + a_EntityHit.TakeDamage(dtRangedAttack, this, TotalDamage, 1); + m_DestroyTimer = 5; + } + } @@ -79,6 +96,7 @@ void cThrownEnderPearlEntity::TeleportCreator(Vector3d a_HitPos) // Teleport the creator here, make them take 5 damage: a_Entity.TeleportToCoords(a_HitPos.x, a_HitPos.y + 0.2, a_HitPos.z); a_Entity.TakeDamage(dtEnderPearl, this, 5, 0); + a_Entity.Detach(true); return true; } ); -- cgit v1.2.3