123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- local add_tree = function (pos, ofx, ofy, ofz, schem, replace)
- -- 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, replace, false)
- end
- -- Register Saplings
- local register_sapling = function(name, desc, texture, height)
- minetest.register_node(name .. "_sapling", {
- description = desc .. " Tree Sapling",
- drawtype = "plantlike",
- 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 = {-4 / 16, -0.5, -4 / 16, 4 / 16, 7 / 16, 4 / 16}
- },
- groups = {
- snappy = 2, dig_immediate = 3, flammable = 2,
- epic_trees_sapling = 1, attached_node = 1, sapling = 1
- },
- sounds = default.node_sound_leaves_defaults(),
- grown_height = height,
- })
- end
- register_sapling("epic_trees:banana_tree", "Banana", "banana_tree_sapling", 8)
- register_sapling("epic_trees:orange_tree", "Orange", "orange_tree_sapling", 6)
- function epic_trees.grow_banana_tree(pos)
- add_tree(pos, 3, 0, 3, epic_trees.bananatree)
- end
- function epic_trees.grow_orange_tree(pos)
- add_tree(pos, 1, 0, 1, epic_trees.orangetree)
- end
- local enough_height = function(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
- local function contains(table, val)
- for i=1,#table do
- if table[i] == val then
- return true
- end
- end
- return false
- end
-
- local grow_sapling = function(pos, node)
- print("we grow")
- 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
- -- 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
- if node.name == "epic_trees:banana_tree_sapling"
- and contains({"default:dirt", "default:sand", 'default:dirt_with_grass'}, under) then
- epic_trees.grow_banana_tree(pos)
- end
- end
- minetest.register_abm({
- label = "Epic Trees grow sapling",
- nodenames = {"group:epic_trees_sapling"},
- interval = 10,
- chance = 50,
- catch_up = false,
- action = function(pos, node)
- local light_level = minetest.get_node_light(pos) or 0
- if light_level < 13 then
- return
- end
- grow_sapling(pos, node)
- end,
- })
|