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.
This commit is contained in:
trans_soup 2023-10-17 16:00:36 +02:00
parent 3459e94de8
commit f31940ffa5
2 changed files with 26 additions and 5 deletions

View file

@ -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,
})

View file

@ -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,