1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Expose collision information to LuaEntity on_step

This commit is contained in:
sfan5 2020-04-14 14:11:33 +02:00
parent aef59f2ad9
commit 3475759d1a
7 changed files with 98 additions and 10 deletions

View file

@ -178,12 +178,11 @@ void ScriptApiEntity::luaentity_GetProperties(u16 id,
lua_pop(L, 1);
}
void ScriptApiEntity::luaentity_Step(u16 id, float dtime)
void ScriptApiEntity::luaentity_Step(u16 id, float dtime,
const collisionMoveResult *moveresult)
{
SCRIPTAPI_PRECHECKHEADER
//infostream<<"scriptapi_luaentity_step: id="<<id<<std::endl;
int error_handler = PUSH_ERROR_HANDLER(L);
// Get core.luaentities[id]
@ -199,9 +198,14 @@ void ScriptApiEntity::luaentity_Step(u16 id, float dtime)
luaL_checktype(L, -1, LUA_TFUNCTION);
lua_pushvalue(L, object); // self
lua_pushnumber(L, dtime); // dtime
/* moveresult */
if (moveresult)
push_collision_move_result(L, *moveresult);
else
lua_pushnil(L);
setOriginFromTable(object);
PCALL_RES(lua_pcall(L, 2, 0, error_handler));
PCALL_RES(lua_pcall(L, 3, 0, error_handler));
lua_pop(L, 2); // Pop object and error handler
}

View file

@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
struct ObjectProperties;
struct ToolCapabilities;
struct collisionMoveResult;
class ScriptApiEntity
: virtual public ScriptApiBase
@ -36,7 +37,8 @@ public:
std::string luaentity_GetStaticdata(u16 id);
void luaentity_GetProperties(u16 id,
ServerActiveObject *self, ObjectProperties *prop);
void luaentity_Step(u16 id, float dtime);
void luaentity_Step(u16 id, float dtime,
const collisionMoveResult *moveresult);
bool luaentity_Punch(u16 id,
ServerActiveObject *puncher, float time_from_last_punch,
const ToolCapabilities *toolcap, v3f dir, s16 damage);