2016-08-20 21:19:10 +02:00
|
|
|
local modname = minetest.get_current_modname()
|
2016-08-21 15:27:18 +02:00
|
|
|
local thismod = _G[modname]
|
2016-08-20 21:19:10 +02:00
|
|
|
|
|
|
|
-- From BFD:
|
|
|
|
|
2016-08-21 00:33:37 +02:00
|
|
|
minetest.register_node(modname .. ':mg_cherry_sapling', {
|
2016-08-20 21:19:10 +02:00
|
|
|
description = "Impossible to get node.",
|
|
|
|
drawtype = 'airlike',
|
|
|
|
paramtype = 'light',
|
|
|
|
tiles = {'xfences_space.png'},
|
|
|
|
groups = {not_in_creative_inventory=1},
|
|
|
|
})
|
|
|
|
|
2016-08-21 00:33:37 +02:00
|
|
|
local c_mg_cherry_sapling = minetest.get_content_id(modname .. ':mg_cherry_sapling')
|
2016-08-20 21:19:10 +02:00
|
|
|
|
|
|
|
minetest.register_on_generated(function(minp, maxp, seed)
|
|
|
|
local timer = os.clock()
|
|
|
|
local vm, emin, emax = minetest.get_mapgen_object('voxelmanip')
|
|
|
|
local data = vm:get_data()
|
|
|
|
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
|
|
|
local trees_grown = 0
|
|
|
|
for z=minp.z, maxp.z, 1 do
|
|
|
|
for y=minp.y, maxp.y, 1 do
|
|
|
|
for x=minp.x, maxp.x, 1 do
|
|
|
|
local p_pos = area:index(x,y,z)
|
|
|
|
local content_id = data[p_pos]
|
|
|
|
if content_id == c_mg_cherry_sapling then
|
2016-08-21 15:27:18 +02:00
|
|
|
minetest.after(1, thismod.grow_cherry_tree,
|
2016-08-20 21:19:10 +02:00
|
|
|
{x=x, y=y, z=z},
|
|
|
|
false,
|
|
|
|
modname .. ':cherry_tree',
|
|
|
|
modname .. ':cherry_blossom_leaves')
|
|
|
|
trees_grown = trees_grown + 1
|
|
|
|
else
|
|
|
|
-- nope
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local geninfo = string.format(" trees grown after: %.2fs", os.clock() - timer)
|
|
|
|
minetest.log('action', trees_grown..geninfo)
|
|
|
|
end)
|
|
|
|
|
2016-08-21 15:27:18 +02:00
|
|
|
function thismod.grow_cherry_tree(pos, is_apple_tree, trunk_node, leaves_node)
|
2016-08-20 21:19:10 +02:00
|
|
|
--[[
|
|
|
|
NOTE: Tree-placing code is currently duplicated in the engine
|
|
|
|
and in games that have saplings; both are deprecated but not
|
|
|
|
replaced yet
|
|
|
|
--]]
|
|
|
|
|
|
|
|
local x, y, z = pos.x, pos.y, pos.z
|
|
|
|
local height = random(4, 5)
|
|
|
|
local c_tree = minetest.get_content_id(trunk_node)
|
|
|
|
local c_leaves = minetest.get_content_id(leaves_node)
|
|
|
|
|
|
|
|
local vm = minetest.get_voxel_manip()
|
|
|
|
local minp, maxp = vm:read_from_map(
|
|
|
|
{x = pos.x - 2, y = pos.y, z = pos.z - 2},
|
|
|
|
{x = pos.x + 2, y = pos.y + height + 1, z = pos.z + 2}
|
|
|
|
)
|
|
|
|
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
|
|
|
|
local data = vm:get_data()
|
|
|
|
|
2016-08-21 15:27:18 +02:00
|
|
|
default.add_trunk_and_leaves(data, a, pos, c_tree, c_leaves, height, 2, 8, is_apple_tree)
|
2016-08-20 21:19:10 +02:00
|
|
|
|
|
|
|
vm:set_data(data)
|
|
|
|
vm:write_to_map()
|
|
|
|
vm:update_map()
|
|
|
|
end
|