summaryrefslogtreecommitdiff
path: root/rubber.lua
diff options
context:
space:
mode:
Diffstat (limited to 'rubber.lua')
-rw-r--r--rubber.lua97
1 files changed, 95 insertions, 2 deletions
diff --git a/rubber.lua b/rubber.lua
index da5def0..d59190e 100644
--- a/rubber.lua
+++ b/rubber.lua
@@ -1,3 +1,5 @@
+-- Code of rubber tree by PilzAdam
+
minetest.register_node("technic:rubber_sapling", {
description = "Rubber Tree Sapling",
drawtype = "plantlike",
@@ -69,7 +71,7 @@ minetest.register_abm({
interval = 60,
chance = 20,
action = function(pos, node)
- farming:generate_tree(pos, "technic:rubber_tree_full", "technic:rubber_leaves", {"default:dirt", "default:dirt_with_grass"})
+ technic:generate_tree(pos, "technic:rubber_tree_full", "technic:rubber_leaves", {"default:dirt", "default:dirt_with_grass"})
end
})
@@ -80,7 +82,7 @@ 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
- farming: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"})
+ technic: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"})
end
end)
@@ -91,3 +93,94 @@ minetest.register_craft({
recipe = "technic:rubber_sapling",
burntime = 10
})
+
+function technic: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