update doc/*/scripting/events.md & add 'tps' argument

This commit is contained in:
MihailRis 2025-09-15 00:31:38 +03:00
parent b863d47d7f
commit a1177f2601
3 changed files with 18 additions and 2 deletions

View File

@ -46,6 +46,13 @@ function on_blocks_tick(tps: int)
Called tps (20) times per second. Use 1/tps instead of `time.delta()`. Called tps (20) times per second. Use 1/tps instead of `time.delta()`.
```lua
function on_block_tick(x, y, z, tps: number)
```
Called tps (20 / tick-interval) times per second for a block.
Use 1/tps instead of `time.delta()`.
```lua ```lua
function on_player_tick(playerid: int, tps: int) function on_player_tick(playerid: int, tps: int)
``` ```

View File

@ -46,6 +46,13 @@ function on_blocks_tick(tps: int)
Вызывается tps (20) раз в секунду. Используйте 1/tps вместо `time.delta()`. Вызывается tps (20) раз в секунду. Используйте 1/tps вместо `time.delta()`.
```lua
function on_block_tick(x, y, z, tps: number)
```
Вызывается tps (20 / tick-interval) раз в секунду для конкретного блока.
Используйте 1/tps вместо `time.delta()`.
```lua ```lua
function on_player_tick(playerid: int, tps: int) function on_player_tick(playerid: int, tps: int)
``` ```

View File

@ -174,12 +174,13 @@ block.__perform_ticks = function(delta)
end end
entry.timer = 0.0 entry.timer = 0.0
local event = entry.event local event = entry.event
local tps = entry.tps
for i=1, steps do for i=1, steps do
local x = entry[entry.pointer + 1] local x = entry[entry.pointer + 1]
local y = entry[entry.pointer + 2] local y = entry[entry.pointer + 2]
local z = entry[entry.pointer + 3] local z = entry[entry.pointer + 3]
entry.pointer = (entry.pointer + 3) % #entry entry.pointer = (entry.pointer + 3) % #entry
events.emit(event, x, y, z) events.emit(event, x, y, z, tps)
end end
::continue:: ::continue::
end end
@ -203,7 +204,8 @@ block.__process_register_events = function()
if not list then if not list then
list = {} list = {}
list.event = block.name(id) .. ".blocktick" list.event = block.name(id) .. ".blocktick"
list.delta = 1.0 / (20.0 / (block.properties[id]["tick-interval"] or 1)) list.tps = 20 / (block.properties[id]["tick-interval"] or 1)
list.delta = 1.0 / list.tps
list.timer = 0.0 list.timer = 0.0
list.pointer = 0 list.pointer = 0
updating_blocks[id] = list updating_blocks[id] = list