world.lua: on_world_tick event
This commit is contained in:
@@ -57,6 +57,7 @@ BlocksController::BlocksController(Level* level, uint padding)
|
|||||||
lighting(level->lighting.get()),
|
lighting(level->lighting.get()),
|
||||||
randTickClock(20, 3),
|
randTickClock(20, 3),
|
||||||
blocksTickClock(20, 1),
|
blocksTickClock(20, 1),
|
||||||
|
worldTickClock(20, 1),
|
||||||
padding(padding) {
|
padding(padding) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +100,9 @@ void BlocksController::update(float delta) {
|
|||||||
if (blocksTickClock.update(delta)) {
|
if (blocksTickClock.update(delta)) {
|
||||||
onBlocksTick(blocksTickClock.getPart(), blocksTickClock.getParts());
|
onBlocksTick(blocksTickClock.getPart(), blocksTickClock.getParts());
|
||||||
}
|
}
|
||||||
|
if (worldTickClock.update(delta)) {
|
||||||
|
scripting::on_world_tick();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlocksController::onBlocksTick(int tickid, int parts) {
|
void BlocksController::onBlocksTick(int tickid, int parts) {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class BlocksController {
|
|||||||
Lighting* lighting;
|
Lighting* lighting;
|
||||||
Clock randTickClock;
|
Clock randTickClock;
|
||||||
Clock blocksTickClock;
|
Clock blocksTickClock;
|
||||||
|
Clock worldTickClock;
|
||||||
uint padding;
|
uint padding;
|
||||||
FastRandom random;
|
FastRandom random;
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -109,6 +109,12 @@ void scripting::on_world_load(Level* level, BlocksController* blocks) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scripting::on_world_tick() {
|
||||||
|
for (auto& pack : scripting::engine->getContentPacks()) {
|
||||||
|
emit_event(pack.id + ".worldtick");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void scripting::on_world_save() {
|
void scripting::on_world_save() {
|
||||||
for (auto& pack : scripting::engine->getContentPacks()) {
|
for (auto& pack : scripting::engine->getContentPacks()) {
|
||||||
emit_event(pack.id + ".worldsave");
|
emit_event(pack.id + ".worldsave");
|
||||||
@@ -285,6 +291,7 @@ void scripting::load_world_script(int env, std::string prefix, fs::path file) {
|
|||||||
|
|
||||||
register_event(env, "init", prefix+".init");
|
register_event(env, "init", prefix+".init");
|
||||||
register_event(env, "on_world_open", prefix+".worldopen");
|
register_event(env, "on_world_open", prefix+".worldopen");
|
||||||
|
register_event(env, "on_world_tick", prefix+".worldtick");
|
||||||
register_event(env, "on_world_save", prefix+".worldsave");
|
register_event(env, "on_world_save", prefix+".worldsave");
|
||||||
register_event(env, "on_world_quit", prefix+".worldquit");
|
register_event(env, "on_world_quit", prefix+".worldquit");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ namespace scripting {
|
|||||||
std::unique_ptr<Environment> create_doc_environment(int parent, const std::string& name);
|
std::unique_ptr<Environment> create_doc_environment(int parent, const std::string& name);
|
||||||
|
|
||||||
void on_world_load(Level* level, BlocksController* blocks);
|
void on_world_load(Level* level, BlocksController* blocks);
|
||||||
|
void on_world_tick();
|
||||||
void on_world_save();
|
void on_world_save();
|
||||||
void on_world_quit();
|
void on_world_quit();
|
||||||
void on_blocks_tick(const Block* block, int tps);
|
void on_blocks_tick(const Block* block, int tps);
|
||||||
|
|||||||
Reference in New Issue
Block a user