From d669079a6075685ab97c0a6e940fdc5dc6578735 Mon Sep 17 00:00:00 2001 From: Bas Date: Fri, 25 Jan 2013 20:55:24 +0100 Subject: [PATCH] New vines and compatible with plant_lib --- README.md | 12 +- depends.txt | 1 + init.lua | 415 ++++++++++++++++++++-------------------- textures/vines_item.png | Bin 0 -> 359 bytes textures/vines_root.png | Bin 0 -> 441 bytes textures/vines_side.png | Bin 0 -> 537 bytes 6 files changed, 218 insertions(+), 210 deletions(-) create mode 100644 textures/vines_item.png create mode 100644 textures/vines_root.png create mode 100644 textures/vines_side.png diff --git a/README.md b/README.md index 6e3f3d8..2e6fb7a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,12 @@ -vines +Vines ===== -Vines mod for minetest. Also adds ropes. \ No newline at end of file +Description +==== +Vines mod for Minetest. That also adds ropebox + +Types of vines +===== +* Side vines +* Root vines +* Bottom vines diff --git a/depends.txt b/depends.txt index 4ad96d5..d1473e1 100644 --- a/depends.txt +++ b/depends.txt @@ -1 +1,2 @@ default +plants_lib diff --git a/init.lua b/init.lua index 57a0213..c934201 100644 --- a/init.lua +++ b/init.lua @@ -1,250 +1,249 @@ -print("[Vines] v1.0") +--Vines Mod for minetest adds vines to trees and dirt with grass nodes, +--Also adds spawning API made for things that grow on the side of nodes signlike(param2) and things that grow downward. + +--BY: Bas080 +--DESCRIPTION: Vines for minetest +--Licence: WTFPL + +local mod_name = "vines" +local average_height = 12 -- Nodes minetest.register_node("vines:rope_block", { - description = "Rope", - sunlight_propagates = true, - paramtype = "light", - drops = "", - tile_images = { - "vines_rope_block.png", - "vines_rope_block.png", - "default_wood.png", - "default_wood.png", - "vines_rope_block.png", - "vines_rope_block.png" - }, - drawtype = "cube", - groups = { snappy = 3}, - sounds = default.node_sound_leaves_defaults(), - after_place_node = function(pos) - local p = {x=pos.x, y=pos.y-1, z=pos.z} - local n = minetest.env:get_node(p) - if n.name == "air" then - minetest.env:add_node(p, {name="vines:rope_end"}) + description = "Rope", + sunlight_propagates = true, + paramtype = "light", + drops = "", + tile_images = { + "vines_rope_block.png", + "vines_rope_block.png", + "default_wood.png", + "default_wood.png", + "vines_rope_block.png", + "vines_rope_block.png" + }, + drawtype = "cube", + groups = { snappy = 3}, + sounds = default.node_sound_leaves_defaults(), + after_place_node = function(pos) + local p = {x=pos.x, y=pos.y-1, z=pos.z} + local n = minetest.env:get_node(p) + if n.name == "air" then + minetest.env:add_node(p, {name="vines:rope_end"}) end end, }) minetest.register_node("vines:rope", { - description = "Rope", - walkable = false, - climbable = true, - sunlight_propagates = true, - paramtype = "light", - tile_images = { "vines_rope.png" }, - drawtype = "plantlike", - groups = {}, - sounds = default.node_sound_leaves_defaults(), - selection_box = { - type = "fixed", - fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7}, - }, - + description = "Rope", + walkable = false, + climbable = true, + sunlight_propagates = true, + paramtype = "light", + tile_images = { "vines_rope.png" }, + drawtype = "plantlike", + groups = {}, + sounds = default.node_sound_leaves_defaults(), + selection_box = { + type = "fixed", + fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7}, + }, }) minetest.register_node("vines:rope_end", { - description = "Rope", - walkable = false, - climbable = true, - sunlight_propagates = true, - paramtype = "light", - drops = "", - tile_images = { "vines_rope.png" }, - drawtype = "plantlike", - groups = {}, - sounds = default.node_sound_leaves_defaults(), - after_place_node = function(pos) - yesh = {x = pos.x, y= pos.y-1, z=pos.z} - minetest.env:add_node(yesh, "vines:rope") - end, - selection_box = { - type = "fixed", - fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7}, - }, + description = "Rope", + walkable = false, + climbable = true, + sunlight_propagates = true, + paramtype = "light", + drops = "", + tile_images = { "vines_rope.png" }, + drawtype = "plantlike", + groups = {}, + sounds = default.node_sound_leaves_defaults(), + after_place_node = function(pos) + yesh = {x = pos.x, y= pos.y-1, z=pos.z} + minetest.env:add_node(yesh, "vines:rope") + end, + selection_box = { + type = "fixed", + fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7}, + }, }) +minetest.register_node("vines:side", { + description = "Vine", + walkable = false, + climbable = true, + drop = 'vines:vines', + sunlight_propagates = true, + paramtype = "light", + paramtype2 = "wallmounted", + tile_images = { "vines_side.png" }, + drawtype = "signlike", + inventory_image = "vines_side.png", + groups = { snappy = 3,flammable=2, hanging=1 }, + sounds = default.node_sound_leaves_defaults(), + selection_box = { + type = "wallmounted", + }, + on_construct = function(pos, placer) + local p = {x=pos.x, y=pos.y, z=pos.z} + local n = minetest.env:get_node(p) + local walldir = n.param2 + local down=-1 + + print("Placed") + + while math.random(0,average_height) > 1.0 do + print("One") + local pt = {x = p.x, y= p.y+down, z=p.z} + local nt = minetest.env:get_node(pt) + if nt.name == "air" then + minetest.env:add_node(pt, {name=n.name, param2 = walldir}) + down=down-1 + else + return + end + end + end, +}) + +minetest.register_node("vines:root", { + description = "Vine", + walkable = false, + climbable = true, + drop = 'vines:vines', + sunlight_propagates = true, + paramtype = "light", + tile_images = { "vines_root.png" }, + drawtype = "plantlike", + inventory_image = "vines_root.png", + groups = { snappy = 3,flammable=2, hanging=1 }, + sounds = default.node_sound_leaves_defaults(), + selection_box = { + type = "fixed", + fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7}, + }, +}) minetest.register_node("vines:vine", { - description = "Vine", - walkable = false, - climbable = true, - drop = 'vines:vines', - sunlight_propagates = true, - paramtype = "light", - tile_images = { "vines_vine.png" }, - drawtype = "plantlike", - inventory_image = "vines_vine.png", - groups = { snappy = 3,flammable=2, hanging=1 }, - sounds = default.node_sound_leaves_defaults(), + description = "Vine", + walkable = false, + climbable = true, + drop = 'vines:vines', + sunlight_propagates = true, + paramtype = "light", + tile_images = { "vines_vine.png" }, + drawtype = "plantlike", + inventory_image = "vines_vine.png", + groups = { snappy = 3,flammable=2, hanging=1 }, + sounds = default.node_sound_leaves_defaults(), + selection_box = { + type = "fixed", + fixed = {-0.3, -1/2, -0.3, 0.3, 1/2, 0.3}, + }, }) minetest.register_node("vines:vine_rotten", { - description = "Rotten vine", - walkable = false, - climbable = true, - drop = 'vines:vines', - sunlight_propagates = true, - paramtype = "light", - tile_images = { "vines_vine_rotten.png" }, - drawtype = "plantlike", - inventory_image = "vines_vine_rotten.png", - groups = { snappy = 3,flammable=2, hanging=1 }, - sounds = default.node_sound_leaves_defaults(), + description = "Rotten vine", + walkable = false, + climbable = true, + drop = 'vines:vines', + sunlight_propagates = true, + paramtype = "light", + tile_images = { "vines_vine_rotten.png" }, + drawtype = "plantlike", + inventory_image = "vines_vine_rotten.png", + groups = { snappy = 3,flammable=2, hanging=1 }, + sounds = default.node_sound_leaves_defaults(), + selection_box = { + type = "fixed", + fixed = {-0.3, -1/2, -0.3, 0.3, 1/2, 0.3}, + }, }) --ABM +--make vines grow downward minetest.register_abm({ - nodenames = {"default:leaves", "growing_trees:leaves", "default:dirt_with_grass", }, - interval = 180, - chance = 200, - action = function(pos, node) - - local p = {x=pos.x, y=pos.y-1, z=pos.z} - local n = minetest.env:get_node(p) - - if n.name =="air" then - minetest.env:add_node(p, {name="vines:vine"}) - end - end -}) - - - -minetest.register_abm({ - nodenames = {"vines:vine"}, - interval = 5, - chance = 4, - action = function(pos, node, active_object_count, active_object_count_wider) - - local p = {x=pos.x, y=pos.y-1, z=pos.z} - local n = minetest.env:get_node(p) - - --remove if top node is removed - if minetest.env:get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" then - minetest.env:remove_node(pos) - end - - --the second argument in the random function represents the average height - if math.random(0,3)<1 then - minetest.env:add_node(pos, {name="vines:vine_rotten"}) - else - if n.name =="air" then - minetest.env:add_node(pos, {name="vines:vine_rotten"}) - minetest.env:add_node(p, {name="vines:vine"}) - end - end + nodenames = {"vines:vine", "vines:side", "vines:root"}, + interval = 300, + chance = 8, + action = function(pos, node, active_object_count, active_object_count_wider) + local p = {x=pos.x, y=pos.y-1, z=pos.z} + local n = minetest.env:get_node(p) + if n.name == "air" then + walldir = node.param2 + minetest.env:add_node(p, {name=node.name, param2 = walldir}) end + end }) minetest.register_abm({ - nodenames = {"vines:vine_rotten"}, - interval = 60, - chance = 4, - action = function(pos, node, active_object_count, active_object_count_wider) - - local p = {x=pos.x, y=pos.y-1, z=pos.z} - local n = minetest.env:get_node(p) - - -- only remove if nothing is hangin on the bottom of it. - if n.name ~="vines:vine" and n.name ~="vines:vine_rotten" then - minetest.env:remove_node(pos) - end - - if minetest.env:get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" then - minetest.env:remove_node({x=pos.x, y=pos.y+1, z=pos.z}) - end - - end + nodenames = {"default:dirt", "default:dirt_with_grass"}, + interval = 36000, + chance = 10, + action = function(pos, node, active_object_count, active_object_count_wider) + local p = {x=pos.x, y=pos.y-1, z=pos.z} + local n = minetest.env:get_node(p) + minetest.env:add_node(p, {name="vines:vine"}) + end }) minetest.register_abm({ - nodenames = {"default:dirt", "default:dirt_with_grass"}, - interval = 36000, - chance = 10, - action = function(pos, node, active_object_count, active_object_count_wider) - - local p = {x=pos.x, y=pos.y-1, z=pos.z} - local n = minetest.env:get_node(p) - - --remove if top node is removed - if n.name == "air" and is_node_in_cube ({"vines:vine"}, pos, 3) then - minetest.env:add_node(p, {name="vines:vine"}) - end - end + nodenames = {"vines:rope_end"}, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local p = {x=pos.x, y=pos.y-1, z=pos.z} + local n = minetest.env:get_node(p) + + --remove if top node is removed + if n.name == "air" then + minetest.env:remove_node(pos) + minetest.env:add_node(pos, {name="vines:rope"}) + minetest.env:add_node(p, {name="vines:rope_end"}) + end + end }) -minetest.register_abm({ - nodenames = {"vines:rope_end"}, - interval = 1, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - - local p = {x=pos.x, y=pos.y-1, z=pos.z} - local n = minetest.env:get_node(p) - - --remove if top node is removed - if n.name == "air" then - minetest.env:remove_node(pos) - minetest.env:add_node(pos, {name="vines:rope"}) - minetest.env:add_node(p, {name="vines:rope_end"}) - end - end -}) - -is_node_in_cube = function(nodenames, node_pos, radius) - for x = node_pos.x - radius, node_pos.x + radius do - for y = node_pos.y - radius, node_pos.y + radius do - for z = node_pos.z - radius, node_pos.z + radius do - n = minetest.env:get_node_or_nil({x = x, y = y, z = z}) - if (n == nil) - or (n.name == 'ignore') - or (table_contains(nodenames, n.name) == true) then - return true - end - end - end - end - - return false -end - -table_contains = function(t, v) - for _, i in ipairs(t) do - if (i == v) then - return true - end - end - - return false -end - -- craft rope minetest.register_craft({ - output = 'vines:rope_block', - recipe = { - {'', 'default:wood', ''}, - {'', 'vines:vines', ''}, - {'', 'vines:vines', ''}, - } + output = 'vines:rope_block', + recipe = { + {'', 'default:wood', ''}, + {'', 'vines:vines', ''}, + {'', 'vines:vines', ''}, + } }) minetest.register_craftitem("vines:vines", { description = "Vines", - inventory_image = "vines_vine.png", + inventory_image = "vines_item.png", }) +--remove rope when rope block is removed minetest.register_on_dignode(function (pos, node, player) - if node.name == 'vines:rope_block' then - local p = {x=pos.x, y=pos.y-1, z=pos.z} - local n = minetest.env:get_node(p) - while n.name == 'vines:rope' do - minetest.env:remove_node(p) - p = {x=p.x, y=p.y-1, z=p.z} - n = minetest.env:get_node(p) - end - if n.name == 'vines:rope_end' then - minetest.env:remove_node(p) - end + if node.name == 'vines:rope_block' then + local p = {x=pos.x, y=pos.y-1, z=pos.z} + local n = minetest.env:get_node(p) + while n.name == 'vines:rope' do + minetest.env:remove_node(p) + p = {x=p.x, y=p.y-1, z=p.z} + n = minetest.env:get_node(p) end + if n.name == 'vines:rope_end' then + minetest.env:remove_node(p) + end + end end) + +plantslib:spawn_on_surfaces({ + spawn_delay = 300, + spawn_plants = {"vines:side"}, + spawn_chance = 10, + spawn_surfaces = {"default:leaves"}, + spawn_on_side = true +}) + +print("[Vines] Loaded!") diff --git a/textures/vines_item.png b/textures/vines_item.png new file mode 100644 index 0000000000000000000000000000000000000000..f02bc653ddbf503bb2e02c7e9f7c2c0f42a7b354 GIT binary patch literal 359 zcmeAS@N?(olHy`uVBq!ia0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