diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2016-08-20 14:34:29 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2016-08-20 14:34:29 +0200 |
commit | 7175b9e435a54cff33914d21384625a445cc5cf0 (patch) | |
tree | 7feb44f1e8e4ed7ea4d5bf0ba1d173abd3417f34 /src/Bindings | |
parent | Added cWorld:SetSpawn() API and Lua binding (#3316) (diff) | |
download | cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.gz cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.bz2 cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.lz cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.xz cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.zst cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/DeprecatedBindings.cpp | 125 | ||||
-rw-r--r-- | src/Bindings/ManualBindings_World.cpp | 3 |
2 files changed, 125 insertions, 3 deletions
diff --git a/src/Bindings/DeprecatedBindings.cpp b/src/Bindings/DeprecatedBindings.cpp index 0ffc58cbb..4f610eb78 100644 --- a/src/Bindings/DeprecatedBindings.cpp +++ b/src/Bindings/DeprecatedBindings.cpp @@ -291,6 +291,126 @@ tolua_lerror: +/* function: TeleportToCoords */ +static int tolua_cEntity_TeleportToCoords00(lua_State* tolua_S) +{ + cLuaState LuaState(tolua_S); + + if ( + !LuaState.CheckParamUserType(1, "cEntity") || + !LuaState.CheckParamNumber(2, 4) || + !LuaState.CheckParamEnd(5) + ) + return 0; + else + { + cEntity * self = nullptr; + double BlockX = 0; + double BlockY = 0; + double BlockZ = 0; + + LuaState.GetStackValues(1, self, BlockX, BlockY, BlockZ); + + #ifndef TOLUA_RELEASE + if (self == nullptr) + { + tolua_error(LuaState, "invalid 'self' in function 'TeleportToCoords'", nullptr); + } + #endif + { + self->TeleportToCoords({ BlockX, BlockY, BlockZ }); + } + } + LOGWARNING("Warning in function call 'TeleportToCoords': TeleportToCoords(X, Y, Z) is deprecated. Please use TeleportToCoords(Vector3d)"); + LuaState.LogStackTrace(0); + return 1; +} + + + + + +/* function: MoveToWorld */ +static int tolua_cEntity_MoveToWorld00(lua_State* tolua_S) +{ + cLuaState LuaState(tolua_S); + + if (!LuaState.CheckParamUserType(1, "cEntity")) + { + return 0; + } + + if (LuaState.CheckParamString(2) && (LuaState.CheckParamEnd(3) || LuaState.CheckParamEnd(4))) + { + cEntity * self = nullptr; + std::string WorldName; + LuaState.GetStackValues(1, self, WorldName); + + #ifndef TOLUA_RELEASE + if (self == nullptr) + { + tolua_error(LuaState, "invalid 'self' in function 'MoveToWorld'", nullptr); + } + #endif + { + self->MoveToWorld(WorldName, self->GetPosition()); + } + } + else if (LuaState.CheckParamUserType(2, "cWorld")) + { + if (LuaState.CheckParamUserType(4, "Vector3d") && LuaState.CheckParamEnd(5)) + { + cEntity * self = nullptr; + cWorld * World; + Vector3d * Position; + LuaState.GetStackValues(1, self, World); + LuaState.GetStackValues(4, Position); + + #ifndef TOLUA_RELEASE + if (self == nullptr) + { + tolua_error(LuaState, "invalid 'self' in function 'MoveToWorld'", nullptr); + } + #endif + { + self->MoveToWorld(*World, *Position); + } + } + else if (LuaState.CheckParamEnd(4)) + { + cEntity * self = nullptr; + std::string WorldName; + LuaState.GetStackValues(1, self, WorldName); + + #ifndef TOLUA_RELEASE + if (self == nullptr) + { + tolua_error(LuaState, "invalid 'self' in function 'MoveToWorld'", nullptr); + } + #endif + { + self->MoveToWorld(WorldName, self->GetPosition()); + } + } + else + { + return 0; + } + } + else + { + return 0; + } + + LOGWARNING("Warning in function call 'MoveToWorld': the ShouldSendRespawn parameter is deprecated and a destination position is mandatory."); + LuaState.LogStackTrace(0); + return 1; +} + + + + + /** function: cWorld:SetSignLines */ static int tolua_cWorld_SetSignLines(lua_State * tolua_S) { @@ -416,6 +536,11 @@ void DeprecatedBindings::Bind(lua_State * tolua_S) tolua_function(tolua_S,"abs", tolua_Vector3_Abs<double>); tolua_function(tolua_S,"clamp", tolua_Vector3_Clamp<double>); tolua_endmodule(tolua_S); + + tolua_beginmodule(tolua_S, "cEntity"); + tolua_function(tolua_S, "MoveToWorld", tolua_cEntity_MoveToWorld00); + tolua_function(tolua_S, "TeleportToCoords", tolua_cEntity_TeleportToCoords00); + tolua_endmodule(tolua_S); tolua_endmodule(tolua_S); } diff --git a/src/Bindings/ManualBindings_World.cpp b/src/Bindings/ManualBindings_World.cpp index 56a4ee65b..b101fdd7d 100644 --- a/src/Bindings/ManualBindings_World.cpp +++ b/src/Bindings/ManualBindings_World.cpp @@ -450,9 +450,6 @@ static int tolua_cWorld_PrepareChunk(lua_State * tolua_S) { m_LuaState.Call(m_Callback, a_CBChunkX, a_CBChunkZ, a_IsSuccess); } - - // This is the last reference of this object, we must delete it so that it doesn't leak: - delete this; } protected: |