From 3316dcba15c849fb152cbb6bad3ca0f6b0b4dac6 Mon Sep 17 00:00:00 2001 From: trans_soup <> Date: Thu, 19 Oct 2023 15:27:38 +0200 Subject: [PATCH] improve `blockgame.attempt_place` utility. it now takes an optional argument that specifies what nodes may be replaced (besides air). --- mods/bg_api/util_node.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mods/bg_api/util_node.lua b/mods/bg_api/util_node.lua index d77df15..e61cd9b 100644 --- a/mods/bg_api/util_node.lua +++ b/mods/bg_api/util_node.lua @@ -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