improve blockgame.attempt_place utility.

it now takes an optional argument that specifies what nodes may be
replaced (besides air).
This commit is contained in:
trans_soup 2023-10-19 15:27:38 +02:00
parent 477afad09e
commit 3316dcba15

View file

@ -8,10 +8,18 @@ end
function blockgame.attempt_place (pos, node)
if minetest.get_node(pos).name ~= "air" then return false end
minetest.set_node(pos, node)
return true
function blockgame.attempt_place (pos, node, replacable)
local replacable = replacable or {}
local node_name = minetest.get_node(pos).name
local can_place = false
if node_name == "air" then can_place = true end
if blockgame.item_matches(node_name, replacable) then can_place = true end
if can_place then
minetest.set_node(pos, node)
end
return can_place
end