summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.lua182
-rw-r--r--mod.conf3
2 files changed, 185 insertions, 0 deletions
diff --git a/init.lua b/init.lua
new file mode 100644
index 0000000..ccb0900
--- /dev/null
+++ b/init.lua
@@ -0,0 +1,182 @@
+woodnt = {}
+
+minetest.register_node("woodnt:treent",{
+ description = "Treen't",
+ tiles = {
+ "default_tree.png^[invert:rgb",
+ },
+ groups = {
+ cracky = 3,
+ },
+})
+
+minetest.register_node("woodnt:woodnt",{
+ description = "Woodn't Planks",
+ tiles = {
+ "default_wood.png^[invert:rgb",
+ },
+ groups = {
+ cracky = 3,
+ },
+})
+
+minetest.register_node("woodnt:leavesnt",{
+ description = "Leavesn't",
+ tiles = {
+ "default_leaves.png^[invert:rgb",
+ },
+ groups = {
+ snappy = 3,
+ },
+ drawtype = "glasslike",
+ paramtype = "light",
+ light_source = 8,
+ drop = {
+ max_items = 1,
+ items = {
+ {
+ rarity = 10,
+ items = {"woodnt:leavesnt"},
+ },
+ {
+ rarity = 1,
+ items = {"woodnt:saplingnt"},
+ },
+
+ }
+ },
+})
+
+local random = math.random
+
+function woodnt.can_grow(pos)
+ local node_under = minetest.get_node_or_nil({x = pos.x, y = pos.y + 1, z = pos.z})
+ if not node_under then
+ return false
+ end
+ if minetest.get_item_group(node_under.name, "soil") > 0 then
+ return false
+ end
+ local light_level = minetest.get_node_light(pos)
+ if not light_level or light_level > 10 then
+ return false
+ end
+ return true
+end
+
+local function add_trunk_and_leaves(data, a, pos, tree_cid, leaves_cid,
+ height, size, iters, is_apple_tree)
+ local x, y, z = pos.x, pos.y, pos.z
+ local c_air = minetest.get_content_id("air")
+ local c_ignore = minetest.get_content_id("ignore")
+ local c_apple = minetest.get_content_id("default:apple")
+
+ -- Trunk
+ data[a:index(x, y, z)] = tree_cid -- Force-place lowest trunk node to replace sapling
+ for yy = y-height-1,y - 1 do
+ local vi = a:index(x, yy, z)
+ local node_id = data[vi]
+ if node_id == c_air or node_id == c_ignore or node_id == leaves_cid then
+ data[vi] = tree_cid
+ end
+ end
+
+ -- Force leaves near the trunk
+ for z_dist = -1, 1 do
+ for y_dist = -size, 1 do
+ local vi = a:index(x - 1, y - height - y_dist, z + z_dist)
+ for x_dist = -1, 1 do
+ if data[vi] == c_air or data[vi] == c_ignore then
+ if is_apple_tree and random(1, 8) == 1 then
+ data[vi] = c_apple
+ else
+ data[vi] = leaves_cid
+ end
+ end
+ vi = vi + 1
+ end
+ end
+ end
+
+ -- Randomly add leaves in 2x2x2 clusters.
+ for i = 1, iters do
+ local clust_x = x + random(-size, size - 1)
+ local clust_y = y - height + random(-size, 0)
+ local clust_z = z + random(-size, size - 1)
+
+ for xi = 0, 1 do
+ for yi = 0, 1 do
+ for zi = 0, 1 do
+ local vi = a:index(clust_x + xi, clust_y + yi, clust_z + zi)
+ if data[vi] == c_air or data[vi] == c_ignore then
+ if is_apple_tree and random(1, 8) == 1 then
+ data[vi] = c_apple
+ else
+ data[vi] = leaves_cid
+ end
+ end
+ end
+ end
+ end
+ end
+end
+
+function woodnt.grow_tree(pos, is_apple_tree, bad)
+ --[[
+ NOTE: Tree-placing code is currently duplicated in the engine
+ and in games that have saplings; both are deprecated but not
+ replaced yet
+ --]]
+ if bad then
+ error("Deprecated use of default.grow_tree")
+ end
+
+ local x, y, z = pos.x, pos.y, pos.z
+ local height = random(4, 5)
+ local c_tree = minetest.get_content_id("woodnt:treent")
+ local c_leaves = minetest.get_content_id("woodnt:leavesnt")
+
+ local vm = minetest.get_voxel_manip()
+ local minp, maxp = vm:read_from_map(
+ {x = x - 2, y = y, z = z - 2},
+ {x = x + 2, y = y - height - 1, z = z + 2}
+ )
+ local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
+ local data = vm:get_data()
+
+ add_trunk_and_leaves(data, a, pos, c_tree, c_leaves, height, 2, 8, is_apple_tree)
+
+ vm:set_data(data)
+ vm:write_to_map()
+ vm:update_map()
+end
+
+function woodnt.grow_sapling(pos)
+ if not woodnt.can_grow(pos) then
+ minetest.get_node_timer(pos):start(30)
+ return
+ end
+ woodnt.grow_tree(pos)
+end
+
+minetest.register_node("woodnt:saplingnt",{
+ description = "Saplingn't",
+ tiles = {
+ "default_sapling.png^[invert:rgb^[transformFY",
+ },
+ groups = {
+ snappy = 1,
+ },
+ drawtype = "plantlike",
+ paramtype = "light",
+ on_timer = woodnt.grow_sapling,
+ on_construct = function(pos)
+ minetest.get_node_timer(pos):start(math.random(30, 150))
+ end,
+})
+
+minetest.register_craft({
+ output = "woodnt:woodnt 4",
+ recipe = {{"woodnt:treent"}},
+})
+
diff --git a/mod.conf b/mod.conf
new file mode 100644
index 0000000..7cb1071
--- /dev/null
+++ b/mod.conf
@@ -0,0 +1,3 @@
+name = woodnt
+description = Some mod, blame rdococ
+depends = default