diff options
author | Dániel Juhász <juhdanad@gmail.com> | 2016-07-23 21:11:20 +0200 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2017-07-07 22:28:23 +0100 |
commit | 3caad3f3c9e319ca67d63231e8c64b2ace855fff (patch) | |
tree | f3cb283b7aa28958e2deec7c70dad3a85e1236d4 /src/script/lua_api/l_env.h | |
parent | a80ecbee1e838491343af760539a37fac4232048 (diff) | |
download | minetest-3caad3f3c9e319ca67d63231e8c64b2ace855fff.tar.gz minetest-3caad3f3c9e319ca67d63231e8c64b2ace855fff.tar.bz2 minetest-3caad3f3c9e319ca67d63231e8c64b2ace855fff.zip |
Expose getPointedThing to Lua
This commit introduces Raycast, a Lua user object, which can be
used to perform a raycast on the map. The ray is continuable, so one can
also get hidden nodes (for example to see trough glass).
Diffstat (limited to 'src/script/lua_api/l_env.h')
-rw-r--r-- | src/script/lua_api/l_env.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h index 7ce19b085..f380d8d6f 100644 --- a/src/script/lua_api/l_env.h +++ b/src/script/lua_api/l_env.h @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "lua_api/l_base.h" #include "serverenvironment.h" +#include "raycast.h" class ModApiEnvMod : public ModApiBase { private: @@ -159,6 +160,9 @@ private: // line_of_sight(pos1, pos2, stepsize) -> true/false static int l_line_of_sight(lua_State *L); + // raycast(pos1, pos2, objects, liquids) -> Raycast + static int l_raycast(lua_State *L); + // find_path(pos1, pos2, searchdistance, // max_jump, max_drop, algorithm) -> table containing path static int l_find_path(lua_State *L); @@ -245,6 +249,47 @@ public: virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n); }; +//! Lua wrapper for RaycastState objects +class LuaRaycast : public ModApiBase +{ +private: + static const char className[]; + static const luaL_Reg methods[]; + //! Inner state + RaycastState state; + + // Exported functions + + // garbage collector + static int gc_object(lua_State *L); + + /*! + * Raycast:next() -> pointed_thing + * Returns the next pointed thing on the ray. + */ + static int l_next(lua_State *L); +public: + //! Constructor with the same arguments as RaycastState. + LuaRaycast( + const core::line3d<f32> &shootline, + bool objects_pointable, + bool liquids_pointable) : + state(shootline, objects_pointable, liquids_pointable) + {} + + //! Creates a LuaRaycast and leaves it on top of the stack. + static int create_object(lua_State *L); + + /*! + * Returns the Raycast from the stack or throws an error. + * @param narg location of the RaycastState in the stack + */ + static LuaRaycast *checkobject(lua_State *L, int narg); + + //! Registers Raycast as a Lua userdata type. + static void Register(lua_State *L); +}; + struct ScriptCallbackState { ServerScripting *script; int callback_ref; |