From a6d54685117b1870b1fcae43549a801163fba85e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Douglas=20da=20Silva=20Souza?= <44056294+JoseDouglas26@users.noreply.github.com> Date: Mon, 13 May 2024 04:56:51 -0300 Subject: [PATCH] Changes on placement checks --- mods/butterflies/init.lua | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/mods/butterflies/init.lua b/mods/butterflies/init.lua index 16b67910..2228bf85 100644 --- a/mods/butterflies/init.lua +++ b/mods/butterflies/init.lua @@ -45,15 +45,18 @@ for i in ipairs (butter_list) do floodable = true, on_place = function(itemstack, placer, pointed_thing) local player_name = placer and placer:get_player_name() or "" - local pos = pointed_thing.above + local apos = pointed_thing.above - if not minetest.is_protected(pos, player_name) and - not minetest.is_protected(pointed_thing.under, player_name) and - minetest.get_node(pos).name == "air" then - minetest.set_node(pos, {name = "butterflies:butterfly_"..name}) - minetest.get_node_timer(pos):start(1) - itemstack:take_item() + if minetest.is_protected(pos, player_name) or minetest.is_protected(pointed_thing.under, player_name) then + return end + + local _, sucess = minetest.item_place(itemstack, placer, pointed_thing) + + if sucess then + minetest.get_node_timer(pos):start(1) + end + return itemstack end, on_timer = function(pos, elapsed) @@ -78,15 +81,18 @@ for i in ipairs (butter_list) do floodable = true, on_place = function(itemstack, placer, pointed_thing) local player_name = placer and placer:get_player_name() or "" - local pos = pointed_thing.above + local apos = pointed_thing.above - if not minetest.is_protected(pos, player_name) and - not minetest.is_protected(pointed_thing.under, player_name) and - minetest.get_node(pos).name == "air" then - minetest.set_node(pos, {name = "butterflies:hidden_butterfly_"..name}) - minetest.get_node_timer(pos):start(1) - itemstack:take_item() + if minetest.is_protected(pos, player_name) or minetest.is_protected(pointed_thing.under, player_name) then + return end + + local _, sucess = minetest.item_place(itemstack, placer, pointed_thing) + + if sucess then + minetest.get_node_timer(pos):start(1) + end + return itemstack end, on_timer = function(pos, elapsed)