From f01e4bb55f0e774a867d45451e6c837a1d40c244 Mon Sep 17 00:00:00 2001 From: Vanessa Dannenberg Date: Sun, 20 Jun 2021 23:18:32 -0400 Subject: [PATCH 1/6] Convert moss to wallmounted mode I couldn't use leaf decay to make moss disappear when a trunk is dug, because it breaks leaf decay on that tree's leaves: the leafdecay function is not a true "register"- type function that can be run more than once on a given trunk node, it's an all-or-nothing override and only the last call for any given trunk actually sticks. Since moss is... was facedir, attached_node didn't work right either, as it doesn't have a mode to look for a vertical surface behind the attached object (like how it works with wallmounted items), so this converts moss to true wallmounted and uses attached_node like I originally wanted. To avoid losing the effect where moss can be rotated randomly when generated, I registered 4 nodes for each moss type, with increasingly-rotated textures. --- trunks/generating.lua | 50 ++++++++++-------- trunks/nodes.lua | 117 +++++++++++++++++++++++++++--------------- 2 files changed, 105 insertions(+), 62 deletions(-) diff --git a/trunks/generating.lua b/trunks/generating.lua index 699baf9..af19254 100644 --- a/trunks/generating.lua +++ b/trunks/generating.lua @@ -356,11 +356,12 @@ if Moss_on_ground == true then abstract_trunks.grow_moss_on_ground = function(pos) local on_ground = {x=pos.x, y=pos.y+1, z=pos.z} local moss_type = math.random(1,21) + local rot = math.random(0,3) if moss_type == 1 then - minetest.swap_node(on_ground, {name="trunks:moss_fungus", param2=math.random(0,3)}) + minetest.swap_node(on_ground, {name="trunks:moss_with_fungus_"..rot, param2=1}) else - minetest.swap_node(on_ground, {name="trunks:moss", param2=math.random(0,3)}) + minetest.swap_node(on_ground, {name="trunks:moss_plain_"..rot, param2=1}) end end @@ -406,44 +407,49 @@ abstract_trunks.grow_moss_on_trunk = function(pos) local node_under = minetest.get_node(undrneath) --if minetest.get_item_group(node_under.name, "tree") < 1 then - local moss_type = math.random(1,41) - if minetest.registered_nodes[node_here.name].buildable_to then -- instead of check_air = true, + if minetest.registered_nodes[node_here.name].buildable_to then + local moss_type = math.random(1,41) + local rot = math.random(0,3) if moss_type == 1 then - minetest.swap_node(on_ground, {name="trunks:moss_fungus", param2=math.random(0,3) --[[1]]}) + minetest.swap_node(on_ground, {name="trunks:moss_with_fungus_"..rot, param2=1}) elseif moss_type < 22 then - minetest.swap_node(on_ground, {name="trunks:moss", param2=math.random(0,3) --[[1]]}) + minetest.swap_node(on_ground, {name="trunks:moss_plain_"..rot, param2=1}) end end - local moss_type = math.random(1,31) -- cliche of more moss at north - if minetest.registered_nodes[node_north.name].buildable_to then -- instead of check_air = true, + if minetest.registered_nodes[node_north.name].buildable_to then + local moss_type = math.random(1,31) -- cliche of more moss at north + local rot = math.random(0,3) if moss_type == 1 then - minetest.swap_node(at_side_n, {name="trunks:moss_fungus", param2=math.random(4,7)}) -- 5,4,6,7 + minetest.swap_node(at_side_n, {name="trunks:moss_with_fungus_"..rot, param2=5}) elseif moss_type < 22 then - minetest.swap_node(at_side_n, {name="trunks:moss", param2=math.random(4,7)}) + minetest.swap_node(at_side_n, {name="trunks:moss_plain_"..rot, param2=5}) end end - local moss_type = math.random(1,41) - if minetest.registered_nodes[node_east.name].buildable_to then -- instead of check_air = true, + if minetest.registered_nodes[node_east.name].buildable_to then + local moss_type = math.random(1,41) + local rot = math.random(0,3) if moss_type == 1 then - minetest.swap_node(at_side_e, {name="trunks:moss_fungus", param2=math.random(12,15)}) + minetest.swap_node(at_side_e, {name="trunks:moss_with_fungus_"..rot, param2=3}) elseif moss_type < 22 then - minetest.swap_node(at_side_e, {name="trunks:moss", param2=math.random(12,15)}) + minetest.swap_node(at_side_e, {name="trunks:moss_plain_"..rot, param2=3}) end end - local moss_type = math.random(1,41) - if minetest.registered_nodes[node_south.name].buildable_to then -- instead of check_air = true, + if minetest.registered_nodes[node_south.name].buildable_to then + local moss_type = math.random(1,41) + local rot = math.random(0,3) if moss_type == 1 then - minetest.swap_node(at_side_s, {name="trunks:moss_fungus", param2=math.random(8,11)}) + minetest.swap_node(at_side_s, {name="trunks:moss_with_fungus_"..rot, param2=4}) elseif moss_type < 22 then - minetest.swap_node(at_side_s, {name="trunks:moss", param2=math.random(8,11)}) + minetest.swap_node(at_side_s, {name="trunks:moss_plain_"..rot, param2=4}) end end - local moss_type = math.random(1,41) - if minetest.registered_nodes[node_west.name].buildable_to then -- instead of check_air = true, + if minetest.registered_nodes[node_west.name].buildable_to then + local moss_type = math.random(1,41) + local rot = math.random(0,3) if moss_type == 1 then - minetest.swap_node(at_side_w, {name="trunks:moss_fungus", param2=math.random(16,19)}) + minetest.swap_node(at_side_w, {name="trunks:moss_with_fungus_"..rot, param2=2}) elseif moss_type < 22 then - minetest.swap_node(at_side_w, {name="trunks:moss", param2=math.random(16,19)}) + minetest.swap_node(at_side_w, {name="trunks:moss_plain_"..rot, param2=2}) end end --end diff --git a/trunks/nodes.lua b/trunks/nodes.lua index 5f3906f..cc7f919 100644 --- a/trunks/nodes.lua +++ b/trunks/nodes.lua @@ -65,42 +65,61 @@ end ----------------------------------------------------------------------------------------------- -- MoSS ----------------------------------------------------------------------------------------------- -local flat_moss = {-1/2, -1/2, -1/2, 1/2, -15/32--[[<-flickers if smaller]], 1/2} -minetest.register_node("trunks:moss", { - description = S("Moss"), - drawtype = "nodebox",--"signlike", - tiles = {"trunks_moss.png"}, - inventory_image = "trunks_moss.png", - wield_image = "trunks_moss.png", - paramtype = "light", - paramtype2 = "facedir",--"wallmounted", - sunlight_propagates = true, - walkable = false, - node_box = {type = "fixed", fixed = flat_moss}, - selection_box = {type = "fixed", fixed = flat_stick},--{type = "wallmounted"}, - groups = {snappy = 3, flammable = 3, attached_node=1 }, - sounds = default.node_sound_leaves_defaults(), -}) +-- wall_top = {-0.4375, 0.4375, -0.3125, 0.4375, 0.5, 0.3125}, +-- wall_bottom = {-0.4375, -0.5, -0.3125, 0.4375, -0.4375, 0.3125}, +-- wall_side = {-0.5, -0.3125, -0.4375, -0.4375, 0.3125, 0.4375}, ------------------------------------------------------------------------------------------------ --- MoSS & FuNGuS ------------------------------------------------------------------------------------------------ -minetest.register_node("trunks:moss_fungus", { - description = S("Moss with Fungus"), - drawtype = "nodebox",--"signlike", - tiles = {"trunks_moss_fungus.png"}, - inventory_image = "trunks_moss_fungus.png", - wield_image = "trunks_moss_fungus.png", - paramtype = "light", - paramtype2 = "facedir",--"wallmounted", - sunlight_propagates = true, - walkable = false, - node_box = {type = "fixed", fixed = flat_moss}, - selection_box = {type = "fixed", fixed = flat_stick},--{type = "wallmounted"}, - groups = {snappy = 3, flammable = 3, attached_node=1 }, - sounds = default.node_sound_leaves_defaults(), -}) +-- was local flat_moss = {-1/2, -1/2, -1/2, 1/2, -15/32, 1/2} + + +local cbox = { + type = "wallmounted", + wall_top = {-1/2, 1/2, -1/2, 1/2, 15/32, 1/2}, + wall_bottom = {-1/2, -1/2, -1/2, 1/2, -15/32, 1/2}, + wall_side = {-1/2, -1/2, -1/2, -15/32, 1/2, 1/2} +} + +for r = 0, 3 do + local xform = "" + if r > 0 then xform = "^[transformR"..r*90 end + + minetest.register_node("trunks:moss_plain_"..r, { + description = S("Moss"), + drawtype = "nodebox", + tiles = {"trunks_moss.png"..xform}, + inventory_image = "trunks_moss.png", + wield_image = "trunks_moss.png", + paramtype = "light", + paramtype2 = "wallmounted", + sunlight_propagates = true, + walkable = false, + node_box = cbox, + groups = {snappy = 3, flammable = 3, attached_node=1, not_in_creative_inventory = r}, + sounds = default.node_sound_leaves_defaults(), + }) + + ----------------------------------------------------------------------------------------------- + -- MoSS & FuNGuS + ----------------------------------------------------------------------------------------------- + minetest.register_node("trunks:moss_with_fungus_"..r, { + description = S("Moss with Fungus"), + drawtype = "nodebox", + tiles = {"trunks_moss_fungus.png"..xform}, + inventory_image = "trunks_moss_fungus.png", + wield_image = "trunks_moss_fungus.png", + paramtype = "light", + paramtype2 = "wallmounted", + sunlight_propagates = true, + walkable = false, + node_box = cbox, + groups = {snappy = 3, flammable = 3, attached_node=1, not_in_creative_inventory = r}, + sounds = default.node_sound_leaves_defaults(), + }) +end + +minetest.register_alias("trunks:moss_plain", "trunks:moss_plain_0") +minetest.register_alias("trunks:moss_with_fungus", "trunks:moss_with_fungus_0") ----------------------------------------------------------------------------------------------- -- TWiGS BLoCK @@ -362,18 +381,13 @@ for i in pairs(TRuNKS) do choppy=2, oddly_breakable_by_hand=1, flammable=2, + attached_node = 1 --not_in_creative_inventory=1 -- atm in inv for testing }, --drop = "trunks:twig_1", -- not sure about this yet sounds = default.node_sound_wood_defaults(), }) - default.register_leafdecay({ - trunks = { MoD..":"..TRuNK }, - leaves = { "trunks:"..TRuNK.."root" }, - radius = 1, - }) - else minetest.log("error", string.format("[Trunks] warning: tree type '%s:%s' not found", MoD, TRuNK)) end @@ -382,3 +396,26 @@ end end minetest.register_alias("trunks:pine_trunkroot", "trunks:pine_treeroot") + +-- convert moss to wallmounted mode so that attached_node works properly. + +local fdirtowall = { + [0] = 1, + [1] = 5, + [2] = 4, + [3] = 3, + [4] = 2, +} + +minetest.register_lbm({ + name = "trunks:convert_moss_wallmounted", + label = "Convert moss to wallmounted mode", + run_at_every_load = false, + nodenames = {"trunks:moss", "trunks:moss_fungus"}, + action = function(pos, node) + local basedir = math.floor(node.param2 / 4) + local rot = node.param2 % 4 + local newname = node.name == "trunks:moss_fungus" and "trunks:moss_with_fungus" or "trunks:moss_plain" + minetest.set_node(pos, {name = newname.."_"..rot, param2 = fdirtowall[basedir] }) + end +}) From b1b4a088346921b5e0eb4619e3b5af3292000977 Mon Sep 17 00:00:00 2001 From: Vanessa Dannenberg Date: Mon, 21 Jun 2021 00:36:14 -0400 Subject: [PATCH 2/6] make pebbles fall when ground is dug. --- cavestuff/nodes.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cavestuff/nodes.lua b/cavestuff/nodes.lua index 654ceeb..7dcf6b7 100644 --- a/cavestuff/nodes.lua +++ b/cavestuff/nodes.lua @@ -15,7 +15,7 @@ minetest.register_node("cavestuff:pebble_1",{ tiles = {"undergrowth_pebble.png"}, paramtype = "light", paramtype2 = "facedir", - groups = {cracky=3, stone=1}, + groups = {cracky=3, stone=1, attached_node=1}, selection_box = cbox, collision_box = cbox, on_place = function(itemstack, placer, pointed_thing) @@ -35,7 +35,7 @@ minetest.register_node("cavestuff:pebble_2",{ tiles = {"undergrowth_pebble.png"}, paramtype = "light", paramtype2 = "facedir", - groups = {cracky=3, stone=1, not_in_creative_inventory=1}, + groups = {cracky=3, stone=1, attached_node=1, not_in_creative_inventory=1}, selection_box = cbox, collision_box = cbox, sounds = default.node_sound_stone_defaults(), @@ -48,7 +48,7 @@ minetest.register_node("cavestuff:desert_pebble_1",{ tiles = {"default_desert_stone.png"}, paramtype = "light", paramtype2 = "facedir", - groups = {cracky=3, stone=1}, + groups = {cracky=3, stone=1, attached_node=1}, selection_box = cbox, collision_box = cbox, on_place = function(itemstack, placer, pointed_thing) @@ -67,7 +67,7 @@ minetest.register_node("cavestuff:desert_pebble_2",{ tiles = {"default_desert_stone.png"}, paramtype = "light", paramtype2 = "facedir", - groups = {cracky=3, stone=1, not_in_creative_inventory=1}, + groups = {cracky=3, stone=1, attached_node=1, not_in_creative_inventory=1}, selection_box = cbox, collision_box = cbox, sounds = default.node_sound_stone_defaults(), From b3cbd3df2ed28f69c976585f325076dbebddc27e Mon Sep 17 00:00:00 2001 From: Vanessa Dannenberg Date: Mon, 21 Jun 2021 05:21:34 -0400 Subject: [PATCH 3/6] fix moss node drops --- trunks/nodes.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/trunks/nodes.lua b/trunks/nodes.lua index cc7f919..60c02ec 100644 --- a/trunks/nodes.lua +++ b/trunks/nodes.lua @@ -97,6 +97,7 @@ for r = 0, 3 do node_box = cbox, groups = {snappy = 3, flammable = 3, attached_node=1, not_in_creative_inventory = r}, sounds = default.node_sound_leaves_defaults(), + drop = "trunks:moss_plain_0", }) ----------------------------------------------------------------------------------------------- @@ -115,6 +116,7 @@ for r = 0, 3 do node_box = cbox, groups = {snappy = 3, flammable = 3, attached_node=1, not_in_creative_inventory = r}, sounds = default.node_sound_leaves_defaults(), + drop = "trunks:moss_with_fungus_0", }) end From 3f107a806793f3af6e97290a329de4e869d7888f Mon Sep 17 00:00:00 2001 From: Vanessa Dannenberg Date: Wed, 23 Jun 2021 10:09:58 -0400 Subject: [PATCH 4/6] renamed the LBM in case it got run at the wrong time between mod updates; forces it to run again (it's harmless to let it run twice) --- trunks/nodes.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trunks/nodes.lua b/trunks/nodes.lua index 60c02ec..90e38d9 100644 --- a/trunks/nodes.lua +++ b/trunks/nodes.lua @@ -410,7 +410,7 @@ local fdirtowall = { } minetest.register_lbm({ - name = "trunks:convert_moss_wallmounted", + name = "trunks:convert_moss_wallmounted_2", label = "Convert moss to wallmounted mode", run_at_every_load = false, nodenames = {"trunks:moss", "trunks:moss_fungus"}, From 9ed47715159962cd42f69c441dcc9eee150e4f66 Mon Sep 17 00:00:00 2001 From: Vanessa Dannenberg Date: Wed, 23 Jun 2021 21:03:06 -0400 Subject: [PATCH 5/6] fix rare edge-case where unknown nodes cause a crash When a new mapblock is generated and the mod checks the neighbors around a target to place a fallen twig, if it finds an unknown node (because it's in a neighboring, old mapblock from a previous session -- perhaps an old moss node that hadn't converted-over to wallmounted yet), trying to check its buildable_to state will fail, since that requires that there be a node def to look at, which an unknown node wouldn't have. This substitutes a known not-buildable_to node for those cases, so that the code won't try to overwrite what it found. --- trunks/generating.lua | 54 ++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/trunks/generating.lua b/trunks/generating.lua index af19254..f693df6 100644 --- a/trunks/generating.lua +++ b/trunks/generating.lua @@ -4,28 +4,44 @@ -- TWiGS ----------------------------------------------------------------------------------------------- +local fakenode = { + name = "default:stone", -- could be anything that's guaranteed to exist at mapgen time, and isn't buildable_to + param1 = 0, + param2 = 0 +} + abstract_trunks.place_twig = function(pos) - local twig_size = math.random(1,27) + local twig_size = math.random(1,27) - local right_here = {x=pos.x , y=pos.y+1, z=pos.z } - local north = {x=pos.x , y=pos.y+1, z=pos.z+1} - local north_east = {x=pos.x+1, y=pos.y+1, z=pos.z+1} - local east = {x=pos.x+1, y=pos.y+1, z=pos.z } - local south_east = {x=pos.x+1, y=pos.y+1, z=pos.z-1} - local south = {x=pos.x , y=pos.y+1, z=pos.z-1} - local south_west = {x=pos.x-1, y=pos.y+1, z=pos.z-1} - local west = {x=pos.x-1, y=pos.y+1, z=pos.z } - local north_west = {x=pos.x-1, y=pos.y+1, z=pos.z+1} + local right_here = {x=pos.x , y=pos.y+1, z=pos.z } + local north = {x=pos.x , y=pos.y+1, z=pos.z+1} + local north_east = {x=pos.x+1, y=pos.y+1, z=pos.z+1} + local east = {x=pos.x+1, y=pos.y+1, z=pos.z } + local south_east = {x=pos.x+1, y=pos.y+1, z=pos.z-1} + local south = {x=pos.x , y=pos.y+1, z=pos.z-1} + local south_west = {x=pos.x-1, y=pos.y+1, z=pos.z-1} + local west = {x=pos.x-1, y=pos.y+1, z=pos.z } + local north_west = {x=pos.x-1, y=pos.y+1, z=pos.z+1} + + local node_here = minetest.get_node(right_here) + local node_north = minetest.get_node(north) + local node_n_e = minetest.get_node(north_east) + local node_east = minetest.get_node(east) + local node_s_e = minetest.get_node(south_east) + local node_south = minetest.get_node(south) + local node_s_w = minetest.get_node(south_west) + local node_west = minetest.get_node(west) + local node_n_w = minetest.get_node(north_west) + + node_north = minetest.registered_nodes[node_north.name] and node_north or fakenode + node_n_e = minetest.registered_nodes[node_n_e.name] and node_n_e or fakenode + node_east = minetest.registered_nodes[node_east.name] and node_east or fakenode + node_s_e = minetest.registered_nodes[node_s_e.name] and node_s_e or fakenode + node_south = minetest.registered_nodes[node_south.name] and node_south or fakenode + node_s_w = minetest.registered_nodes[node_s_w.name] and node_s_w or fakenode + node_west = minetest.registered_nodes[node_west.name] and node_west or fakenode + node_n_w = minetest.registered_nodes[node_n_w.name] and node_n_w or fakenode - local node_here = minetest.get_node(right_here) - local node_north = minetest.get_node(north) - local node_n_e = minetest.get_node(north_east) - local node_east = minetest.get_node(east) - local node_s_e = minetest.get_node(south_east) - local node_south = minetest.get_node(south) - local node_s_w = minetest.get_node(south_west) - local node_west = minetest.get_node(west) - local node_n_w = minetest.get_node(north_west) -- small twigs if twig_size <= 16 then minetest.swap_node(right_here, {name="trunks:twig_"..math.random(1,4), param2=math.random(0,3)}) From bfd08f01c8b41756f604c8bd71ccc1efeae1239d Mon Sep 17 00:00:00 2001 From: Vanessa Dannenberg Date: Wed, 23 Jun 2021 21:09:48 -0400 Subject: [PATCH 6/6] Just run the conversion LBM on every load it won't take any appreciable CPU anyway if there's nothing to do. Minetest seems to not new (or newly-renamed) LBMs when it should, when it's set to only run once. Also covers cases where a crash could prevent mapblocks being checked later. --- trunks/nodes.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trunks/nodes.lua b/trunks/nodes.lua index 90e38d9..04d124f 100644 --- a/trunks/nodes.lua +++ b/trunks/nodes.lua @@ -410,9 +410,9 @@ local fdirtowall = { } minetest.register_lbm({ - name = "trunks:convert_moss_wallmounted_2", + name = "trunks:convert_moss_wallmounted", label = "Convert moss to wallmounted mode", - run_at_every_load = false, + run_at_every_load = true, nodenames = {"trunks:moss", "trunks:moss_fungus"}, action = function(pos, node) local basedir = math.floor(node.param2 / 4)