summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2012-09-09 12:05:38 +0300
committerPerttu Ahola <celeron55@gmail.com>2012-09-09 12:05:38 +0300
commitac628c9b0ab8c69313b3fe401384ecd0fc20eb14 (patch)
tree9497875d7c9bcb201b010548503c3b3b76b60392 /src
parent9696ed31a41b5e3ca85bad4a29c190a0d25c7752 (diff)
downloadminetest-ac628c9b0ab8c69313b3fe401384ecd0fc20eb14.tar.gz
minetest-ac628c9b0ab8c69313b3fe401384ecd0fc20eb14.tar.bz2
minetest-ac628c9b0ab8c69313b3fe401384ecd0fc20eb14.zip
Fix ObjectRef:punch()
Diffstat (limited to 'src')
-rw-r--r--src/scriptapi.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index 81e96aec6..39e2a46e4 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -2542,7 +2542,7 @@ private:
return 0;
}
- // punch(self, puncher, tool_capabilities, direction, time_from_last_punch)
+ // punch(self, puncher, time_from_last_punch, tool_capabilities, dir)
static int l_punch(lua_State *L)
{
ObjectRef *ref = checkobject(L, 1);
@@ -2551,13 +2551,18 @@ private:
ServerActiveObject *puncher = getobject(puncher_ref);
if(co == NULL) return 0;
if(puncher == NULL) return 0;
- ToolCapabilities toolcap = read_tool_capabilities(L, 3);
- v3f dir = read_v3f(L, 4);
+ v3f dir;
+ if(lua_type(L, 5) != LUA_TTABLE)
+ dir = co->getBasePosition() - puncher->getBasePosition();
+ else
+ dir = read_v3f(L, 5);
float time_from_last_punch = 1000000;
- if(lua_isnumber(L, 5))
- time_from_last_punch = lua_tonumber(L, 5);
+ if(lua_isnumber(L, 3))
+ time_from_last_punch = lua_tonumber(L, 3);
+ ToolCapabilities toolcap = read_tool_capabilities(L, 4);
+ dir.normalize();
// Do it
- puncher->punch(dir, &toolcap, puncher, time_from_last_punch);
+ co->punch(dir, &toolcap, puncher, time_from_last_punch);
return 0;
}