add on_chunk_present and on_chunk_remove events

This commit is contained in:
MihailRis
2025-01-12 05:41:42 +03:00
parent cfa6b5e578
commit 22c7cb8398
9 changed files with 65 additions and 9 deletions
+9
View File
@@ -14,6 +14,7 @@
#include "scripting/scripting.hpp"
#include "lighting/Lighting.hpp"
#include "settings.hpp"
#include "world/LevelEvents.hpp"
#include "world/Level.hpp"
#include "world/World.hpp"
@@ -26,6 +27,14 @@ LevelController::LevelController(
level(std::move(levelPtr)),
chunks(std::make_unique<ChunksController>(*level)),
playerTickClock(20, 3) {
level->events->listen(LevelEventType::CHUNK_PRESENT, [](auto, Chunk* chunk) {
scripting::on_chunk_present(*chunk, chunk->flags.loaded);
});
level->events->listen(LevelEventType::CHUNK_UNLOAD, [](auto, Chunk* chunk) {
scripting::on_chunk_remove(*chunk);
});
if (clientPlayer) {
chunks->lighting = std::make_unique<Lighting>(
level->content, *clientPlayer->chunks