1
0

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 <me@bearbin.net>

* one symbol to change everything
one symbol to break the whole build

Co-authored-by: 12xx12 <12xx12100@gmail.com>
Co-authored-by: Alexander Harkness <me@bearbin.net>
This commit is contained in:
12xx12 2020-10-09 21:19:22 +02:00 committed by GitHub
parent 6ddc03db09
commit d3255b3014
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -225,7 +225,7 @@ void cBeaconEntity::GiveEffects(void)
return;
}
int Radius = m_BeaconLevel * 10 + 10;
double Radius = static_cast<double>(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<double>(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<cPlayer &>(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)