Skip to content
Snippets Groups Projects
sapling.lua 6.09 KiB
Newer Older
TenPlus1's avatar
TenPlus1 committed
local S = ethereal.intllib

-- Bamboo Sprout
minetest.register_node("ethereal:bamboo_sprout", {
TenPlus1's avatar
TenPlus1 committed
	description = S("Bamboo Sprout"),
	drawtype = "plantlike",
	tiles = {"bamboo_sprout.png"},
	inventory_image = "bamboo_sprout.png",
	wield_image = "bamboo_sprout.png",
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	groups = {
		snappy = 3, attached_node = 1, flammable = 2,
TenPlus1's avatar
TenPlus1 committed
		dig_immediate = 3, ethereal_sapling = 1
	},
	sounds = default.node_sound_defaults(),
	selection_box = {
		type = "fixed",
		fixed = {-0.5, -0.5, -0.5, 0.5, -5/16, 0.5},
	},
	on_use = minetest.item_eat(-2),
TenPlus1's avatar
TenPlus1 committed
	grown_height = 11,
tenplus1's avatar
tenplus1 committed
-- Register Saplings
TenPlus1's avatar
TenPlus1 committed
ethereal.register_sapling = function(name, desc, texture, height)
TenPlus1's avatar
TenPlus1 committed

	minetest.register_node(name .. "_sapling", {
TenPlus1's avatar
TenPlus1 committed
		description = S(desc .. " Tree Sapling"),
TenPlus1's avatar
TenPlus1 committed
		drawtype = "plantlike",
		visual_scale = 1.0,
		tiles = {texture .. ".png"},
		inventory_image = texture .. ".png",
		wield_image = texture .. ".png",
TenPlus1's avatar
TenPlus1 committed
		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
TenPlus1's avatar
TenPlus1 committed
		},
		sounds = default.node_sound_defaults(),
TenPlus1's avatar
TenPlus1 committed
		grown_height = height,
TenPlus1's avatar
TenPlus1 committed
	})
tenplus1's avatar
tenplus1 committed
end

TenPlus1's avatar
TenPlus1 committed
ethereal.register_sapling("ethereal:willow", "Willow", "willow_sapling", 14)
ethereal.register_sapling("ethereal:yellow_tree", "Healing", "yellow_tree_sapling", 19)
ethereal.register_sapling("ethereal:big_tree", "Big", "ethereal_big_tree_sapling", 7)
ethereal.register_sapling("ethereal:banana_tree", "Banana", "banana_tree_sapling", 8)
ethereal.register_sapling("ethereal:frost_tree", "Frost", "ethereal_frost_tree_sapling", 19)
ethereal.register_sapling("ethereal:mushroom", "Mushroom", "ethereal_mushroom_sapling", 11)
ethereal.register_sapling("ethereal:palm", "Palm", "moretrees_palm_sapling", 9)
ethereal.register_sapling("ethereal:redwood", "Redwood", "redwood_sapling", 31)
ethereal.register_sapling("ethereal:orange_tree", "Orange", "orange_tree_sapling", 6)
ethereal.register_sapling("ethereal:birch", "Birch", "moretrees_birch_sapling", 7)

ethereal.add_tree = function (pos, ofx, ofy, ofz, schem)
tenplus1's avatar
tenplus1 committed
	-- check for schematic
	if not schem then
TenPlus1's avatar
TenPlus1 committed
		print (S("Schematic not found"))
tenplus1's avatar
tenplus1 committed
		return
	end
	-- remove sapling and place schematic
TenPlus1's avatar
TenPlus1 committed
	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)
TenPlus1's avatar
TenPlus1 committed
local path = minetest.get_modpath("ethereal").."/schematics/"

-- grow tree functions
function ethereal.grow_yellow_tree(pos)
	ethereal.add_tree(pos, 4, 0, 4, path .. "yellowtree.mts")
end

function ethereal.grow_big_tree(pos)
	ethereal.add_tree(pos, 4, 0, 4, path .. "bigtree.mts")
end

function ethereal.grow_banana_tree(pos)
	ethereal.add_tree(pos, 3, 0, 3, ethereal.bananatree)
end

function ethereal.grow_frost_tree(pos)
	ethereal.add_tree(pos, 4, 0, 4, path .. "frosttrees.mts")
end

function ethereal.grow_mushroom_tree(pos)
	ethereal.add_tree(pos, 4, 0, 4, path .. "mushroomone.mts")
end

function ethereal.grow_palm_tree(pos)
	ethereal.add_tree(pos, 4, 0, 4, path .. "palmtree.mts")
end

function ethereal.grow_willow_tree(pos)
	ethereal.add_tree(pos, 5, 0, 5, path .. "willow.mts")
end

function ethereal.grow_redwood_tree(pos)
Milan's avatar
Milan committed
		ethereal.add_tree(pos, 8, 34, 8, path .. "redwood_tree.mts") -- iska
end

function ethereal.grow_orange_tree(pos)
	ethereal.add_tree(pos, 1, 0, 1, ethereal.orangetree)
end

function ethereal.grow_bamboo_tree(pos)
	ethereal.add_tree(pos, 1, 0, 1, ethereal.bambootree)
end

function ethereal.grow_birch_tree(pos)
	ethereal.add_tree(pos, 2, 0, 2, ethereal.birchtree)
end

TenPlus1's avatar
TenPlus1 committed
-- check if sapling has enough height room to grow
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

ethereal.grow_sapling = function (pos, node)

	local under =  minetest.get_node({
		x = pos.x,
		y = pos.y - 1,
		z = pos.z
	}).name
TenPlus1's avatar
TenPlus1 committed
	if not minetest.registered_nodes[node.name] then
		return
	end

	local height = minetest.registered_nodes[node.name].grown_height

	-- do we have enough height to grow sapling into tree?
	if not height or not enough_height(pos, height) then
		return
	end

	-- Check if Ethereal Sapling is growing on correct substrate
TenPlus1's avatar
TenPlus1 committed
	if node.name == "ethereal:yellow_tree_sapling"
	and under == "default:dirt_with_snow" then
		ethereal.grow_yellow_tree(pos)
TenPlus1's avatar
TenPlus1 committed

	elseif node.name == "ethereal:big_tree_sapling"
	and under == "ethereal:green_dirt" then
		ethereal.grow_big_tree(pos)
TenPlus1's avatar
TenPlus1 committed

	elseif node.name == "ethereal:banana_tree_sapling"
	and under == "ethereal:grove_dirt" then
		ethereal.grow_banana_tree(pos)
TenPlus1's avatar
TenPlus1 committed

	elseif node.name == "ethereal:frost_tree_sapling"
	and under == "ethereal:crystal_dirt" then
		ethereal.grow_frost_tree(pos)
TenPlus1's avatar
TenPlus1 committed

	elseif node.name == "ethereal:mushroom_sapling"
	and under == "ethereal:mushroom_dirt" then
		ethereal.grow_mushroom_tree(pos)
TenPlus1's avatar
TenPlus1 committed

	elseif node.name == "ethereal:palm_sapling"
	and under == "default:sand" then
		ethereal.grow_palm_tree(pos)
TenPlus1's avatar
TenPlus1 committed

	elseif node.name == "ethereal:willow_sapling"
	and under == "ethereal:gray_dirt" then
		ethereal.grow_willow_tree(pos)
TenPlus1's avatar
TenPlus1 committed

	elseif node.name == "ethereal:redwood_sapling"
Milan's avatar
Milan committed
	and under == "ethereal:mesa_dirt" then
		ethereal.grow_redwood_tree(pos)
TenPlus1's avatar
TenPlus1 committed

	elseif node.name == "ethereal:orange_tree_sapling"
	and under == "ethereal:prairie_dirt" then
		ethereal.grow_orange_tree(pos)

	elseif node.name == "ethereal:bamboo_sprout"
	and under == "ethereal:bamboo_dirt" then
		ethereal.grow_bamboo_tree(pos)

	elseif node.name == "ethereal:birch_sapling"
	and under == "ethereal:green_dirt" then
		ethereal.grow_birch_tree(pos)
tenplus1's avatar
tenplus1 committed
-- Grow saplings
minetest.register_abm({
TenPlus1's avatar
TenPlus1 committed
	label = "Ethereal grow sapling",
tenplus1's avatar
tenplus1 committed
	nodenames = {"group:ethereal_sapling"},
tenplus1's avatar
tenplus1 committed
	interval = 10,
	chance = 50,
TenPlus1's avatar
TenPlus1 committed
	catch_up = false,
tenplus1's avatar
tenplus1 committed
	action = function(pos, node)
		local light_level = minetest.get_node_light(pos)
		if not light_level or light_level < 13 then
		ethereal.grow_sapling(pos, node)