From 83a41c93e9dede8c187cf841d5618c27e145d2a3 Mon Sep 17 00:00:00 2001 From: Mat Date: Thu, 5 Mar 2020 21:33:43 +0200 Subject: Attached entities can't enter portals (#4484) * Attached entities can't enter portals * Whitespace fixes --- src/Entities/Entity.cpp | 15 +++++++++++++++ src/Entities/Player.cpp | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 44808e2a5..983cc96be 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1349,6 +1349,12 @@ bool cEntity::DetectPortal() return false; } + if ((m_AttachedTo != nullptr) || (m_Attachee != nullptr)) + { + // Don't let attached entities change worlds, like players riding a minecart + return false; + } + if (IsPlayer() && !(static_cast(this))->IsGameModeCreative() && (m_PortalCooldownData.m_TicksDelayed != 80)) { // Delay teleportation for four seconds if the entity is a non-creative player @@ -1425,6 +1431,12 @@ bool cEntity::DetectPortal() return false; } + if ((m_AttachedTo != nullptr) || (m_Attachee != nullptr)) + { + // Don't let attached entities change worlds, like players riding a minecart + return false; + } + // End portal in the end if (GetWorld()->GetDimension() == dimEnd) { @@ -1523,6 +1535,9 @@ void cEntity::DoMoveToWorld(const sWorldChangeInfo & a_WorldChangeInfo) GetChunkX(), GetChunkZ() ); + // If entity is attached to another entity, detach, to prevent client side effects + Detach(); + // Stop ticking, in preperation for detaching from this world. SetIsTicking(false); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 421eddbd5..07342bd52 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -2029,6 +2029,9 @@ void cPlayer::DoMoveToWorld(const cEntity::sWorldChangeInfo & a_WorldChangeInfo) // Stop all mobs from targeting this player StopEveryoneFromTargetingMe(); + // If player is attached to entity, detach, to prevent client side effects + Detach(); + // Prevent further ticking in this world SetIsTicking(false); -- cgit v1.2.3