diff options
author | Mattes D <github@xoft.cz> | 2016-12-11 21:22:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-11 21:22:09 +0100 |
commit | c59ff9b431cb46ce90f8f4b37ce16fab77841fdd (patch) | |
tree | fb810cb4529cabb39927da41d80491db009f7723 /src | |
parent | Powered rails can kick-start minecarts (#3472) (diff) | |
parent | Export GetPosition and GetSpeed from cEntity as a copy instead of a pointer to lua. (diff) | |
download | cuberite-c59ff9b431cb46ce90f8f4b37ce16fab77841fdd.tar cuberite-c59ff9b431cb46ce90f8f4b37ce16fab77841fdd.tar.gz cuberite-c59ff9b431cb46ce90f8f4b37ce16fab77841fdd.tar.bz2 cuberite-c59ff9b431cb46ce90f8f4b37ce16fab77841fdd.tar.lz cuberite-c59ff9b431cb46ce90f8f4b37ce16fab77841fdd.tar.xz cuberite-c59ff9b431cb46ce90f8f4b37ce16fab77841fdd.tar.zst cuberite-c59ff9b431cb46ce90f8f4b37ce16fab77841fdd.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 46 | ||||
-rw-r--r-- | src/Entities/Entity.h | 8 |
2 files changed, 52 insertions, 2 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 083a30f2a..1fe3c0f9f 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -3799,6 +3799,50 @@ static int tolua_cCompositeChat_UnderlineUrls(lua_State * tolua_S) +static int tolua_cEntity_GetPosition(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + + // Get the params: + cEntity * self = reinterpret_cast<cEntity *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (self == nullptr) + { + LOGWARNING("%s: invalid self (%p)", __FUNCTION__, static_cast<void *>(self)); + return 0; + } + + L.Push(Mtolua_new((Vector3d)(self->GetPosition()))); + + tolua_register_gc(L, lua_gettop(L)); // Make Lua own the object + return 1; +} + + + + + +static int tolua_cEntity_GetSpeed(lua_State * tolua_S) +{ + cLuaState L(tolua_S); + + // Get the params: + cEntity * self = reinterpret_cast<cEntity *>(tolua_tousertype(tolua_S, 1, nullptr)); + if (self == nullptr) + { + LOGWARNING("%s: invalid self (%p)", __FUNCTION__, static_cast<void *>(self)); + return 0; + } + + L.Push(Mtolua_new((Vector3d)(self->GetSpeed()))); + + tolua_register_gc(L, lua_gettop(L)); // Make Lua own the object + return 1; +} + + + + + void cManualBindings::Bind(lua_State * tolua_S) { tolua_beginmodule(tolua_S, nullptr); @@ -3878,6 +3922,8 @@ void cManualBindings::Bind(lua_State * tolua_S) tolua_beginmodule(tolua_S, "cEntity"); tolua_constant(tolua_S, "INVALID_ID", cEntity::INVALID_ID); + tolua_function(tolua_S, "GetPosition", tolua_cEntity_GetPosition); + tolua_function(tolua_S, "GetSpeed", tolua_cEntity_GetSpeed); tolua_endmodule(tolua_S); tolua_beginmodule(tolua_S, "cFile"); diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 4833f8b5c..c9d445de7 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -191,7 +191,6 @@ public: double GetHeadYaw (void) const { return m_HeadYaw; } // In degrees double GetHeight (void) const { return m_Height; } double GetMass (void) const { return m_Mass; } - const Vector3d & GetPosition (void) const { return m_Position; } double GetPosX (void) const { return m_Position.x; } double GetPosY (void) const { return m_Position.y; } double GetPosZ (void) const { return m_Position.z; } @@ -199,7 +198,6 @@ public: double GetPitch (void) const { return m_Rot.y; } // In degrees, [-180, +180), but normal client clips to [-90, +90] double GetRoll (void) const { return m_Rot.z; } // In degrees, unused in current client Vector3d GetLookVector(void) const; - const Vector3d & GetSpeed (void) const { return m_Speed; } double GetSpeedX (void) const { return m_Speed.x; } double GetSpeedY (void) const { return m_Speed.y; } double GetSpeedZ (void) const { return m_Speed.z; } @@ -292,6 +290,12 @@ public: // tolua_end + /** Exported in ManualBindings */ + const Vector3d & GetPosition(void) const { return m_Position; } + + /** Exported in ManualBindings */ + const Vector3d & GetSpeed(void) const { return m_Speed; } + /** Destroy the entity without scheduling memory freeing. This should only be used by cChunk or cClientHandle for internal memory management. */ void DestroyNoScheduling(bool a_ShouldBroadcast); |