2020-02-22 11:49:17 -05:00
|
|
|
--saplings
|
2020-05-08 06:46:54 -04:00
|
|
|
--
|
|
|
|
--
|
2020-05-09 07:39:53 -04:00
|
|
|
--local sapling_min = 120
|
|
|
|
--local sapling_max = 720
|
2020-05-08 06:46:54 -04:00
|
|
|
--make sapling grow
|
|
|
|
local function sapling_grow(pos)
|
|
|
|
if minetest.get_node_light(pos, nil) < 10 then
|
|
|
|
--print("failed to grow at "..dump(pos))
|
|
|
|
return
|
|
|
|
end
|
|
|
|
--print("growing at "..dump(pos))
|
|
|
|
if minetest.get_node_group(minetest.get_node(vector.new(pos.x,pos.y-1,pos.z)).name, "soil") > 0 then
|
|
|
|
local good_to_grow = true
|
|
|
|
--check if room to grow (leaves or air)
|
|
|
|
for i = 1,4 do
|
|
|
|
local node_name = minetest.get_node(vector.new(pos.x,pos.y+i,pos.z)).name
|
|
|
|
if node_name ~= "air" and node_name ~= "main:leaves" then
|
|
|
|
good_to_grow = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if good_to_grow == true then
|
|
|
|
minetest.set_node(pos,{name="main:tree"})
|
2020-05-09 09:24:09 -04:00
|
|
|
local schemmy = math.random(1,2)
|
|
|
|
if schemmy == 1 then
|
|
|
|
minetest.place_schematic(pos, tree_big,"0",nil,false,"place_center_x, place_center_z")
|
|
|
|
elseif schemmy == 2 then
|
|
|
|
minetest.place_schematic(pos, tree_small,"0",nil,false,"place_center_x, place_center_z")
|
|
|
|
end
|
2020-05-08 06:46:54 -04:00
|
|
|
--override leaves
|
2020-05-09 09:24:09 -04:00
|
|
|
local max = 3
|
|
|
|
if schemmy == 2 then
|
|
|
|
max = 1
|
|
|
|
end
|
|
|
|
for i = 1,max do
|
2020-05-08 06:46:54 -04:00
|
|
|
minetest.set_node(vector.new(pos.x,pos.y+i,pos.z),{name="main:tree"})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-22 11:49:17 -05:00
|
|
|
minetest.register_node("main:sapling", {
|
2020-03-10 23:56:27 -07:00
|
|
|
description = "Sapling",
|
|
|
|
drawtype = "plantlike",
|
2020-05-08 06:46:54 -04:00
|
|
|
inventory_image = "sapling.png",
|
2020-03-10 23:56:27 -07:00
|
|
|
waving = 1,
|
|
|
|
walkable = false,
|
|
|
|
climbable = false,
|
|
|
|
paramtype = "light",
|
|
|
|
is_ground_content = false,
|
|
|
|
tiles = {"sapling.png"},
|
2020-05-08 07:35:45 -04:00
|
|
|
groups = {leaves = 1, plant = 1, axe = 1, hand = 0,instant=1, sapling=1, attached_node=1,flammable=1},
|
2020-05-08 06:46:54 -04:00
|
|
|
sounds = main.dirtSound(),
|
2020-03-10 23:56:27 -07:00
|
|
|
drop = "main:sapling",
|
|
|
|
node_placement_prediction = "",
|
|
|
|
selection_box = {
|
2020-02-22 11:49:17 -05:00
|
|
|
type = "fixed",
|
|
|
|
fixed = {-4 / 16, -0.5, -4 / 16, 4 / 16, 7 / 16, 4 / 16}
|
|
|
|
},
|
2020-04-09 21:37:36 -04:00
|
|
|
on_place = on_rightclick or function(itemstack, placer, pointed_thing)
|
2020-03-10 23:56:27 -07:00
|
|
|
if not pointed_thing.type == "node" then
|
|
|
|
return
|
|
|
|
end
|
2020-04-09 22:15:06 -04:00
|
|
|
|
|
|
|
local sneak = placer:get_player_control().sneak
|
|
|
|
local noddef = minetest.registered_nodes[minetest.get_node(pointed_thing.under).name]
|
|
|
|
|
|
|
|
if not sneak and noddef.on_rightclick then
|
|
|
|
minetest.item_place(itemstack, placer, pointed_thing)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-04-09 21:37:36 -04:00
|
|
|
local buildable = minetest.registered_nodes[minetest.get_node(pointed_thing.under).name].buildable_to
|
|
|
|
--replace buildable
|
|
|
|
if buildable and minetest.get_node_group(minetest.get_node(vector.new(pointed_thing.under.x,pointed_thing.under.y-1,pointed_thing.under.z)).name, "soil") > 0 then
|
|
|
|
return(minetest.item_place(itemstack, placer, pointed_thing))
|
|
|
|
end
|
|
|
|
local buildable = minetest.registered_nodes[minetest.get_node(pointed_thing.above).name].buildable_to
|
|
|
|
if buildable and minetest.get_node_group(minetest.get_node(vector.new(pointed_thing.above.x,pointed_thing.above.y-1,pointed_thing.above.z)).name, "soil") > 0 then
|
|
|
|
return(minetest.item_place(itemstack, placer, pointed_thing))
|
|
|
|
end
|
|
|
|
--place sapling
|
2020-03-10 23:56:27 -07:00
|
|
|
local pos = pointed_thing.above
|
|
|
|
if minetest.get_node_group(minetest.get_node(vector.new(pos.x,pos.y-1,pos.z)).name, "soil") > 0 and minetest.get_node(pointed_thing.above).name == "air" then
|
|
|
|
minetest.set_node(pointed_thing.above, {name="main:sapling"})
|
2020-05-08 06:46:54 -04:00
|
|
|
minetest.sound_play("dirt",{pos=pointed_thing.above})
|
2020-03-10 23:56:27 -07:00
|
|
|
itemstack:take_item(1)
|
|
|
|
return(itemstack)
|
|
|
|
end
|
|
|
|
end,
|
2020-05-08 22:19:26 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
--growing abm for sapling
|
|
|
|
minetest.register_abm({
|
|
|
|
label = "Tree Grow",
|
|
|
|
nodenames = {"group:sapling"},
|
|
|
|
neighbors = {"group:soil"},
|
2020-05-09 07:39:53 -04:00
|
|
|
interval = 6,
|
2020-05-09 08:16:44 -04:00
|
|
|
chance = 250,
|
2020-05-08 22:19:26 -04:00
|
|
|
catch_up = true,
|
|
|
|
action = function(pos)
|
2020-03-10 23:56:27 -07:00
|
|
|
sapling_grow(pos)
|
|
|
|
end,
|
2020-02-22 11:49:17 -05:00
|
|
|
})
|