diff options
author | jclever77 <82078401+jclever77@users.noreply.github.com> | 2021-04-30 13:39:10 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-30 13:39:10 +0200 |
commit | cbfc740ad0ade4b8f03648ea52c16368d3a026a8 (patch) | |
tree | 848f7650b55dc6bc7dbacec2555f174e2a35b52a /src/Entities/Minecart.cpp | |
parent | Fix random_engine seed cast (#5212) (diff) | |
download | cuberite-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 'src/Entities/Minecart.cpp')
-rw-r--r-- | src/Entities/Minecart.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 1f454c857..123965916 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -21,6 +21,35 @@ +class cMinecartAttachCallback +{ +public: + cMinecartAttachCallback(cMinecart * a_Minecart, cEntity * a_Attachee) : + m_Minecart(a_Minecart), m_Attachee(a_Attachee) + { + } + + bool operator () (cEntity & a_Entity) + { + // Check if minecart is empty and if given entity is a mob + if ((m_Attachee == nullptr) && (a_Entity.IsMob())) + { + // if so, attach to minecart and return true + a_Entity.AttachTo(m_Minecart); + return true; + } + return false; + } + +protected: + cMinecart * m_Minecart; + cEntity * m_Attachee; +}; + + + + + class cMinecartCollisionCallback { public: @@ -1054,6 +1083,12 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) return false; } + // Collision was true, create bounding box for minecart, call attach callback for all entities within that box + cMinecartAttachCallback MinecartAttachCallback(this, m_Attachee); + Vector3d MinecartPosition = GetPosition(); + cBoundingBox bbMinecart(Vector3d(MinecartPosition.x, floor(MinecartPosition.y), MinecartPosition.z), GetWidth() / 2, GetHeight()); + m_World->ForEachEntityInBox(bbMinecart, MinecartAttachCallback); + switch (a_RailMeta) { case E_META_RAIL_ZM_ZP: |