aestivalserver-mods/illuna_aestival/src/saplings.lua

118 lines
3.0 KiB
Lua
Executable File

illuna_ethereal = {}
illuna_ethereal.register_sapling = function(name, desc, texture, height)
minetest.register_node(name .. "_sapling", {
description = desc .. " Tree Sapling",
drawtype = "plantlike",
visual_scale = 1.0,
tiles = {texture .. ".png"},
inventory_image = texture .. ".png",
wield_image = texture .. ".png",
paramtype = "light",
sunlight_propagates = true,
is_ground_content = false,
walkable = false,
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5}
},
groups = {
snappy = 2, dig_immediate = 3, flammable = 2,
ethereal_sapling = 1, sapling = 1, attached_node = 1
},
sounds = default.node_sound_defaults(),
grown_height = height,
buildable_to = true,
})
end
illuna_ethereal.register_sapling(":illuna_ethereal:douglasie", "Douglasie", "douglasie_sapling", 0)
illuna_ethereal.register_sapling(":ethereal:redwood", "Redwood", "redwood_sapling", 31)
illuna_ethereal.add_tree = function (pos, ofx, ofy, ofz, schem)
-- check for schematic
if not schem then
print ("Schematic not found")
return
end
-- remove sapling and place schematic
minetest.swap_node(pos, {name = "air"})
minetest.place_schematic(
{x = pos.x - ofx, y = pos.y - ofy, z = pos.z - ofz},
schem, 0, nil, false)
end
local path = minetest.get_modpath("illuna_aestival").."/schematics/"
function illuna_ethereal.grow_douglasie_tree(pos)
illuna_ethereal.add_tree(pos, 5, 0, 5, path .. "douglasie.mts")
end
function illuna_ethereal.grow_redwood_tree(pos)
illuna_ethereal.add_tree(pos, 8, 47, 8, path .. "redwood_tree.mts")
end
local function enough_height(pos, height)
local nod = minetest.line_of_sight(
{x = pos.x, y = pos.y + 1, z = pos.z},
{x = pos.x, y = pos.y + height, z = pos.z})
if not nod then
return false -- obstructed
else
return true -- can grow
end
end
illuna_ethereal.grow_sapling = function (pos, node)
local under = minetest.get_node({
x = pos.x,
y = pos.y - 1,
z = pos.z
}).name
if not minetest.registered_nodes[node.name] then
return
end
local height = minetest.registered_nodes[node.name].grown_height
if not height or not enough_height(pos, height) then
return
end
if node.name == "illuna_ethereal:douglasie_sapling"
and under == "default:dirt_with_grass" then
illuna_ethereal.grow_douglasie_tree(pos)
elseif node.name == "ethereal:redwood_sapling"
and under == "ethereal:mesa_dirt" then
illuna_ethereal.grow_redwood_tree(pos)
end
end
-- Grow saplings
minetest.register_abm({
label = "Illuna ethereal grow sapling",
nodenames = {"group:ethereal_sapling"},
interval = 10,
chance = 80,
catch_up = false,
action = function(pos, node)
local light_level = minetest.get_node_light(pos)
if not light_level or light_level < 13 then
return
end
illuna_ethereal.grow_sapling(pos, node)
end,
})
bonemeal:add_sapling({
{ "ethereal:redwood_sapling", illuna_ethereal.grow_redwood_tree, "soil" },
{ "illuna_ethereal:douglasie_sapling", illuna_ethereal.grow_douglasie_tree, "soil" },
})