summaryrefslogtreecommitdiffstats
path: root/src/Entities/Boat.cpp
diff options
context:
space:
mode:
authorjclever77 <82078401+jclever77@users.noreply.github.com>2021-04-30 13:39:10 +0200
committerGitHub <noreply@github.com>2021-04-30 13:39:10 +0200
commitcbfc740ad0ade4b8f03648ea52c16368d3a026a8 (patch)
tree848f7650b55dc6bc7dbacec2555f174e2a35b52a /src/Entities/Boat.cpp
parentFix random_engine seed cast (#5212) (diff)
downloadcuberite-cbfc740ad0ade4b8f03648ea52c16368d3a026a8.tar
cuberite-cbfc740ad0ade4b8f03648ea52c16368d3a026a8.tar.gz
cuberite-cbfc740ad0ade4b8f03648ea52c16368d3a026a8.tar.bz2
cuberite-cbfc740ad0ade4b8f03648ea52c16368d3a026a8.tar.lz
cuberite-cbfc740ad0ade4b8f03648ea52c16368d3a026a8.tar.xz
cuberite-cbfc740ad0ade4b8f03648ea52c16368d3a026a8.tar.zst
cuberite-cbfc740ad0ade4b8f03648ea52c16368d3a026a8.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Boat.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp
index 1016773e9..cd66c523b 100644
--- a/src/Entities/Boat.cpp
+++ b/src/Entities/Boat.cpp
@@ -14,6 +14,36 @@
+class cBoatCollisionCallback
+{
+public:
+ cBoatCollisionCallback(cBoat * a_Boat, cEntity * a_Attachee) :
+ m_Boat(a_Boat), m_Attachee(a_Attachee)
+ {
+ }
+
+ bool operator()(cEntity & a_Entity)
+ {
+ // Checks if boat is empty and if given entity is a mob
+ if ((m_Attachee == nullptr) && (a_Entity.IsMob()))
+ {
+ // if so attach and return true
+ a_Entity.AttachTo(m_Boat);
+ return true;
+ }
+
+ return false;
+ }
+
+protected:
+ cBoat * m_Boat;
+ cEntity * m_Attachee;
+};
+
+
+
+
+
cBoat::cBoat(Vector3d a_Pos, eMaterial a_Material) :
Super(etBoat, a_Pos, 1.375f, 0.5625f),
m_LastDamage(0), m_ForwardDirection(0),
@@ -311,3 +341,20 @@ cItem cBoat::MaterialToItem(eMaterial a_Material)
+
+void cBoat::HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
+{
+ /** Special version of cEntity::HandlePhysics(...) function for boats, checks if mobs
+ colliding with the boat can be attached and does if that's the case, then returns to
+ normal physics calcualtions */
+
+ // Calculate boat's bounding box, run collision callback on all entities in said box
+ cBoatCollisionCallback BoatCollisionCallback(this, m_Attachee);
+ Vector3d BoatPosition = GetPosition();
+ cBoundingBox bbBoat(
+ Vector3d(BoatPosition.x, floor(BoatPosition.y), BoatPosition.z), GetWidth() / 2, GetHeight());
+ m_World->ForEachEntityInBox(bbBoat, BoatCollisionCallback);
+
+ // Return to calculating physics normally
+ Super::HandlePhysics(a_Dt, a_Chunk);
+}