]> git.lizzy.rs Git - minetest.git/commit
Fix minetest.find_nodes_in_area() coord clamping find_nodes_in_area
authorNils Dagsson Moskopp <nils@dieweltistgarnichtso.net>
Tue, 14 Dec 2021 13:06:31 +0000 (14:06 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Tue, 14 Dec 2021 15:17:49 +0000 (16:17 +0100)
commit33087897fdb2ac2bd07700356a8edfa33d5a9ec6
tree00cc6a9e845154aeca104abacbecd4cf0a823d93
parent76aa6103e39533d70f3b46e6df902dc6b4dd4104
Fix minetest.find_nodes_in_area() coord clamping

Previously, minetest.find_nodes_in_area() was affected by a signed
integer overflow, which was fixed by clamping the area in which the
function works to MAX_MAP_GENERATION_LIMIT & -MAX_MAP_GENERATION_LIMIT.

The problem with that approach is that nodes can exist and even be generated
past MAX_MAP_GENERATION_LIMIT in vanilla Minetest – which, despite the name,
does not specify exactly where the map generator stops working. Therefore,
the bug fix created an unknown amount of other bugs near the map border.

At minimum, those bugs affect the outer mapblocks, where nodes past
MAX_MAP_GENERATION_LIMIT can be generated. Ironically, the first thing
broken by the faulty bug fix was a test case belonging to a workaround that
prevents minetest.find_nodes_in_area() being called with coordinates out of
s16 bounds in the Mineclonia game, thus avoiding signed integer overflow.

Using INT16_MIN+1 & INT16_MAX-1 makes minetest.find_nodes_in_area()
work for all coordinates that worked before the faulty fix, avoiding a
situation where Minetest can place a node in the map, but then not find
it afterwards using minetest_find_nodes_in_area().
src/script/lua_api/l_env.cpp