Fix indentation, use log() instead of print() and use get_item_group() in tree growing ABM

This commit is contained in:
PilzAdam 2013-11-17 11:46:41 +01:00
parent 4c0c7ae146
commit 5d0795a1a7
1 changed files with 40 additions and 32 deletions

View File

@ -132,41 +132,49 @@ minetest.register_on_punchnode(on_punchnode)
-- --
minetest.register_abm({ minetest.register_abm({
nodenames = {"default:sapling"}, nodenames = {"default:sapling"},
interval = 10, interval = 10,
chance = 50, chance = 50,
action = function(pos, node) action = function(pos, node)
local is_soil = minetest.registered_nodes[minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name].groups.soil local nu = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name
if is_soil == nil or is_soil == 0 then return end local is_soil = minetest.get_item_group(nu, "soil")
print("A sapling grows into a tree at "..minetest.pos_to_string(pos)) if is_soil == 0 then
local vm = minetest.get_voxel_manip() return
local minp, maxp = vm:read_from_map({x=pos.x-16, y=pos.y, z=pos.z-16}, {x=pos.x+16, y=pos.y+16, z=pos.z+16}) end
local a = VoxelArea:new{MinEdge=minp, MaxEdge=maxp}
local data = vm:get_data() minetest.log("action", "A sapling grows into a tree at "..minetest.pos_to_string(pos))
default.grow_tree(data, a, pos, math.random(1, 4) == 1, math.random(1,100000)) local vm = minetest.get_voxel_manip()
vm:set_data(data) local minp, maxp = vm:read_from_map({x=pos.x-16, y=pos.y, z=pos.z-16}, {x=pos.x+16, y=pos.y+16, z=pos.z+16})
vm:write_to_map(data) local a = VoxelArea:new{MinEdge=minp, MaxEdge=maxp}
vm:update_map() local data = vm:get_data()
end default.grow_tree(data, a, pos, math.random(1, 4) == 1, math.random(1,100000))
vm:set_data(data)
vm:write_to_map(data)
vm:update_map()
end
}) })
minetest.register_abm({ minetest.register_abm({
nodenames = {"default:junglesapling"}, nodenames = {"default:junglesapling"},
interval = 10, interval = 10,
chance = 50, chance = 50,
action = function(pos, node) action = function(pos, node)
local is_soil = minetest.registered_nodes[minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name].groups.soil local nu = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z}).name
if is_soil == nil or is_soil == 0 then return end local is_soil = minetest.get_item_group(nu, "soil")
print("A jungle sapling grows into a tree at "..minetest.pos_to_string(pos)) if is_soil == 0 then
local vm = minetest.get_voxel_manip() return
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}) end
local a = VoxelArea:new{MinEdge=minp, MaxEdge=maxp}
local data = vm:get_data() minetest.log("action", "A jungle sapling grows into a tree at "..minetest.pos_to_string(pos))
default.grow_jungletree(data, a, pos, math.random(1,100000)) local vm = minetest.get_voxel_manip()
vm:set_data(data) 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})
vm:write_to_map(data) local a = VoxelArea:new{MinEdge=minp, MaxEdge=maxp}
vm:update_map() local data = vm:get_data()
end default.grow_jungletree(data, a, pos, math.random(1,100000))
vm:set_data(data)
vm:write_to_map(data)
vm:update_map()
end
}) })
-- --