1
0
Fork 0

Add cEntity::GetBoundingBox, and use where appropriate. (#4711)

* Add cEntity::GetBoundingBox, and use where appropriate.
This commit is contained in:
Alexander Harkness 2020-05-03 20:04:33 +00:00 committed by GitHub
parent 5b92e6654f
commit 994036a3b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 22 additions and 11 deletions

View File

@ -3190,6 +3190,16 @@ local Hash = cCryptoHash.sha1HexString("DataToHash")
},
Notes = "Returns the number of hitpoints out of RawDamage that the currently equipped armor would cover. See {{TakeDamageInfo}} for more information on attack damage.",
},
GetBoundingBox =
{
Returns =
{
{
Type = "cBoundingBox",
},
},
Notes = "Returns the bounding box of the entity, which has width and height corresponding to the entity, and is aligned with the block grid.",
},
GetChunkX =
{
Returns =

View File

@ -1625,7 +1625,7 @@ void cChunk::SetAreaBiome(int a_MinRelX, int a_MaxRelX, int a_MinRelZ, int a_Max
void cChunk::CollectPickupsByPlayer(cPlayer & a_Player)
{
auto BoundingBox = cBoundingBox(a_Player.GetPosition(), a_Player.GetWidth(), a_Player.GetHeight());
auto BoundingBox = a_Player.GetBoundingBox();
BoundingBox.Expand(1, 0.5, 1);
for (auto & Entity : m_Entities)
@ -1876,8 +1876,7 @@ bool cChunk::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback a_Ca
{
continue;
}
cBoundingBox EntBox(Entity->GetPosition(), Entity->GetWidth() / 2, Entity->GetHeight());
if (!EntBox.DoesIntersect(a_Box))
if (!Entity->GetBoundingBox().DoesIntersect(a_Box))
{
// The entity is not in the specified box
continue;

View File

@ -1298,9 +1298,8 @@ void cChunkMap::DoExplosionAt(double a_ExplosionSize, double a_BlockX, double a_
if (!a_Entity.IsTNT() && !a_Entity.IsFallingBlock()) // Don't apply damage to other TNT entities and falling blocks, they should be invincible
{
cBoundingBox bbEntity(a_Entity.GetPosition(), a_Entity.GetWidth() / 2, a_Entity.GetHeight());
if (!bbTNT.IsInside(bbEntity)) // If bbEntity is inside bbTNT, not vice versa!
auto EntityBox = a_Entity.GetBoundingBox();
if (!bbTNT.IsInside(EntityBox)) // If entity box is inside tnt box, not vice versa!
{
return false;
}

View File

@ -2353,7 +2353,7 @@ float cEntity::GetExplosionExposureRate(Vector3d a_ExplosionPosition, float a_Ex
return 0;
}
cBoundingBox EntityBox(GetPosition(), m_Width / 2, m_Height);
auto EntityBox = GetBoundingBox();
cBoundingBox ExplosionBox(a_ExplosionPosition, a_ExlosionPower * 2.0);
cBoundingBox IntersectionBox(EntityBox);

View File

@ -1,6 +1,7 @@
#pragma once
#include "../BoundingBox.h"
#include "../Item.h"
#include "../OSSupport/AtomicUniquePtr.h"
@ -239,6 +240,8 @@ public:
int GetChunkX(void) const { return FloorC(m_Position.x / cChunkDef::Width); }
int GetChunkZ(void) const { return FloorC(m_Position.z / cChunkDef::Width); }
cBoundingBox GetBoundingBox() const { return cBoundingBox(GetPosition(), GetWidth() / 2, GetHeight()); }
void SetHeadYaw (double a_HeadYaw);
void SetMass (double a_Mass);
void SetPosX (double a_PosX) { SetPosition({a_PosX, m_Position.y, m_Position.z}); }

View File

@ -31,7 +31,7 @@ public:
return false;
}
cBoundingBox EntBox(a_Entity.GetPosition(), a_Entity.GetWidth() / 2, a_Entity.GetHeight());
auto EntBox = a_Entity.GetBoundingBox();
double LineCoeff;
eBlockFace Face;

View File

@ -84,7 +84,7 @@ void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// Spectators cannot push entities around
if ((!IsPlayer()) || (!static_cast<cPlayer *>(this)->IsGameModeSpectator()))
{
m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), GetWidth(), GetHeight()), [=](cEntity & a_Entity)
m_World->ForEachEntityInBox(GetBoundingBox(), [=](cEntity & a_Entity)
{
if (a_Entity.GetUniqueID() == GetUniqueID())
{

View File

@ -2780,7 +2780,7 @@ bool cPlayer::DoesPlacingBlocksIntersectEntity(const sSetBlockVector & a_Blocks)
{
return false;
}
cBoundingBox EntBox(a_Entity.GetPosition(), a_Entity.GetWidth() / 2, a_Entity.GetHeight());
auto EntBox = a_Entity.GetBoundingBox();
for (auto BlockBox : PlacementBoxes)
{
// Put in a little bit of wiggle room

View File

@ -147,7 +147,7 @@ public:
}
}
cBoundingBox EntBox(a_Entity.GetPosition(), a_Entity.GetWidth() / 2, a_Entity.GetHeight());
auto EntBox = a_Entity.GetBoundingBox();
// Instead of colliding the bounding box with another bounding box in motion, we collide an enlarged bounding box with a hairline.
// The results should be good enough for our purposes