summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Harkness <me@bearbin.net>2020-05-03 22:04:33 +0200
committerGitHub <noreply@github.com>2020-05-03 22:04:33 +0200
commit994036a3b8b09f8da1b6ec2055cc7a5ceb05a776 (patch)
tree54de33e0f563209cdabc40067b72328ec3126be8
parentUpdate src/Simulator/IncrementalRedstoneSimulator/RedstoneWireHandler.h (diff)
downloadcuberite-994036a3b8b09f8da1b6ec2055cc7a5ceb05a776.tar
cuberite-994036a3b8b09f8da1b6ec2055cc7a5ceb05a776.tar.gz
cuberite-994036a3b8b09f8da1b6ec2055cc7a5ceb05a776.tar.bz2
cuberite-994036a3b8b09f8da1b6ec2055cc7a5ceb05a776.tar.lz
cuberite-994036a3b8b09f8da1b6ec2055cc7a5ceb05a776.tar.xz
cuberite-994036a3b8b09f8da1b6ec2055cc7a5ceb05a776.tar.zst
cuberite-994036a3b8b09f8da1b6ec2055cc7a5ceb05a776.zip
Diffstat (limited to '')
-rw-r--r--Server/Plugins/APIDump/APIDesc.lua10
-rw-r--r--src/Chunk.cpp5
-rw-r--r--src/ChunkMap.cpp5
-rw-r--r--src/Entities/Entity.cpp2
-rw-r--r--src/Entities/Entity.h3
-rw-r--r--src/Entities/Floater.cpp2
-rw-r--r--src/Entities/Pawn.cpp2
-rw-r--r--src/Entities/Player.cpp2
-rw-r--r--src/Entities/ProjectileEntity.cpp2
9 files changed, 22 insertions, 11 deletions
diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua
index 2513acceb..5df216f49 100644
--- a/Server/Plugins/APIDump/APIDesc.lua
+++ b/Server/Plugins/APIDump/APIDesc.lua
@@ -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 =
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index 66c8cf4c3..7bb496a5c 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -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;
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index 1713173f8..0ff4d5ff7 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -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;
}
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 0f1266445..431d5f54b 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -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);
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index 2d9781edb..9cb0f970a 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -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}); }
diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp
index bd1e7a637..bb326f70b 100644
--- a/src/Entities/Floater.cpp
+++ b/src/Entities/Floater.cpp
@@ -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;
diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp
index 6a69cf6e5..b872cdfac 100644
--- a/src/Entities/Pawn.cpp
+++ b/src/Entities/Pawn.cpp
@@ -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())
{
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 55139f65e..46a1606d0 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -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
diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp
index c38fa0180..fa0654ca5 100644
--- a/src/Entities/ProjectileEntity.cpp
+++ b/src/Entities/ProjectileEntity.cpp
@@ -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