mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
Add on_entity_spawned and on_entity_despawned events
This commit is contained in:
parent
936a5c8525
commit
518d5d5ae4
8 changed files with 75 additions and 1 deletions
|
|
@ -555,6 +555,34 @@ void scripting::on_player_tick(Player* player, int tps) {
|
|||
}
|
||||
}
|
||||
|
||||
void scripting::on_entity_spawned(entityid_t eid) {
|
||||
auto L = lua::get_main_state();
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(
|
||||
L,
|
||||
pack.id + ":.entityspawned",
|
||||
[&](lua::State* L) {
|
||||
lua::pushinteger(L, eid);
|
||||
return 1;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void scripting::on_entity_despawned(entityid_t eid) {
|
||||
auto L = lua::get_main_state();
|
||||
for (auto& pack : content_control->getAllContentPacks()) {
|
||||
lua::emit_event(
|
||||
L,
|
||||
pack.id + ":.entitydespawned",
|
||||
[&](lua::State* L) {
|
||||
lua::pushinteger(L, eid);
|
||||
return 1;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool scripting::on_item_use(Player* player, const ItemDef& item) {
|
||||
std::string name = item.name + ".use";
|
||||
return lua::emit_event(
|
||||
|
|
@ -781,6 +809,10 @@ void scripting::load_world_script(
|
|||
register_event(env, "on_inventory_open", prefix + ":.inventoryopen");
|
||||
funcsset.oninventoryclosed =
|
||||
register_event(env, "on_inventory_closed", prefix + ":.inventoryclosed");
|
||||
funcsset.onentityspawned =
|
||||
register_event(env, "on_entity_spawned", prefix + ":.entityspawned");
|
||||
funcsset.onentitydespawned =
|
||||
register_event(env, "on_entity_despawned", prefix + ":.entitydespawned");
|
||||
}
|
||||
|
||||
void scripting::load_content_script(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue