Cleanup 2

This commit is contained in:
Kotolegokot 2012-11-15 17:26:45 +06:00
parent f472d24b13
commit 450b266bb1
2 changed files with 138 additions and 160 deletions

View File

@ -1,4 +1,4 @@
dofile(minetest.get_modpath("trees").."/treegen.lua") dofile(minetest.get_modpath("trees").."/leavesgen.lua")
trees = {} trees = {}
@ -27,10 +27,9 @@ trees.desc_list = {
for i, tree in ipairs(trees.list) do for i, tree in ipairs(trees.list) do
minetest.register_node("trees:"..tree.."_trunk", { minetest.register_node("trees:"..tree.."_trunk", {
description = "Log of "..trees.desc_list[i], description = trees.desc_list[i].." Trunk",
tiles = {"trees_"..tree.."_trunk_top.png", "trees_"..tree.."_trunk_top.png", "trees_"..tree.."_trunk.png"}, tiles = {"trees_"..tree.."_trunk_top.png", "trees_"..tree.."_trunk_top.png", "trees_"..tree.."_trunk.png"},
is_ground_content = true, groups = {tree=1,snappy=1,choppy=2,flammable=2,dropping_node=1},
groups = {tree=1,snappy=1,choppy=2,flammable=2},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
@ -49,7 +48,7 @@ for i, tree in ipairs(trees.list) do
}) })
minetest.register_node("trees:"..tree.."_leaves", { minetest.register_node("trees:"..tree.."_leaves", {
description = "Leaves of "..trees.desc_list[i], description = trees.desc_list[i].." Leaves",
drawtype = "allfaces_optional", drawtype = "allfaces_optional",
visual_scale = 1.3, visual_scale = 1.3,
tiles = {"trees_"..tree.."_leaves.png"}, tiles = {"trees_"..tree.."_leaves.png"},
@ -76,29 +75,27 @@ for i, tree in ipairs(trees.list) do
climbable = true, climbable = true,
}) })
minetest.register_node("trees:"..tree.."_wood", { minetest.register_node("trees:"..tree.."_planks", {
description = "Wooden Planks of "..trees.desc_list[i], description = trees.desc_list[i].." Planks",
tiles = {"trees_"..tree.."_wood.png"}, tiles = {"trees_"..tree.."_planks.png"},
is_ground_content = true,
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3}, groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
minetest.register_craftitem("trees:"..tree.."_stick", { minetest.register_craftitem("trees:"..tree.."_stick", {
description = "Stick of "..trees.desc_list[i], description = trees.desc_list[i].." Stick",
inventory_image = "trees_"..tree.."_stick.png", inventory_image = "trees_"..tree.."_stick.png",
groups = {sticks=3}, groups = {sticks=1},
--[[on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then
return return
end end
minetest.env:set_node(pointed_thing.above,{name="trees:pine_trunk"}) trees.make_tree(pointed_thing.above, 4, 12, TREES_GEN_PINE_LIST, "trees:"..tree.."_trunk", "trees:"..tree.."_leaves")
gen_tree(pointed_thing.above, 4, 12, TREES_GEN_PINE_LIST, "trees:pine_trunk", "trees:pine_leaves") end,
end,]]
}) })
minetest.register_node("trees:"..tree.."_sapling", { minetest.register_node("trees:"..tree.."_sapling", {
description = "Sapling of "..trees.desc_list[i], description = trees.desc_list[i].." Sapling",
drawtype = "plantlike", drawtype = "plantlike",
visual_scale = 1.0, visual_scale = 1.0,
tiles = {"trees_"..tree.."_sapling.png"}, tiles = {"trees_"..tree.."_sapling.png"},
@ -111,7 +108,7 @@ for i, tree in ipairs(trees.list) do
}) })
--[[minetest.register_abm({ --[[minetest.register_abm({
nodenames = {"trees:"..TREES_LIST[i].."_sapling"}, nodenames = {"trees:"..tree.."_sapling"},
interval = 9.0, interval = 9.0,
chance = 1.0, chance = 1.0,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
@ -122,51 +119,37 @@ for i, tree in ipairs(trees.list) do
--gen_ash(posn) --gen_ash(posn)
end, end,
})]] })]]
end
minetest.register_abm({ function trees.make_tree(pos, arlenght, height, genlist, trunk, leaves)
nodenames = {"trees:"..tree.."_trunk"}, for i, tree in ipairs(trees.list) do
interval = 1.0, if minetest.env:find_node_near(pos, arlenght, "trees:"..tree.."_trunk") then
chance = 1.0,
action = function(pos, node, active_object_count, active_object_count_wider)
if table.contains(trees.grounds, minetest.env:get_node({x = pos.x, y = pos.y-1, z = pos.z}).name) then return end
for x = -1, 1 do
for z = -1, 1 do
local posn={x = pos.x+x, y = pos.y-1, z = pos.z+z}
if minetest.env:get_node(posn).name == "trees:"..tree.."_trunk" then
return return
end end
end end
for i = 0,height do
if minetest.env:get_node({x=pos.x, y=pos.y+i, z=pos.z}).name == "air" then
minetest.env:add_node({x=pos.x, y=pos.y+i, z=pos.z}, {name=trunk})
end end
minetest.env:add_item(pos, "trees:"..tree.."_trunk")
minetest.env:add_node(pos, {name="air"})
end,
})
end end
function set_node_instead_air(ipos, i, j, k, block)
local pos = {x=ipos.x+i,y=ipos.y+j,z=ipos.z+k}
if minetest.env:get_node(pos).name == "air" then minetest.env:set_node(pos, block) end
end
function gen_tree(ipos, arlenght, height, genlist, trunk, leaves)
local pos = ipos
if minetest.env:find_node_near(pos, arlenght, trunk) then return end
for i=1,height do
set_node_instead_air({x=pos.x, y=pos.y+i, z=pos.z},0,0,0,{name=trunk})
end
local loc_leaves={name=leaves}
for i = 1,#genlist do for i = 1,#genlist do
set_node_instead_air(pos, genlist[i][1], height+genlist[i][2], genlist[i][3], loc_leaves) local p = {x=pos.x+genlist[i][1], y=pos.y+height+genlist[i][2], z=pos.z+genlist[i][3]}
if minetest.env:get_node(p).name == "air" then
minetest.env:add_node(p, {name=leaves})
end
end end
end end
local get_height = function(tree) function trees.get_tree_height(trunk)
if tree=="trees:ash_trunk" then return 4+math.random(4) end local height = {
if tree=="trees:mapple_trunk" then return 7+math.random(5) end ["trees:ash_trunk"] = 4 + math.random(4),
if tree=="trees:birch_trunk" then return 10+math.random(4) end ["trees:mapple_trunk"] = 7 + math.random(5),
if tree=="trees:aspen_trunk" then return 10+math.random(4) end ["trees:birch_trunk"] = 10 + math.random(4),
if tree=="trees:chestnut_trunk" then return 9+math.random(2) end ["trees:aspen_trunk"] = 10 + math.random(4),
if tree=="trees:pine_trunk" then return 13+math.random(4) end ["trees:chestnut_trunk"] = 9 + math.random(2),
["trees:pine_trunk"] = 13 + math.random(4),
}
return height[trunk]
end end
local function generate(genlist, arlenght, trunk, leaves, wherein, minp, maxp, seed, chunks_per_volume, ore_per_chunk, height_min, height_max) local function generate(genlist, arlenght, trunk, leaves, wherein, minp, maxp, seed, chunks_per_volume, ore_per_chunk, height_min, height_max)
@ -199,7 +182,7 @@ local function generate(genlist, arlenght, trunk, leaves, wherein, minp, maxp, s
local p2 = {x=x2, y=y2, z=z2} local p2 = {x=x2, y=y2, z=z2}
local p3 = {x=x2, y=y2+1, z=z2} local p3 = {x=x2, y=y2+1, z=z2}
if (minetest.env:get_node(p2).name == wherein) and (minetest.env:get_node(p3).name == "air") then if (minetest.env:get_node(p2).name == wherein) and (minetest.env:get_node(p3).name == "air") then
gen_tree(p2, arlenght, get_height(trunk), genlist, trunk, leaves) trees.make_tree(p2, arlenght, trees.get_tree_height(trunk), genlist, trunk, leaves)
end end
end end
end end
@ -209,29 +192,24 @@ local function generate(genlist, arlenght, trunk, leaves, wherein, minp, maxp, s
end end
end end
minetest.register_on_generated( minetest.register_on_generated(function(minp, maxp, seed)
function(minp, maxp, seed)
local pr = PseudoRandom(seed) local pr = PseudoRandom(seed)
minetest.after(0,
function()
if pr:next(1,3) == 1 then if pr:next(1,3) == 1 then
generate(TREES_GEN_ASH_LIST, 5, "trees:ash_trunk","trees:ash_leaves", "default:dirt_with_grass", minp, maxp, seed, 1/8/2, 1, -1000, 10000) generate(TREES_GEN_ASH_LIST, 5, "trees:ash_trunk","trees:ash_leaves", "default:dirt_with_grass", minp, maxp, seed, 1/8/2, 1, -50, 100)
end end
if pr:next(1,6) == 1 then if pr:next(1,6) == 1 then
generate(TREES_GEN_MAPPLE_LIST, 5,"trees:mapple_trunk", "trees:mapple_leaves", "default:dirt_with_grass", minp, maxp, seed, 1/8/2, 1, -1000, 10000) generate(TREES_GEN_MAPPLE_LIST, 5,"trees:mapple_trunk", "trees:mapple_leaves", "default:dirt_with_grass", minp, maxp, seed, 1/8/2, 1, -50, 100)
end end
if pr:next(1,6) == 1 then if pr:next(1,6) == 1 then
generate(TREES_GEN_BIRCH_LIST, 5, "trees:birch_trunk", "trees:birch_leaves", "default:dirt_with_grass", minp, maxp, seed, 1/8/2, 1, -1000, 10000) generate(TREES_GEN_BIRCH_LIST, 5, "trees:birch_trunk", "trees:birch_leaves", "default:dirt_with_grass", minp, maxp, seed, 1/8/2, 1, -50, 100)
end end
if pr:next(1,6) == 1 then if pr:next(1,6) == 1 then
generate(TREES_GEN_ASPEN_LIST, 5, "trees:aspen_trunk", "trees:aspen_leaves", "default:dirt_with_grass", minp, maxp, seed, 1/8/2, 1, -1000, 10000) generate(TREES_GEN_ASPEN_LIST, 5, "trees:aspen_trunk", "trees:aspen_leaves", "default:dirt_with_grass", minp, maxp, seed, 1/8/2, 1, -50, 100)
end end
if pr:next(1,6) == 1 then if pr:next(1,6) == 1 then
generate(TREES_GEN_CHESTNUT_LIST, 10, "trees:chestnut_trunk", "trees:chestnut_leaves", "default:dirt_with_grass", minp, maxp, seed, 1/8/2, 1, -1000, 10000) generate(TREES_GEN_CHESTNUT_LIST, 10, "trees:chestnut_trunk", "trees:chestnut_leaves", "default:dirt_with_grass", minp, maxp, seed, 1/8/2, 1, -50, 100)
end end
if pr:next(1,6) == 1 then if pr:next(1,6) == 1 then
generate(TREES_GEN_PINE_LIST, 6, "trees:pine_trunk", "trees:pine_leaves", "default:dirt_with_grass", minp, maxp, seed, 1/8/2, 1, -1000, 10000) generate(TREES_GEN_PINE_LIST, 6, "trees:pine_trunk", "trees:pine_leaves", "default:dirt_with_grass", minp, maxp, seed, 1/8/2, 1, -50, 100)
end end
end) end)
end)