From d3255b3014fec4421732b5041c7a99548ef61923 Mon Sep 17 00:00:00 2001 From: 12xx12 <44411062+12xx12@users.noreply.github.com> Date: Fri, 9 Oct 2020 21:19:22 +0200 Subject: Beacon now checks for players in surrounding square (#4972) * Beacon now check for players in surrounding square not every player * added proper BoundingBox Co-authored-by: Alexander Harkness * one symbol to change everything one symbol to break the whole build Co-authored-by: 12xx12 <12xx12100@gmail.com> Co-authored-by: Alexander Harkness --- src/BlockEntities/BeaconEntity.cpp | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp index f9ceb6f34..a7bdbca2d 100644 --- a/src/BlockEntities/BeaconEntity.cpp +++ b/src/BlockEntities/BeaconEntity.cpp @@ -225,7 +225,7 @@ void cBeaconEntity::GiveEffects(void) return; } - int Radius = m_BeaconLevel * 10 + 10; + double Radius = static_cast(m_BeaconLevel) * 10 + 10; short EffectLevel = 0; if ((m_BeaconLevel >= 4) && (m_PrimaryEffect == m_SecondaryEffect)) { @@ -234,28 +234,22 @@ void cBeaconEntity::GiveEffects(void) bool HasSecondaryEffect = (m_BeaconLevel >= 4) && (m_PrimaryEffect != m_SecondaryEffect) && (m_SecondaryEffect > 0); - Vector3d BeaconPosition(m_Pos); - GetWorld()->ForEachPlayer([=](cPlayer & a_Player) + auto Area = cBoundingBox(m_Pos, Radius, Radius + static_cast(cChunkDef::Height), -Radius); + GetWorld()->ForEachEntityInBox(Area, [&](cEntity & a_Entity) + { + if (!a_Entity.IsPlayer()) { - auto PlayerPosition = a_Player.GetPosition(); - if (PlayerPosition.y > BeaconPosition.y) - { - PlayerPosition.y = BeaconPosition.y; - } - - // TODO: Vanilla minecraft uses an AABB check instead of a radius one - if ((PlayerPosition - BeaconPosition).Length() <= Radius) - { - a_Player.AddEntityEffect(m_PrimaryEffect, 180, EffectLevel); - - if (HasSecondaryEffect) - { - a_Player.AddEntityEffect(m_SecondaryEffect, 180, 0); - } - } return false; } - ); + auto & Player = static_cast(a_Entity); + Player.AddEntityEffect(m_PrimaryEffect, 180, EffectLevel); + + if (HasSecondaryEffect) + { + Player.AddEntityEffect(m_SecondaryEffect, 180, 0); + } + return false; + }); } @@ -325,4 +319,3 @@ bool cBeaconEntity::UsedBy(cPlayer * a_Player) - -- cgit v1.2.3