mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
add entity event: on_fall
This commit is contained in:
parent
3946119a67
commit
50c714692a
5 changed files with 39 additions and 10 deletions
|
|
@ -271,6 +271,7 @@ scriptenv scripting::on_entity_spawn(const EntityDef& def, entityid_t eid, entit
|
|||
|
||||
lua::pushenv(L, *entityenv);
|
||||
funcsset.on_grounded = lua::hasfield(L, "on_grounded");
|
||||
funcsset.on_fall = lua::hasfield(L, "on_fall");
|
||||
funcsset.on_despawn = lua::hasfield(L, "on_despawn");
|
||||
lua::pop(L, 2);
|
||||
return entityenv;
|
||||
|
|
@ -306,10 +307,20 @@ bool scripting::on_entity_despawn(const EntityDef& def, const Entity& entity) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool scripting::on_entity_grounded(const EntityDef& def, const Entity& entity) {
|
||||
bool scripting::on_entity_grounded(const Entity& entity, float force) {
|
||||
const auto& script = entity.getScripting();
|
||||
if (script.funcsset.on_grounded) {
|
||||
return process_entity_callback(script.env, "on_grounded", nullptr);
|
||||
return process_entity_callback(script.env, "on_grounded", [force](auto L){
|
||||
return lua::pushnumber(L, force);
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool scripting::on_entity_fall(const Entity& entity) {
|
||||
const auto& script = entity.getScripting();
|
||||
if (script.funcsset.on_fall) {
|
||||
return process_entity_callback(script.env, "on_fall", nullptr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue