From 23e1d8e0ca7cfc44fed877d733bcfebe7fb32694 Mon Sep 17 00:00:00 2001 From: RealBadAngel Date: Wed, 2 Jan 2013 04:49:03 +0100 Subject: [PATCH] Make Rubber tree using L-Systems --- technic/technic/rubber.lua | 123 +++++------------- .../textures/technic_rubber_leaves.png | Bin 0 -> 444 bytes 2 files changed, 29 insertions(+), 94 deletions(-) create mode 100644 technic/technic/textures/technic_rubber_leaves.png diff --git a/technic/technic/rubber.lua b/technic/technic/rubber.lua index 311f3af..0e530ff 100644 --- a/technic/technic/rubber.lua +++ b/technic/technic/rubber.lua @@ -51,7 +51,7 @@ minetest.register_abm({ minetest.register_node("technic:rubber_leaves", { drawtype = "allfaces_optional", visual_scale = 1.3, - tiles = {"default_leaves.png"}, + tiles = {"technic_rubber_leaves.png"}, paramtype = "light", groups = {snappy=3, leafdecay=3, flammable=2, not_in_creative_inventory=1}, drop = { @@ -71,7 +71,20 @@ minetest.register_abm({ interval = 60, chance = 20, action = function(pos, node) - generate_tree(pos, "technic:rubber_tree_full", "technic:rubber_leaves", {"default:dirt", "default:dirt_with_grass"}) + rubber_tree={ + axiom="FFFFA", + rules_a="[&FFBFA]////[&BFFFA]////[&FBFFA]", + rules_b="[&FFA]////[&FFA]////[&FFA]", + trunk="technic:rubber_tree_full", + leaves="technic:rubber_leaves", + angle=35, + iterations=3, + random_level=1, + thin_trunks=false; + fruit_tree=false, + fruit="" + } + minetest.env:spawn_tree(pos,rubber_tree) end }) @@ -82,7 +95,20 @@ minetest.register_on_generated(function(minp, maxp, blockseed) local tmp = {x=(maxp.x-minp.x)/2+minp.x, y=(maxp.y-minp.y)/2+minp.y, z=(maxp.z-minp.z)/2+minp.z} local pos = minetest.env:find_node_near(tmp, maxp.x-minp.x, {"default:dirt_with_grass"}) if pos ~= nil then - generate_tree({x=pos.x, y=pos.y+1, z=pos.z}, "technic:rubber_tree_full", "technic:rubber_leaves", {"default:dirt", "default:dirt_with_grass"}) + rubber_tree={ + axiom="FFFFA", + rules_a="[&FFBFA]////[&BFFFA]////[&FBFFA]", + rules_b="[&FFA]////[&FFA]////[&FFA]", + trunk="technic:rubber_tree_full", + leaves="technic:rubber_leaves", + angle=35, + iterations=3, + random_level=1, + thin_trunks=false; + fruit_tree=false, + fruit="" + } + minetest.env:spawn_tree({x=pos.x, y=pos.y+1, z=pos.z},rubber_tree) end end) @@ -93,94 +119,3 @@ minetest.register_craft({ recipe = "technic:rubber_sapling", burntime = 10 }) - -function generate_tree(pos, trunk, leaves, underground, replacements) - pos.y = pos.y-1 - local nodename = minetest.env:get_node(pos).name - local ret = true - for _,name in ipairs(underground) do - if nodename == name then - ret = false - break - end - end - pos.y = pos.y+1 - if ret or minetest.env:get_node_light(pos) < 8 then - return - end - - node = {name = ""} - for dy=1,4 do - pos.y = pos.y+dy - if minetest.env:get_node(pos).name ~= "air" then - return - end - pos.y = pos.y-dy - end - node.name = trunk - for dy=0,4 do - pos.y = pos.y+dy - minetest.env:set_node(pos, node) - pos.y = pos.y-dy - end - - if not replacements then - replacements = {} - end - - node.name = leaves - pos.y = pos.y+3 - for dx=-2,2 do - for dz=-2,2 do - for dy=0,3 do - pos.x = pos.x+dx - pos.y = pos.y+dy - pos.z = pos.z+dz - - if dx == 0 and dz == 0 and dy==3 then - if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then - minetest.env:set_node(pos, node) - for name,rarity in pairs(replacements) do - if math.random(1, rarity) == 1 then - minetest.env:set_node(pos, {name=name}) - end - end - end - elseif dx == 0 and dz == 0 and dy==4 then - if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then - minetest.env:set_node(pos, node) - for name,rarity in pairs(replacements) do - if math.random(1, rarity) == 1 then - minetest.env:set_node(pos, {name=name}) - end - end - end - elseif math.abs(dx) ~= 2 and math.abs(dz) ~= 2 then - if minetest.env:get_node(pos).name == "air" then - minetest.env:set_node(pos, node) - for name,rarity in pairs(replacements) do - if math.random(1, rarity) == 1 then - minetest.env:set_node(pos, {name=name}) - end - end - end - else - if math.abs(dx) ~= 2 or math.abs(dz) ~= 2 then - if minetest.env:get_node(pos).name == "air" and math.random(1, 5) <= 4 then - minetest.env:set_node(pos, node) - for name,rarity in pairs(replacements) do - if math.random(1, rarity) == 1 then - minetest.env:set_node(pos, {name=name}) - end - end - end - end - end - - pos.x = pos.x-dx - pos.y = pos.y-dy - pos.z = pos.z-dz - end - end - end -end diff --git a/technic/technic/textures/technic_rubber_leaves.png b/technic/technic/textures/technic_rubber_leaves.png new file mode 100644 index 0000000000000000000000000000000000000000..ae013e0a06f426ff50d41f6dcf8e1734708bc62d GIT binary patch literal 444 zcmV;t0YmPx#32;bRa{vGf6951U69E94oEQKA00(qQO+^RY0RjUL1L?}QMgRZ-PDw;TR5;6Z zQ?YS`Fc93+Xg(nP0;qv91QCG}YM=nupaQ-I5(giF%b)}g1rQQo#^=D?`GEH(n%U8v zZg)=v0A*V*SkSb= zY4Lv2v>l4Y7tAZT$S#lQB{6AuJSn8eG9nilKHlD`Y-<(+m1`n*Lzu0-s mJ?szmcCY_~?uW!{Joy0{3H8Cd2MP!P0000