From f31940ffa54c6ddac04aa57885894a3444f125b0 Mon Sep 17 00:00:00 2001 From: trans_soup <> Date: Tue, 17 Oct 2023 16:00:36 +0200 Subject: [PATCH] make unsupported leaves die & fall. leaves that aren't in contact with living logs, or are not in contact with any supported leaves, or are too far away from living logs, will now die and fall down. --- mods/bg_tree/node_leaves.lua | 25 +++++++++++++++++++++---- mods/bg_tree/node_log.lua | 6 +++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/mods/bg_tree/node_leaves.lua b/mods/bg_tree/node_leaves.lua index b50a917..720df34 100644 --- a/mods/bg_tree/node_leaves.lua +++ b/mods/bg_tree/node_leaves.lua @@ -1,9 +1,26 @@ local modname = minetest.get_current_modname() local function leaves_fall_check (pos, node) - return blockgame.every(blockgame.vector.get_neighbors(pos), function (pos) - return minetest.get_item_group(minetest.get_node(pos).name, "supports_leaves") == 0 - end) + local is_supported = false + + blockgame.flood_fill(pos, function (pos, distance) + local nodename = minetest.get_node(pos).name + + if blockgame.item_matches(nodename, {"group:supports_leaves"}) then + is_supported = true + return false + end + + if blockgame.item_matches(nodename, {"group:extends_leaves_support"}) then + return true + end + end, 3) + + if not is_supported then + minetest.set_node(pos, {name = modname .. ":leaves"}) + end + + return not is_supported end local function reg_leaves (name, def) @@ -17,7 +34,7 @@ local function reg_leaves (name, def) def.groups = blockgame.underride(def.groups, { planty = 1, - supports_leaves = 1, + extends_leaves_support = 1, air_flowable = 1, can_fall = 1, }) diff --git a/mods/bg_tree/node_log.lua b/mods/bg_tree/node_log.lua index 1c36629..a34818e 100644 --- a/mods/bg_tree/node_log.lua +++ b/mods/bg_tree/node_log.lua @@ -20,7 +20,11 @@ local function reg_log (name, def) blockgame.register_node(modname .. ":" .. name, def) end -reg_log("log") +reg_log("log", { + groups = { + supports_leaves = 0, + }, +}) reg_log("log_alive", { groups = { planty = 1,