add growing tree nodes.

add `log_alive` and `leaves_alive`. make alive logs actually have a top
texture (bottom texture and dead logs are still wrong, though).

slightly refactor some tree growth code.
This commit is contained in:
trans_soup 2023-10-11 18:23:09 +02:00
parent ac307233a1
commit c3fb8df14a
9 changed files with 46 additions and 27 deletions

View file

@ -2,6 +2,16 @@ local modname = minetest.get_current_modname()
local api = blockgame.tree
local vec = blockgame.vector
-- NODE NAMES
local log = modname .. ":log"
local log_alive = modname .. ":log_alive"
local leaves = modname .. ":leaves"
local leaves_alive = modname .. ":leaves_alive"
local root = modname .. ":root"
-- END OF NODE NAMES
local attempt_place = function (pos, node)
if minetest.get_node(pos).name ~= "air" then return false end
return minetest.set_node(pos, node)
@ -10,7 +20,7 @@ end
local extend_leaves_from = function (pos)
local side = vec.random_side()
attempt_place(pos + side, {name = modname .. ":leaves"})
attempt_place(pos + side, {name = leaves_alive})
end
local random_walk = function (pos, steps, check)
@ -27,15 +37,15 @@ end
local spread_roots_from = function (source)
local root_pos = random_walk(source, 2, function (pos)
if minetest.get_node(pos).name == modname .. ":log" then return true end
if minetest.get_node(pos).name == modname .. ":root" then return true end
if minetest.get_node(pos).name == log_alive then return true end
if minetest.get_node(pos).name == root then return true end
return false
end)
local root_node = minetest.get_node(root_pos)
if minetest.get_node(root_pos + vector.new(0, 1, 0)).name == modname .. ":log" then
minetest.set_node(root_pos, {name = modname .. ":root"})
if minetest.get_node(root_pos + vector.new(0, 1, 0)).name == log_alive then
minetest.set_node(root_pos, {name = root})
return true
end
@ -44,7 +54,7 @@ local spread_roots_from = function (source)
if blockgame.chance(2) then target_pos = vec.get_below(root_pos) end
if minetest.get_item_group(minetest.get_node(target_pos), "dirty") then
return minetest.set_node(target_pos, {name = modname .. ":root"})
return minetest.set_node(target_pos, {name = root})
end
return false
@ -53,7 +63,7 @@ end
minetest.register_abm({
label = "sapling grow",
nodenames = {"tree:sapling"},
neighbors = {"group:dirty", modname .. ":log"},
neighbors = {"group:dirty", log_alive},
interval = 15,
chance = 4,
catch_up = true,
@ -78,7 +88,7 @@ minetest.register_abm({
local side = vec.random_side()
local target = pos + side
attempt_place(target, {name = modname .. ":log"})
attempt_place(target, {name = log_alive})
if blockgame.chance(2) then
extend_leaves_from(target)
@ -86,9 +96,9 @@ minetest.register_abm({
end
if blockgame.chance(4) then
minetest.set_node(pos, {name = modname .. ":log"})
minetest.set_node(pos, {name = log_alive})
if minetest.get_node(below).name == modname .. ":log" and blockgame.chance(2) then return end
if minetest.get_node(below).name == log_alive and blockgame.chance(2) then return end
attempt_place(pos + vector.new(0, 1, 0), {name = modname .. ":sapling"})
end

View file

@ -3,11 +3,24 @@ local modname = minetest.get_current_modname()
blockgame.reg_simple_node("log", "Log", {
woody = 1,
})
minetest.register_node(modname .. ":log_alive", {
description = "Growing Log",
tiles = {
modname .. "_log_top.png",
modname .. "_log_alive.png",
},
groups = {
woody = 1,
planty = 1,
},
drop = modname .. ":log",
})
blockgame.reg_simple_node("sapling", "Sapling", {
planty = 1,
})
-- TODO: move this to the woodworking mod.
blockgame.reg_simple_node("plank", "Plank", {
woody = 1,
})
@ -23,23 +36,19 @@ minetest.register_node(modname .. ":leaves", {
groups = {
planty = 1,
},
drop = {
max_items = 2,
items = {
{
rarity = 16,
items = {modname .. ":nut 3"}
},
{
rarity = 8,
items = {modname .. ":nut 2"}
},
{
rarity = 4,
items = {modname .. ":nut"}
},
},
})
minetest.register_node(modname .. ":leaves_alive", {
description = "Growing Leaves",
drawtype = "glasslike",
tiles = {
modname .. "_leaves_alive.png",
},
paramtype = "light",
sunlight_propagates = true,
groups = {
planty = 1,
},
drop = modname .. ":leaves",
})
blockgame.reg_simple_node("nut", "Nut", {

View file

@ -5,7 +5,6 @@ local modname = minetest.get_current_modname()
blockgame.crafting.register_stack_recipe("core:grass", modname .. ":nut", {name = modname .. ":sapling"})
blockgame.crafting.register_stack_recipe("core:dirt", modname .. ":nut", {name = modname .. ":sapling"})
-- NOTE: is currently useless, as there's no way to obtain leaves.
blockgame.crafting.register_pummel_recipe({
label = "pummel leaves into dirt",
used_item = modname .. ":leaves",
@ -15,6 +14,7 @@ blockgame.crafting.register_pummel_recipe({
end,
})
-- TODO: move this to the woodworking mod.
blockgame.crafting.register_pummel_recipe({
label = "pummel log into plank",
used_item = "core:stone",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 956 B

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 305 B

After

Width:  |  Height:  |  Size: 857 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 657 B

After

Width:  |  Height:  |  Size: 887 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB