Merge pull request #1045 from MihailRis/update-on-world-tick

add 'tps' argument to on_world_tick event
This commit is contained in:
MihailRis 2026-10-15 22:04:46 +03:00 • committed by GitHub
commit 5f86068431
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 6 deletions

View file

@ -137,10 +137,10 @@ function on_world_save()
Called before world save. Called before world save.
```lua ```lua
function on_world_tick() function on_world_tick(tps)
``` ```
Called 20 times per second Called *tps* times per second
```lua ```lua
function on_world_quit() function on_world_quit()

View file

@ -124,7 +124,7 @@ function on_block_break_by(x: int, y: int, z: int, playerid: int)
Вызывается при нажатии ЛКМ на блок (в т.ч неразрушимый). Предотвращает разрушение блока, если возвращает `true` Вызывается при нажатии ЛКМ на блок (в т.ч неразрушимый). Предотвращает разрушение блока, если возвращает `true`
## События мира ## События мира
События мира для контент-пака прописываются в `scripts/world.lua` События мира для контент-пака прописываются в `scripts/world.lua`
@ -141,10 +141,10 @@ function on_world_save()
Вызывается перед сохранением мира Вызывается перед сохранением мира
```lua ```lua
function on_world_tick() function on_world_tick(tps)
``` ```
Вызывается 20 раз в секунду Вызывается *tps* раз в секунду
```lua ```lua
function on_world_quit() function on_world_quit()

View file

@ -345,7 +345,9 @@ void scripting::on_world_tick(int tps) {
lua::pop(L); lua::pop(L);
} }
for (auto& pack : content_control->getAllContentPacks()) { for (auto& pack : content_control->getAllContentPacks()) {
lua::emit_event(L, pack.id + ":.worldtick"); lua::emit_event(L, pack.id + ":.worldtick", [tps](lua::State* L) {
return lua::pushinteger(L, tps);
});
} }
} }