aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorDániel Juhász <juhdanad@gmail.com>2018-08-16 20:10:08 +0200
committerSmallJoker <SmallJoker@users.noreply.github.com>2018-08-16 20:10:08 +0200
commit325bf680410e8012394e5f3ba5ba947c69034899 (patch)
tree66ed6c2b0c9d7a1c915006212ecde535699e16c4 /src/script
parent798724efeab2d71da4f041be99de86baa3d3cdd5 (diff)
downloadminetest-325bf680410e8012394e5f3ba5ba947c69034899.tar.gz
minetest-325bf680410e8012394e5f3ba5ba947c69034899.tar.bz2
minetest-325bf680410e8012394e5f3ba5ba947c69034899.zip
Raycast: export exact pointing location (#6304)
* Return intersection point in node coordinates. * Clarify 'intersection_point' documentation
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_content.cpp11
-rw-r--r--src/script/common/c_content.h8
-rw-r--r--src/script/cpp_api/s_item.cpp4
-rw-r--r--src/script/cpp_api/s_item.h6
-rw-r--r--src/script/lua_api/l_env.cpp2
5 files changed, 25 insertions, 6 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 889b94660..1d62ad98a 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -1757,7 +1757,8 @@ void read_json_value(lua_State *L, Json::Value &root, int index, u8 recursion)
lua_pop(L, 1); // Pop value
}
-void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm)
+void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm,
+ bool hitpoint)
{
lua_newtable(L);
if (pointed.type == POINTEDTHING_NODE) {
@@ -1782,6 +1783,14 @@ void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm)
lua_pushstring(L, "nothing");
lua_setfield(L, -2, "type");
}
+ if (hitpoint && (pointed.type != POINTEDTHING_NOTHING)) {
+ push_v3f(L, pointed.intersection_point / BS); // convert to node coords
+ lua_setfield(L, -2, "intersection_point");
+ push_v3s16(L, pointed.intersection_normal);
+ lua_setfield(L, -2, "intersection_normal");
+ lua_pushinteger(L, pointed.box_id + 1); // change to Lua array index
+ lua_setfield(L, -2, "box_id");
+ }
}
void push_objectRef(lua_State *L, const u16 id)
diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h
index 723253559..f3a653682 100644
--- a/src/script/common/c_content.h
+++ b/src/script/common/c_content.h
@@ -178,7 +178,13 @@ bool push_json_value (lua_State *L,
void read_json_value (lua_State *L, Json::Value &root,
int index, u8 recursion = 0);
-void push_pointed_thing (lua_State *L, const PointedThing &pointed, bool csm = false);
+/*!
+ * Pushes a Lua `pointed_thing` to the given Lua stack.
+ * \param csm If true, a client side pointed thing is pushed
+ * \param hitpoint If true, the exact pointing location is also pushed
+ */
+void push_pointed_thing(lua_State *L, const PointedThing &pointed, bool csm =
+ false, bool hitpoint = false);
void push_objectRef (lua_State *L, const u16 id);
diff --git a/src/script/cpp_api/s_item.cpp b/src/script/cpp_api/s_item.cpp
index 94abe267b..cbdfcf1b1 100644
--- a/src/script/cpp_api/s_item.cpp
+++ b/src/script/cpp_api/s_item.cpp
@@ -255,10 +255,10 @@ bool ScriptApiItem::getItemCallback(const char *name, const char *callbackname,
return false;
}
-void ScriptApiItem::pushPointedThing(const PointedThing& pointed)
+void ScriptApiItem::pushPointedThing(const PointedThing &pointed, bool hitpoint)
{
lua_State* L = getStack();
- push_pointed_thing(L, pointed);
+ push_pointed_thing(L, pointed, false, hitpoint);
}
diff --git a/src/script/cpp_api/s_item.h b/src/script/cpp_api/s_item.h
index d91b5c1d6..6c7f286a9 100644
--- a/src/script/cpp_api/s_item.h
+++ b/src/script/cpp_api/s_item.h
@@ -54,6 +54,10 @@ protected:
friend class LuaRaycast;
bool getItemCallback(const char *name, const char *callbackname, const v3s16 *p = nullptr);
- void pushPointedThing(const PointedThing& pointed);
+ /*!
+ * Pushes a `pointed_thing` tabe to the stack.
+ * \param hitpoint If true, the exact pointing location is also pushed
+ */
+ void pushPointedThing(const PointedThing &pointed, bool hitpoint = false);
};
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 4944968da..1e5149f7a 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -150,7 +150,7 @@ int LuaRaycast::l_next(lua_State *L)
if (pointed.type == POINTEDTHING_NOTHING)
lua_pushnil(L);
else
- script->pushPointedThing(pointed);
+ script->pushPointedThing(pointed, true);
return 1;
}