From 31133a371eb28d2844500895c834b1f72bacb83a Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 13 Apr 2024 13:32:18 +0200 Subject: [PATCH] Fix set_node(air) calls In the fireflies case it can be replaced with remove_node. In the beds case we fix the logic to do what it should. Coincidentally the end result was correct nonetheless. --- mods/beds/api.lua | 17 +++++++++++------ mods/fireflies/init.lua | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/mods/beds/api.lua b/mods/beds/api.lua index ea3149a6..6873c1a9 100644 --- a/mods/beds/api.lua +++ b/mods/beds/api.lua @@ -1,3 +1,10 @@ +-- Removes a node without calling on on_destruct() +-- We use this to mess with bed nodes without causing unwanted recursion. +local function remove_no_destruct(pos) + minetest.swap_node(pos, {name = "air"}) + minetest.remove_node(pos) -- Now clear the meta + minetest.check_for_falling(pos) +end local function destruct_bed(pos, n) local node = minetest.get_node(pos) @@ -12,10 +19,7 @@ local function destruct_bed(pos, n) end local oname = minetest.get_node(other).name if minetest.get_item_group(oname, "bed") ~= 0 then - -- Swap node leaves meta, but doesn't call destruct_bed again - minetest.swap_node(other, {name = "air"}) - minetest.remove_node(other) -- Now clear the meta - minetest.check_for_falling(other) + remove_no_destruct(other) beds.remove_spawns_at(pos) beds.remove_spawns_at(other) end @@ -110,6 +114,7 @@ function beds.register_bed(name, def) on_rotate = function(pos, node, user, _, new_param2) local dir = minetest.facedir_to_dir(node.param2) + -- old position of the top node local p = vector.add(pos, dir) local node2 = minetest.get_node_or_nil(p) if not node2 or minetest.get_item_group(node2.name, "bed") ~= 2 or @@ -123,6 +128,7 @@ function beds.register_bed(name, def) if new_param2 % 32 > 3 then return false end + -- new position of the top node local newp = vector.add(pos, minetest.facedir_to_dir(new_param2)) local node3 = minetest.get_node_or_nil(newp) local node_def = node3 and minetest.registered_nodes[node3.name] @@ -134,8 +140,7 @@ function beds.register_bed(name, def) return false end node.param2 = new_param2 - -- do not remove_node here - it will trigger destroy_bed() - minetest.set_node(p, {name = "air"}) + remove_no_destruct(p) minetest.set_node(pos, node) minetest.set_node(newp, {name = name .. "_top", param2 = new_param2}) return true diff --git a/mods/fireflies/init.lua b/mods/fireflies/init.lua index 4aba655d..be8fac60 100644 --- a/mods/fireflies/init.lua +++ b/mods/fireflies/init.lua @@ -104,7 +104,7 @@ minetest.register_tool("fireflies:bug_net", { local node_name = minetest.get_node(pointed_thing.under).name local inv = player:get_inventory() if minetest.get_item_group(node_name, "catchable") == 1 then - minetest.set_node(pointed_thing.under, {name = "air"}) + minetest.remove_node(pointed_thing.under) local stack = ItemStack(node_name.." 1") local leftover = inv:add_item("main", stack) if leftover:get_count() > 0 then