Place saplings automatically

instead of growing the tree
This commit is contained in:
James Stevenson 2016-01-19 02:53:03 -05:00
parent 04f5fa75e4
commit 1a7b5932fa
2 changed files with 17 additions and 34 deletions

View File

@ -378,9 +378,13 @@ minetest.register_on_placenode(function(pos, newnode, placer, oldnode)
if newnode.name == "default:sapling" or
newnode.name == "default:junglesapling" then
if pos.y < 14400 then
if not minetest.find_node_near(pos, 8, {"group:water"}) then
minetest.set_node(pos, oldnode)
minetest.add_item(pos, newnode) --{name="default:sapling"})
local nu = minetest.get_node({x = pos.x, y = pos.y - 1, z = pos.z}).name
if nu == "kalite:dirt_tree" or
nu == "kalite:dirt_jungletree" then
minetest.set_node(pos, newnode)
elseif not minetest.find_node_near(pos, 8, {"group:water"}) then
minetest.set_node(pos, oldnode) -- Return old node (probably air)
minetest.add_item(pos, newnode) -- Drop item onto ground
end
end
end

View File

@ -27,26 +27,15 @@ minetest.register_node("kalite:dirt_tree", {
minetest.register_abm({
nodenames = {"kalite:dirt_tree"},
interval = 120,
chance = 10,
interval = 30,
chance = 3,
action = function(pos, node)
remove_igniters(pos)
local ppos = {x = pos.x, y = pos.y + 1, z = pos.z}
local na = minetest.get_node(ppos).name
if na ~= "default:tree" then
local vm = minetest.get_voxel_manip()
local minp, maxp = vm:read_from_map(
{x = pos.x - 16, y = pos.y + 1, z = pos.z - 16},
{x = pos.x + 16, y = pos.y + 16, z = pos.z + 16})
local a = VoxelArea:new{MinEdge = minp, MaxEdge = maxp}
local data = vm:get_data()
default.grow_tree(data, a, ppos, math.random(1, 4) == 1,
math.random(1, 100000))
vm:set_data(data)
vm:write_to_map(data)
vm:update_map()
minetest.log("action", "A sapling grows into a tree at " ..
minetest.pos_to_string(pos))
if na ~= "default:tree" and
na ~= "default:sapling" then
return minetest.set_node(ppos, {name = "default:sapling"})
end
end
})
@ -69,25 +58,15 @@ minetest.register_node("kalite:dirt_jungletree", {
minetest.register_abm({
nodenames = {"kalite:dirt_jungletree"},
interval = 120,
chance = 10,
interval = 30,
chance = 3,
action = function(pos, node)
remove_igniters(pos)
local ppos = {x = pos.x, y = pos.y + 1, z = pos.z}
local na = minetest.get_node(ppos).name
if na ~= "default:jungletree" then
local vm = minetest.get_voxel_manip()
local minp, maxp = vm:read_from_map(
{x = pos.x - 16, y = pos.y + 1, z = pos.z - 16},
{x = pos.x + 16, y = pos.y + 16, z = pos.z + 16})
local a = VoxelArea:new{MinEdge = minp, MaxEdge = maxp}
local data = vm:get_data()
default.grow_jungletree(data, a, pos, math.random(1, 100000))
vm:set_data(data)
vm:write_to_map(data)
vm:update_map()
minetest.log("action", "A jungle sapling grows into a tree at " ..
minetest.pos_to_string(pos))
if na ~= "default:jungletree"
and na ~= "default:junglesapling" then
return minetest.set_node(ppos, {name = "default:junglesapling"})
end
end
})