content-pack specific variables PACK_ENV and PACK_ID

This commit is contained in:
MihailRis
2024-02-12 03:22:08 +03:00
parent 49fe2108d3
commit 617017d979
5 changed files with 19 additions and 3 deletions
+10 -2
View File
@@ -95,6 +95,16 @@ std::unique_ptr<Environment> scripting::create_environment(int parent) {
return std::make_unique<Environment>(state->createEnvironment(parent));
}
std::unique_ptr<Environment> scripting::create_pack_environment(const ContentPack& pack) {
int id = state->createEnvironment(0);
state->pushenv(id);
state->pushvalue(-1);
state->setfield("PACK_ENV");
state->pushstring(pack.id);
state->setfield("PACK_ID");
return std::make_unique<Environment>(id);
}
void scripting::on_world_load(Level* level, BlocksController* blocks) {
scripting::level = level;
scripting::content = level->content;
@@ -230,8 +240,6 @@ bool register_event(int env, const std::string& name, const std::string& id) {
// remove previous name
state->pushnil();
state->setfield(name, -3);
std::cout << id << std::endl;
// add new global name
state->setglobal(id);
state->pop();