Add cEntity::GetBoundingBox, and use where appropriate. (#4711)
* Add cEntity::GetBoundingBox, and use where appropriate.
This commit is contained in:
parent
5b92e6654f
commit
994036a3b8
@ -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.",
|
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 =
|
GetChunkX =
|
||||||
{
|
{
|
||||||
Returns =
|
Returns =
|
||||||
|
@ -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)
|
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);
|
BoundingBox.Expand(1, 0.5, 1);
|
||||||
|
|
||||||
for (auto & Entity : m_Entities)
|
for (auto & Entity : m_Entities)
|
||||||
@ -1876,8 +1876,7 @@ bool cChunk::ForEachEntityInBox(const cBoundingBox & a_Box, cEntityCallback a_Ca
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
cBoundingBox EntBox(Entity->GetPosition(), Entity->GetWidth() / 2, Entity->GetHeight());
|
if (!Entity->GetBoundingBox().DoesIntersect(a_Box))
|
||||||
if (!EntBox.DoesIntersect(a_Box))
|
|
||||||
{
|
{
|
||||||
// The entity is not in the specified box
|
// The entity is not in the specified box
|
||||||
continue;
|
continue;
|
||||||
|
@ -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
|
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());
|
auto EntityBox = a_Entity.GetBoundingBox();
|
||||||
|
if (!bbTNT.IsInside(EntityBox)) // If entity box is inside tnt box, not vice versa!
|
||||||
if (!bbTNT.IsInside(bbEntity)) // If bbEntity is inside bbTNT, not vice versa!
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2353,7 +2353,7 @@ float cEntity::GetExplosionExposureRate(Vector3d a_ExplosionPosition, float a_Ex
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cBoundingBox EntityBox(GetPosition(), m_Width / 2, m_Height);
|
auto EntityBox = GetBoundingBox();
|
||||||
cBoundingBox ExplosionBox(a_ExplosionPosition, a_ExlosionPower * 2.0);
|
cBoundingBox ExplosionBox(a_ExplosionPosition, a_ExlosionPower * 2.0);
|
||||||
cBoundingBox IntersectionBox(EntityBox);
|
cBoundingBox IntersectionBox(EntityBox);
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../BoundingBox.h"
|
||||||
#include "../Item.h"
|
#include "../Item.h"
|
||||||
#include "../OSSupport/AtomicUniquePtr.h"
|
#include "../OSSupport/AtomicUniquePtr.h"
|
||||||
|
|
||||||
@ -239,6 +240,8 @@ public:
|
|||||||
int GetChunkX(void) const { return FloorC(m_Position.x / cChunkDef::Width); }
|
int GetChunkX(void) const { return FloorC(m_Position.x / cChunkDef::Width); }
|
||||||
int GetChunkZ(void) const { return FloorC(m_Position.z / 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 SetHeadYaw (double a_HeadYaw);
|
||||||
void SetMass (double a_Mass);
|
void SetMass (double a_Mass);
|
||||||
void SetPosX (double a_PosX) { SetPosition({a_PosX, m_Position.y, m_Position.z}); }
|
void SetPosX (double a_PosX) { SetPosition({a_PosX, m_Position.y, m_Position.z}); }
|
||||||
|
@ -31,7 +31,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cBoundingBox EntBox(a_Entity.GetPosition(), a_Entity.GetWidth() / 2, a_Entity.GetHeight());
|
auto EntBox = a_Entity.GetBoundingBox();
|
||||||
|
|
||||||
double LineCoeff;
|
double LineCoeff;
|
||||||
eBlockFace Face;
|
eBlockFace Face;
|
||||||
|
@ -84,7 +84,7 @@ void cPawn::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
|||||||
// Spectators cannot push entities around
|
// Spectators cannot push entities around
|
||||||
if ((!IsPlayer()) || (!static_cast<cPlayer *>(this)->IsGameModeSpectator()))
|
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())
|
if (a_Entity.GetUniqueID() == GetUniqueID())
|
||||||
{
|
{
|
||||||
|
@ -2780,7 +2780,7 @@ bool cPlayer::DoesPlacingBlocksIntersectEntity(const sSetBlockVector & a_Blocks)
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cBoundingBox EntBox(a_Entity.GetPosition(), a_Entity.GetWidth() / 2, a_Entity.GetHeight());
|
auto EntBox = a_Entity.GetBoundingBox();
|
||||||
for (auto BlockBox : PlacementBoxes)
|
for (auto BlockBox : PlacementBoxes)
|
||||||
{
|
{
|
||||||
// Put in a little bit of wiggle room
|
// Put in a little bit of wiggle room
|
||||||
|
@ -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.
|
// 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
|
// The results should be good enough for our purposes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user