fix entity spawn/despawn

This commit is contained in:
Xertis 2026-04-08 22:59:47 +03:00
parent acf8112644
commit 2dd8024b7e

View file

@ -6,7 +6,8 @@
#include "objects/Entity.hpp" #include "objects/Entity.hpp"
#include "objects/Player.hpp" #include "objects/Player.hpp"
#include "util/stringutil.hpp" #include "util/stringutil.hpp"
#include "content/ContentControl.hpp" #include "content/Content.hpp"
#include "content/ContentPack.hpp"
using namespace scripting; using namespace scripting;
@ -131,15 +132,13 @@ void scripting::on_entity_spawn(
create_component(L, -1, *component, args, saved); create_component(L, -1, *component, args, saved);
} }
for (auto& pack : scripting::content_control->getAllContentPacks()) { for (auto& [packid, pack] : content->getPacks()) {
lua::emit_event( if (pack->worldfuncsset.onentityspawn) {
L, lua::emit_event(L, packid + ":.entityspawn", [&](lua::State* L) {
pack.id + ":.entityspawn",
[&](lua::State* L) {
lua::pushinteger(L, eid); lua::pushinteger(L, eid);
return 1; return 1;
} });
); }
} }
} }
@ -186,15 +185,13 @@ void scripting::on_entity_despawn(const Entity& entity) {
auto L = lua::get_main_state(); auto L = lua::get_main_state();
entityid_t uid = entity.getUID(); entityid_t uid = entity.getUID();
for (auto& pack : content_control->getAllContentPacks()) { for (auto& [packid, pack] : content->getPacks()) {
lua::emit_event( if (pack->worldfuncsset.onentitydespawn) {
L, lua::emit_event(L, packid + ":.entitydespawn", [&](lua::State* L) {
pack.id + ":.entitydespawn",
[&](lua::State* L) {
lua::pushinteger(L, uid); lua::pushinteger(L, uid);
return 1; return 1;
} });
); }
} }
lua::get_from(L, "stdcomp", "remove_Entity", true); lua::get_from(L, "stdcomp", "remove_Entity", true);