world.lua: on_world_tick event
This commit is contained in:
parent
db62a47cc2
commit
ce687a67a3
@ -57,6 +57,7 @@ BlocksController::BlocksController(Level* level, uint padding)
|
||||
lighting(level->lighting.get()),
|
||||
randTickClock(20, 3),
|
||||
blocksTickClock(20, 1),
|
||||
worldTickClock(20, 1),
|
||||
padding(padding) {
|
||||
}
|
||||
|
||||
@ -99,6 +100,9 @@ void BlocksController::update(float delta) {
|
||||
if (blocksTickClock.update(delta)) {
|
||||
onBlocksTick(blocksTickClock.getPart(), blocksTickClock.getParts());
|
||||
}
|
||||
if (worldTickClock.update(delta)) {
|
||||
scripting::on_world_tick();
|
||||
}
|
||||
}
|
||||
|
||||
void BlocksController::onBlocksTick(int tickid, int parts) {
|
||||
|
||||
@ -35,6 +35,7 @@ class BlocksController {
|
||||
Lighting* lighting;
|
||||
Clock randTickClock;
|
||||
Clock blocksTickClock;
|
||||
Clock worldTickClock;
|
||||
uint padding;
|
||||
FastRandom random;
|
||||
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() {
|
||||
for (auto& pack : scripting::engine->getContentPacks()) {
|
||||
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, "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_quit", prefix+".worldquit");
|
||||
}
|
||||
|
||||
@ -53,6 +53,7 @@ namespace scripting {
|
||||
std::unique_ptr<Environment> create_doc_environment(int parent, const std::string& name);
|
||||
|
||||
void on_world_load(Level* level, BlocksController* blocks);
|
||||
void on_world_tick();
|
||||
void on_world_save();
|
||||
void on_world_quit();
|
||||
void on_blocks_tick(const Block* block, int tps);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user