From 31b2242c388aa3867265145ebfc447b802f0b351 Mon Sep 17 00:00:00 2001 From: trans_soup <> Date: Tue, 17 Oct 2023 11:25:13 +0200 Subject: [PATCH] make leaves fall down when unsupported. also refactor leaves registration code. --- mods/bg_tree/node.lua | 65 ++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/mods/bg_tree/node.lua b/mods/bg_tree/node.lua index e823f23..e2ef2b4 100644 --- a/mods/bg_tree/node.lua +++ b/mods/bg_tree/node.lua @@ -35,32 +35,53 @@ reg_log("sapling", { drop = modname .. ":log", }) -local function reg_leaves (name, desc, drop, texture, groups) - groups = groups or {} - groups.planty = 1 - groups.air_flowable = 1 - texture = texture or name - drop = drop or name - - blockgame.register_node(modname .. ":" .. name, { - description = desc, - drawtype = "glasslike", - tiles = { - modname .. "_" .. texture .. ".png", - }, - paramtype = "light", - sunlight_propagates = true, - groups = groups, - drop = modname .. ":" .. drop, - }) +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) end -reg_leaves("leaves", "Leaves") -reg_leaves("leaves_growing", "Growing Leaves", "leaves", "leaves_alive") -reg_leaves("leaves_alive", "Leaves", "leaves") -reg_leaves("leaves_decomposing", "Decomposing Leaves") +local function reg_leaves (name, def) + def.description = def.description or name + def.texture = def.texture or name + def.tiles = {modname .. "_" .. def.texture .. ".png"} + + def.drawtype = "glasslike" + def.paramtype = "light" + def.sunlight_propagates = true + + def.groups = blockgame.underride(def.groups, { + planty = 1, + supports_leaves = 1, + air_flowable = 1, + can_fall = 1, + }) + + blockgame.register_node(modname .. ":" .. name, def) +end + +reg_leaves("leaves", { + description = "Leaves", +}) +reg_leaves("leaves_growing", { + description = "Growing Leaves", + drop = modname .. ":leaves", + texture = "leaves_alive", + fall_check = leaves_fall_check, +}) +reg_leaves("leaves_alive", { + description = "Leaves", + drop = modname .. ":leaves", + fall_check = leaves_fall_check, +}) +reg_leaves("leaves_decomposing", { + description = "Decomposing Leaves", + groups = { + supports_leaves = 0, + }, +}) blockgame.reg_simple_node("nut", "Nut", { woody = 1,