From c129cd8e28c46590cc4079fe0757508957e66b68 Mon Sep 17 00:00:00 2001 From: Kotolegokot Date: Fri, 16 Nov 2012 13:39:39 +0600 Subject: [PATCH] realtest.register_tree --- mods/trees/init.lua | 183 +++--------------- mods/trees/leavesgen.lua | 13 +- mods/trees/registration.lua | 144 ++++++++++++++ ...rees_ash_wood.png => trees_ash_planks.png} | Bin ..._aspen_wood.png => trees_aspen_planks.png} | Bin ..._birch_wood.png => trees_birch_planks.png} | Bin ...nut_wood.png => trees_chestnut_planks.png} | Bin ...rees__wood.png => trees_mapple_planks.png} | Bin mods/trees/textures/trees_mapple_wood.png | Bin 439 -> 0 bytes ...es_pine_wood.png => trees_pine_planks.png} | Bin ...uoia_wood.png => trees_sequoia_planks.png} | Bin 11 files changed, 173 insertions(+), 167 deletions(-) create mode 100644 mods/trees/registration.lua rename mods/trees/textures/{trees_ash_wood.png => trees_ash_planks.png} (100%) rename mods/trees/textures/{trees_aspen_wood.png => trees_aspen_planks.png} (100%) rename mods/trees/textures/{trees_birch_wood.png => trees_birch_planks.png} (100%) rename mods/trees/textures/{trees_chestnut_wood.png => trees_chestnut_planks.png} (100%) rename mods/trees/textures/{trees__wood.png => trees_mapple_planks.png} (100%) delete mode 100644 mods/trees/textures/trees_mapple_wood.png rename mods/trees/textures/{trees_pine_wood.png => trees_pine_planks.png} (100%) rename mods/trees/textures/{trees_sequoia_wood.png => trees_sequoia_planks.png} (100%) diff --git a/mods/trees/init.lua b/mods/trees/init.lua index e9c5d21..55ca55a 100644 --- a/mods/trees/init.lua +++ b/mods/trees/init.lua @@ -1,158 +1,32 @@ -dofile(minetest.get_modpath("trees").."/leavesgen.lua") - trees = {} -trees.grounds = { - "default:dirt", - "default:dirt_with_grass", -} +dofile(minetest.get_modpath("trees").."/leavesgen.lua") +dofile(minetest.get_modpath("trees").."/registration.lua") -trees.list = { - "ash", - "aspen", - "birch", - "chestnut", - "mapple", - "pine", -} - -trees.desc_list = { - "Ash", - "Aspen", - "Birch", - "Chestnut", - "Mapple", - "Pine", -} - -for i, tree in ipairs(trees.list) do - minetest.register_node("trees:"..tree.."_trunk", { - description = trees.desc_list[i].." Trunk", - tiles = {"trees_"..tree.."_trunk_top.png", "trees_"..tree.."_trunk_top.png", "trees_"..tree.."_trunk.png"}, - groups = {tree=1,snappy=1,choppy=2,flammable=2,dropping_node=1}, - sounds = default.node_sound_wood_defaults(), - drawtype = "nodebox", - paramtype = "light", - node_box = { - type = "fixed", - fixed = { - {-0.4,-0.5,-0.4,0.4,0.5,0.4}, - }, - }, - selection_box = { - type = "fixed", - fixed = { - {-0.4,-0.5,-0.4,0.4,0.5,0.4}, - }, - }, - }) - - minetest.register_node("trees:"..tree.."_leaves", { - description = trees.desc_list[i].." Leaves", - drawtype = "allfaces_optional", - visual_scale = 1.3, - tiles = {"trees_"..tree.."_leaves.png"}, - paramtype = "light", - groups = {snappy=3, leafdecay=3, flammable=2}, - drop = { - max_items = 1, - items = { - { - items = {'trees:'..tree..'_sapling'}, - rarity = 15, - }, - { - items = {'trees:'..tree..'_stick'}, - rarity = 2, - }, - { - items = {"trees:"..tree.."_leaves"}, - } - } - }, - sounds = default.node_sound_leaves_defaults(), - walkable = false, - climbable = true, - }) - - minetest.register_node("trees:"..tree.."_planks", { - description = trees.desc_list[i].." Planks", - tiles = {"trees_"..tree.."_planks.png"}, - groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3}, - sounds = default.node_sound_wood_defaults(), - }) - - minetest.register_craftitem("trees:"..tree.."_stick", { - description = trees.desc_list[i].." Stick", - inventory_image = "trees_"..tree.."_stick.png", - groups = {sticks=1}, - on_use = function(itemstack, user, pointed_thing) - if pointed_thing.type ~= "node" then - return - end - trees.make_tree(pointed_thing.above, 4, 12, TREES_GEN_PINE_LIST, "trees:"..tree.."_trunk", "trees:"..tree.."_leaves") - end, - }) - - minetest.register_node("trees:"..tree.."_sapling", { - description = trees.desc_list[i].." Sapling", - drawtype = "plantlike", - visual_scale = 1.0, - tiles = {"trees_"..tree.."_sapling.png"}, - inventory_image = "trees_"..tree.."_sapling.png", - wield_image = "trees_"..tree.."_sapling.png", - paramtype = "light", - walkable = false, - groups = {snappy=2,dig_immediate=3,flammable=2}, - sounds = default.node_sound_defaults(), - }) - - --[[minetest.register_abm({ - nodenames = {"trees:"..tree.."_sapling"}, - interval = 9.0, - chance = 1.0, - action = function(pos, node, active_object_count, active_object_count_wider) - posn = {x=pos.x, y=pos.y-1, z=pos.z} - minetest.env:set_node(pos,{name="air"}) - local s = minetest.env:get_node(posn).name - if s ~= "default:dirt" and s ~= "default:dirt_with_grass" then return end - --gen_ash(posn) - end, - })]] -end - -function trees.make_tree(pos, arlenght, height, genlist, trunk, leaves) - for i, tree in ipairs(trees.list) do - if minetest.env:find_node_near(pos, arlenght, "trees:"..tree.."_trunk") then +function trees.make_tree(pos, tree) + local tree = realtest.registered_trees[tree] + if not table.contains(tree.grounds, minetest.env:get_node({x=pos.x,y=pos.y-1,z=pos.z}).name) or + minetest.env:find_node_near(pos, tree.radius, "group:tree") then + return + end + local height = tree.height() + for i = 0,height do + if minetest.env:get_node({x=pos.x, y=pos.y+i, z=pos.z}).name ~= "air" then return 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 + minetest.env:add_node({x=pos.x, y=pos.y+i, z=pos.z}, {name=tree.name.."_trunk"}) end - for i = 1,#genlist do - local p = {x=pos.x+genlist[i][1], y=pos.y+height+genlist[i][2], z=pos.z+genlist[i][3]} + for i = 1,#tree.leaves do + local p = {x=pos.x+tree.leaves[i][1], y=pos.y+height+tree.leaves[i][2], z=pos.z+tree.leaves[i][3]} if minetest.env:get_node(p).name == "air" or minetest.env:get_node(p).name == "ignore" then - minetest.env:add_node(p, {name=leaves}) + minetest.env:add_node(p, {name=tree.name.."_leaves"}) end end end -function trees.get_tree_height(trunk) - local height = { - ["trees:ash_trunk"] = 4 + math.random(4), - ["trees:mapple_trunk"] = 7 + math.random(5), - ["trees:birch_trunk"] = 10 + math.random(4), - ["trees:aspen_trunk"] = 10 + math.random(4), - ["trees:chestnut_trunk"] = 9 + math.random(2), - ["trees:pine_trunk"] = 13 + math.random(4), - } - return height[trunk] -end - -local function generate(genlist, arlenght, trunk, leaves, grounds, minp, maxp, seed, chunks_per_volume, ore_per_chunk, height_min, height_max) +local function generate(tree, minp, maxp, seed, chunks_per_volume, ore_per_chunk, height_min, height_max) if maxp.y < height_min or minp.y > height_max then return end @@ -181,8 +55,8 @@ local function generate(genlist, arlenght, trunk, leaves, grounds, minp, maxp, s local z2 = z0+z1 local p2 = {x=x2, y=y2, z=z2} local p3 = {x=x2, y=y2+1, z=z2} - if table.contains(grounds, minetest.env:get_node(p2).name) and minetest.env:get_node(p3).name == "air" then - trees.make_tree(p3, arlenght, trees.get_tree_height(trunk), genlist, trunk, leaves) + if minetest.env:get_node(p3).name == "air" then + trees.make_tree(p3, tree) end end end @@ -194,22 +68,9 @@ end minetest.register_on_generated(function(minp, maxp, seed) local pr = PseudoRandom(seed) - if pr:next(1,3) == 1 then - generate(TREES_GEN_ASH_LIST, 5, "trees:ash_trunk","trees:ash_leaves", trees.grounds, minp, maxp, seed, 1/8/2, 1, -50, 100) - end - if pr:next(1,6) == 1 then - generate(TREES_GEN_MAPPLE_LIST, 5, "trees:mapple_trunk", "trees:mapple_leaves", trees.grounds, minp, maxp, seed, 1/8/2, 1, -50, 100) - end - if pr:next(1,6) == 1 then - generate(TREES_GEN_BIRCH_LIST, 5, "trees:birch_trunk", "trees:birch_leaves", trees.grounds, minp, maxp, seed, 1/8/2, 1, -50, 100) - end - if pr:next(1,6) == 1 then - generate(TREES_GEN_ASPEN_LIST, 5, "trees:aspen_trunk", "trees:aspen_leaves", trees.grounds, minp, maxp, seed, 1/8/2, 1, -50, 100) - end - if pr:next(1,6) == 1 then - generate(TREES_GEN_CHESTNUT_LIST, 10, "trees:chestnut_trunk", "trees:chestnut_leaves", trees.grounds, minp, maxp, seed, 1/8/2, 1, -50, 100) - end - if pr:next(1,6) == 1 then - generate(TREES_GEN_PINE_LIST, 6, "trees:pine_trunk", "trees:pine_leaves", trees.grounds, minp, maxp, seed, 1/8/2, 1, -50, 100) + for key, value in pairs(realtest.registered_trees) do + if pr:next(1, 10) == 1 then + generate(key, minp, maxp, seed, 1/8/2, 1, -50, 100) + end end end) diff --git a/mods/trees/leavesgen.lua b/mods/trees/leavesgen.lua index 0ed39df..a63ecbf 100644 --- a/mods/trees/leavesgen.lua +++ b/mods/trees/leavesgen.lua @@ -1,4 +1,5 @@ -TREES_GEN_ASH_LIST={ +trees.gen_lists={} +trees.gen_lists.ash={ {0,2,0}, {-1,2,0}, {1,2,0}, @@ -112,7 +113,7 @@ TREES_GEN_ASH_LIST={ {0,-3,2}, } -TREES_GEN_MAPPLE_LIST={ +trees.gen_lists.mapple={ {0,1,0}, {-1,1,0}, {1,1,0}, @@ -193,7 +194,7 @@ TREES_GEN_MAPPLE_LIST={ {1,-4,0}, } -TREES_GEN_BIRCH_LIST={ +trees.gen_lists.birch={ {1,1,0}, {0,1,1}, {-1,1,0}, @@ -453,7 +454,7 @@ TREES_GEN_BIRCH_LIST={ {1,-9,1}, } -TREES_GEN_ASPEN_LIST={ +trees.gen_lists.aspen={ {-1,1,0}, {1,1,0}, {0,1,-1}, @@ -602,7 +603,7 @@ TREES_GEN_ASPEN_LIST={ {0,-6,1}, } -TREES_GEN_CHESTNUT_LIST={ +trees.gen_lists.chestnut={ {0,1,0}, {-1,1,0}, {1,1,0}, @@ -1218,7 +1219,7 @@ TREES_GEN_CHESTNUT_LIST={ {1,-7,2}, } -TREES_GEN_PINE_LIST={ +trees.gen_lists.pine={ {-1,1,0}, {1,1,0}, {0,1,-1}, diff --git a/mods/trees/registration.lua b/mods/trees/registration.lua new file mode 100644 index 0000000..846bc7a --- /dev/null +++ b/mods/trees/registration.lua @@ -0,0 +1,144 @@ +realtest.registered_trees = {} +function realtest.register_tree(name, TreeDef) + local tree = { + name = name, + description = TreeDef.description or "", + grounds = TreeDef.grounds or {"default:dirt","default:dirt_with_grass"}, + leaves = TreeDef.leaves or {}, + height = TreeDef.height or function() return 10 end, + radius = TreeDef.radius or 5, + textures = TreeDef.textures or {{},"","","",""}, + } + realtest.registered_trees[name] = tree + + minetest.register_node(tree.name.."_trunk", { + description = tree.description.." Trunk", + tiles = tree.textures[1], + groups = {tree=1,snappy=1,choppy=2,flammable=2,dropping_node=1}, + sounds = default.node_sound_wood_defaults(), + drawtype = "nodebox", + paramtype = "light", + node_box = { + type = "fixed", + fixed = { + {-0.4,-0.5,-0.4,0.4,0.5,0.4}, + }, + }, + selection_box = { + type = "fixed", + fixed = { + {-0.4,-0.5,-0.4,0.4,0.5,0.4}, + }, + }, + }) + + minetest.register_node(tree.name.."_planks", { + description = tree.description.." Planks", + tiles = {tree.textures[3]}, + groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3}, + sounds = default.node_sound_wood_defaults(), + }) + + minetest.register_craftitem(tree.name.."_stick", { + description = tree.description.." Stick", + inventory_image = tree.textures[4], + groups = {stick=1}, + }) + + minetest.register_node(tree.name.."_sapling", { + description = tree.description.." Sapling", + drawtype = "plantlike", + visual_scale = 1.0, + tiles = {tree.textures[5]}, + inventory_image = tree.textures[5], + wield_image = tree.textures[5], + paramtype = "light", + walkable = false, + groups = {snappy=2,dig_immediate=3,flammable=2}, + sounds = default.node_sound_defaults(), + }) + + minetest.register_node(tree.name.."_leaves", { + description = tree.description.." Leaves", + drawtype = "allfaces_optional", + visual_scale = 1.3, + tiles = {tree.textures[2]}, + paramtype = "light", + groups = {snappy=3, leafdecay=3, flammable=2}, + drop = { + max_items = 1, + items = { + { + items = {tree.name..'_sapling'}, + rarity = 15, + }, + { + items = {tree.name..'_stick'}, + rarity = 2, + }, + { + items = {}, + }, + } + }, + sounds = default.node_sound_leaves_defaults(), + walkable = false, + climbable = true, + }) +end + +realtest.register_tree("trees:ash", { + description = "Ash", + leaves = trees.gen_lists.ash, + height = function() + return 4 + math.random(4) + end, + textures = {{"trees_ash_trunk_top.png", "trees_ash_trunk_top.png", "trees_ash_trunk.png"},"trees_ash_leaves.png", + "trees_ash_planks.png", "trees_ash_stick.png", "trees_ash_sapling.png"} +}) +realtest.register_tree("trees:aspen", { + description = "Aspen", + leaves = trees.gen_lists.aspen, + height = function() + return 10 + math.random(4) + end, + textures = {{"trees_aspen_trunk_top.png", "trees_aspen_trunk_top.png", "trees_aspen_trunk.png"},"trees_aspen_leaves.png", + "trees_aspen_planks.png", "trees_aspen_stick.png", "trees_aspen_sapling.png"} +}) +realtest.register_tree("trees:birch", { + description = "Birch", + leaves = trees.gen_lists.birch, + height = function() + return 10 + math.random(4) + end, + textures = {{"trees_birch_trunk_top.png", "trees_birch_trunk_top.png", "trees_birch_trunk.png"},"trees_birch_leaves.png", + "trees_birch_planks.png", "trees_birch_stick.png", "trees_birch_sapling.png"} +}) +realtest.register_tree("trees:mapple", { + description = "Mapple", + leaves = trees.gen_lists.mapple, + height = function() + return 7 + math.random(5) + end, + textures = {{"trees_mapple_trunk_top.png", "trees_mapple_trunk_top.png", "trees_mapple_trunk.png"},"trees_mapple_leaves.png", + "trees_mapple_planks.png", "trees_mapple_stick.png", "trees_mapple_sapling.png"} +}) +realtest.register_tree("trees:chestnut", { + description = "Chestnut", + leaves = trees.gen_lists.chestnut, + height = function() + return 9 + math.random(2) + end, + radius = 10, + textures = {{"trees_chestnut_trunk_top.png", "trees_chestnut_trunk_top.png", "trees_chestnut_trunk.png"},"trees_chestnut_leaves.png", + "trees_chestnut_planks.png", "trees_chestnut_stick.png", "trees_chestnut_sapling.png"} +}) +realtest.register_tree("trees:pine", { + description = "Pine", + leaves = trees.gen_lists.pine, + height = function() + return 13 + math.random(4) + end, + textures = {{"trees_pine_trunk_top.png", "trees_pine_trunk_top.png", "trees_pine_trunk.png"},"trees_pine_leaves.png", + "trees_pine_planks.png", "trees_pine_stick.png", "trees_pine_sapling.png"} +}) diff --git a/mods/trees/textures/trees_ash_wood.png b/mods/trees/textures/trees_ash_planks.png similarity index 100% rename from mods/trees/textures/trees_ash_wood.png rename to mods/trees/textures/trees_ash_planks.png diff --git a/mods/trees/textures/trees_aspen_wood.png b/mods/trees/textures/trees_aspen_planks.png similarity index 100% rename from mods/trees/textures/trees_aspen_wood.png rename to mods/trees/textures/trees_aspen_planks.png diff --git a/mods/trees/textures/trees_birch_wood.png b/mods/trees/textures/trees_birch_planks.png similarity index 100% rename from mods/trees/textures/trees_birch_wood.png rename to mods/trees/textures/trees_birch_planks.png diff --git a/mods/trees/textures/trees_chestnut_wood.png b/mods/trees/textures/trees_chestnut_planks.png similarity index 100% rename from mods/trees/textures/trees_chestnut_wood.png rename to mods/trees/textures/trees_chestnut_planks.png diff --git a/mods/trees/textures/trees__wood.png b/mods/trees/textures/trees_mapple_planks.png similarity index 100% rename from mods/trees/textures/trees__wood.png rename to mods/trees/textures/trees_mapple_planks.png diff --git a/mods/trees/textures/trees_mapple_wood.png b/mods/trees/textures/trees_mapple_wood.png deleted file mode 100644 index ddca83fee4e275e7ff3c59780c29625f4ce7f789..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 439 zcmV;o0Z9IdP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01m?d01m?e$8V@)00007bV*G`2iyt` z4mB3dM&ht83~dFRE^{KQsjM;dpxL8{Dd5ma8gzQpF72;HLY=UglUw5-q#2j?kzIjkaU0ir?=N zyNzCPP4)bt0bdd0?c;lBtLR3g9(|ChVj|j(HG9FHB5$yYFxjbW)yXC_beZeEVZWGT zT@bsCKDz*Zk@3otw7%A`a$smH%!x82_6$U$am#}B4QN;wtXmjLRm`f$sIAa7-B4A` hhNrYW(fn^8egL$9y!a%vsyzSz002ovPDHLkV1j0Kx{3e* diff --git a/mods/trees/textures/trees_pine_wood.png b/mods/trees/textures/trees_pine_planks.png similarity index 100% rename from mods/trees/textures/trees_pine_wood.png rename to mods/trees/textures/trees_pine_planks.png diff --git a/mods/trees/textures/trees_sequoia_wood.png b/mods/trees/textures/trees_sequoia_planks.png similarity index 100% rename from mods/trees/textures/trees_sequoia_wood.png rename to mods/trees/textures/trees_sequoia_planks.png