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.
master
Vanessa Dannenberg 2021-06-20 23:18:32 -04:00
parent 7b4f54ead0
commit f01e4bb55f
2 changed files with 105 additions and 62 deletions

View File

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

View File

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