1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Add callback on_mapblocks_changed

This commit is contained in:
Jude Melton-Houghton 2022-09-03 22:05:07 -04:00
parent 7701e70dc9
commit 5c248c2d7d
10 changed files with 141 additions and 6 deletions

View file

@ -147,3 +147,33 @@ local function test_mapgen_edges(cb)
minetest.emerge_area(max_edge, max_edge:add(1), emerge_block, max_finished)
end
unittests.register("test_mapgen_edges", test_mapgen_edges, {map=true, async=true})
local finish_test_on_mapblocks_changed
minetest.register_on_mapblocks_changed(function(modified_blocks, modified_block_count)
if finish_test_on_mapblocks_changed then
finish_test_on_mapblocks_changed(modified_blocks, modified_block_count)
finish_test_on_mapblocks_changed = nil
end
end)
local function test_on_mapblocks_changed(cb, player, pos)
local bp1 = (pos / minetest.MAP_BLOCKSIZE):floor()
local bp2 = bp1:add(1)
for _, bp in ipairs({bp1, bp2}) do
-- Make a modification in the block.
local p = bp * minetest.MAP_BLOCKSIZE
minetest.load_area(p)
local meta = minetest.get_meta(p)
meta:set_int("test_on_mapblocks_changed", meta:get_int("test_on_mapblocks_changed") + 1)
end
finish_test_on_mapblocks_changed = function(modified_blocks, modified_block_count)
if modified_block_count < 2 then
return cb("Expected at least two mapblocks to be recorded as modified")
end
if not modified_blocks[minetest.hash_node_position(bp1)] or
not modified_blocks[minetest.hash_node_position(bp2)] then
return cb("The expected mapblocks were not recorded as modified")
end
cb()
end
end
unittests.register("test_on_mapblocks_changed", test_on_mapblocks_changed, {map=true, async=true})