1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-11-04 08:25:01 -05:00

Add time_from_last_punch to Lua API

This commit is contained in:
Perttu Ahola 2011-12-02 11:51:41 +02:00
parent ed128fff26
commit e8b0722137
4 changed files with 9 additions and 6 deletions

View File

@ -104,7 +104,9 @@
-- - getpos() -> {x=num, y=num, z=num} -- - getpos() -> {x=num, y=num, z=num}
-- - setpos(pos); pos={x=num, y=num, z=num} -- - setpos(pos); pos={x=num, y=num, z=num}
-- - moveto(pos, continuous=false): interpolated move -- - moveto(pos, continuous=false): interpolated move
-- - punch(puncher); puncher = an another ObjectRef -- - punch(puncher, time_from_last_punch)
-- ^ puncher = an another ObjectRef,
-- ^ time_from_last_punch = time since last punch action of the puncher
-- - right_click(clicker); clicker = an another ObjectRef -- - right_click(clicker); clicker = an another ObjectRef
-- - get_wield_digging_properties() -> digging property table -- - get_wield_digging_properties() -> digging property table
-- - add_to_inventory_later(itemstring): like above, but after callback returns (only allowed for craftitem callbacks) -- - add_to_inventory_later(itemstring): like above, but after callback returns (only allowed for craftitem callbacks)

View File

@ -1678,7 +1678,7 @@ void LuaEntitySAO::punch(ServerActiveObject *puncher, float time_from_last_punch
if(!m_registered) if(!m_registered)
return; return;
lua_State *L = m_env->getLua(); lua_State *L = m_env->getLua();
scriptapi_luaentity_punch(L, m_id, puncher); scriptapi_luaentity_punch(L, m_id, puncher, time_from_last_punch);
} }
void LuaEntitySAO::rightClick(ServerActiveObject *clicker) void LuaEntitySAO::rightClick(ServerActiveObject *clicker)

View File

@ -3208,9 +3208,9 @@ void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime)
script_error(L, "error running function 'on_step': %s\n", lua_tostring(L, -1)); script_error(L, "error running function 'on_step': %s\n", lua_tostring(L, -1));
} }
// Calls entity:on_punch(ObjectRef puncher) // Calls entity:on_punch(ObjectRef puncher, time_from_last_punch)
void scriptapi_luaentity_punch(lua_State *L, u16 id, void scriptapi_luaentity_punch(lua_State *L, u16 id,
ServerActiveObject *puncher) ServerActiveObject *puncher, float time_from_last_punch)
{ {
realitycheck(L); realitycheck(L);
assert(lua_checkstack(L, 20)); assert(lua_checkstack(L, 20));
@ -3228,8 +3228,9 @@ void scriptapi_luaentity_punch(lua_State *L, u16 id,
luaL_checktype(L, -1, LUA_TFUNCTION); luaL_checktype(L, -1, LUA_TFUNCTION);
lua_pushvalue(L, object); // self lua_pushvalue(L, object); // self
objectref_get_or_create(L, puncher); // Clicker reference objectref_get_or_create(L, puncher); // Clicker reference
lua_pushnumber(L, time_from_last_punch);
// Call with 2 arguments, 0 results // Call with 2 arguments, 0 results
if(lua_pcall(L, 2, 0, 0)) if(lua_pcall(L, 3, 0, 0))
script_error(L, "error running function 'on_punch': %s\n", lua_tostring(L, -1)); script_error(L, "error running function 'on_punch': %s\n", lua_tostring(L, -1));
} }

View File

@ -83,7 +83,7 @@ void scriptapi_luaentity_get_properties(lua_State *L, u16 id,
LuaEntityProperties *prop); LuaEntityProperties *prop);
void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime); void scriptapi_luaentity_step(lua_State *L, u16 id, float dtime);
void scriptapi_luaentity_punch(lua_State *L, u16 id, void scriptapi_luaentity_punch(lua_State *L, u16 id,
ServerActiveObject *puncher); ServerActiveObject *puncher, float time_from_last_punch);
void scriptapi_luaentity_rightclick(lua_State *L, u16 id, void scriptapi_luaentity_rightclick(lua_State *L, u16 id,
ServerActiveObject *clicker); ServerActiveObject *clicker);