diff --git a/habitat/README.md b/habitat/README.md deleted file mode 100644 index a4d5d2b..0000000 --- a/habitat/README.md +++ /dev/null @@ -1,4 +0,0 @@ -habitat -======= - -adds function for modders to use for spawning for example plants and trees near certain nodes \ No newline at end of file diff --git a/habitat/init.lua b/habitat/init.lua index 84e77fb..7efe99a 100644 --- a/habitat/init.lua +++ b/habitat/init.lua @@ -1,69 +1,48 @@ ---Habitat is a mod which adds the function to spawn nodes near certain nodes and away from others on map generate +habitat = {} -local function arrayContains(array, value) - for _,v in pairs(array) do - if v == value then - return true + + +function habitat:generate(node, surface, minp, maxp, height_min, height_max, spread, habitat_size, habitat_nodes, antitat_size, antitat_nodes) + minetest.register_on_generated(function(minp, maxp, seed) + if height_min > maxp.y or height_max < minp.y then + return + end + + local height_min_max = math.max(height_min,minp.y) + local height_max_min = math.min(height_max,maxp.y) + local width = maxp.x-minp.x + local length = maxp.z-minp.z + local height = height_max-height_min + local y_current + local x_current + local z_current + local x_deviation + local z_deviation + local p = {x=minp.x, y=y_current, z=minp.z} + local n = minetest.env:get_node(p).name + local n_top + local p_top + print(node) + local count = 0 + for x_current = spread/2, width, spread do + for z_current = spread/2, length, spread do + x_deviation = math.floor(math.random(spread))-spread/2 + z_deviation = math.floor(math.random(spread))-spread/2 + for y_current = height_max_min, height_min_max, -1 do + n_top = n + count = count + 1 + p = {x=minp.x+x_current+x_deviation, y=y_current, z=minp.z+z_current+z_deviation} + n = minetest.env:get_node(p).name + if surface == n and n_top == "air" then + p_top = {x=p.x, y=p.y+1, z=p.z} + if minetest.env:find_node_near(p_top, habitat_size, habitat_nodes) ~= nil and minetest.env:find_node_near(p_top, antitat_size, antitat_nodes) == nil then + minetest.env:add_node(p_top, {name=node}) + end + end + end end end - - return false + print(count) + end) end - ---HOW TO USE ---minetest.register_on_generated(function(minp, maxp, seed) - --generate("plants:lavender_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 60, 4, 4, {"default:sand",}) ---end) - -function generate(node, surfaces, minp, maxp, height_min, height_max, spread, habitat_size, habitat_nodes, antitat_size, antitat_nodes) - - if height_min > maxp.y or height_max < minp.y then --stop if min and max height of plant spawning is not generated area - return - end - - local y_min = math.max(minp.y, height_min) - local y_max = math.min(maxp.y, height_max) - - local width = maxp.x-minp.x - local length = maxp.z-minp.z - local height = height_max-height_min - - local y_current - local x_current - local z_current - - local x_deviation - local z_deviation - - local p - local n - local p_top - local n_top - - --loop and take steps depending on the spread of the plants - for x_current = spread/2, width, spread do - for z_current = spread/2, length, spread do - - x_deviation = math.floor(math.random(spread))-spread/2 - z_deviation = math.floor(math.random(spread))-spread/2 - - for y_current = height_max, height_min, -1 do --loop to look for the node that is not air - p = {x=minp.x+x_current+x_deviation, y=y_current, z=minp.z+z_current+z_deviation} - n = minetest.env:get_node(p) - p_top = {x=p.x, y=p.y+1, z=p.z} - n_top = minetest.env:get_node(p_top) - - if n.name ~= "air" and n_top.name == "air" then - if arrayContains(surfaces, n.name) then - if minetest.env:find_node_near(p_top, habitat_size, habitat_nodes) ~= nil and minetest.env:find_node_near(p_top, antitat_size, antitat_nodes) == nil then - minetest.env:add_node(p_top, {name=node}) - end - end - end - end - z_current = z_current + spread - end - end -end - print("[Habitat] Loaded!") diff --git a/habitat/readme.txt b/habitat/readme.txt new file mode 100644 index 0000000..a2189b6 --- /dev/null +++ b/habitat/readme.txt @@ -0,0 +1,43 @@ + __ __ _______ _______ ___ _______ _______ _______ +| | | || _ || _ || | | || _ || | +| |_| || |_| || |_| || | |_ _|| |_| ||_ _| +| || || || | | | | | | | +| || || _ | | | | | | | | | +| _ || _ || |_| || | | | | _ | | | +|__| |__||__| |__||_______||___| |___| |__| |__| |___| + +BY: bas080 +DESCRIPTION: Adds the function to spawn nodes near certain nodes and away from others on world generate +VERSION: 0.5 +LICENCE: WTFPL +FORUM: http://forum.minetest.net/viewtopic.php?id=4612 + +Instructions + +habitat:generate(node, surfaces, minp, maxp, height_min, height_max, spread, habitat_size, habitat_nodes, antitat_size, antitat_nodes) + +* height is the altitude between the node spawns +* spawn near habitat nodes +* avoids antitat nodes +* spread determines how near they spawn next to eachother + +Example (from plants mod) + +habitat:generate("plants:lavender_wild", {"default:dirt_with_grass"}, minp, maxp, -10, 60, 4, 4, {"default:sand",}) + +TODO + +1.1 +* Make node string argument nodes array that spawns random nodes in array + +Changelog + +1.0 +* Reduce amount of loops even more by changing surfaces array to surface string + +0.5 +* changed function definition (name) +* Improved for loop. Less looping and node checking + +0.1 +* Spawn plants on generate diff --git a/sumpf/16771__dobroide__20060307-swamp.wav b/sumpf/16771__dobroide__20060307-swamp.wav deleted file mode 100644 index 4573bdf..0000000 Binary files a/sumpf/16771__dobroide__20060307-swamp.wav and /dev/null differ diff --git a/sumpf/birke.lua b/sumpf/birke.lua index fcc9aac..ba12d1c 100644 --- a/sumpf/birke.lua +++ b/sumpf/birke.lua @@ -153,10 +153,10 @@ minetest.register_abm({ end ,}) ---function anti_generate(node, surfaces, minp, maxp, height_min, height_max, spread, habitat_size, habitat_nodes) -if sumpf.enable_birches then - minetest.register_on_generated(function(minp, maxp, seed) - generate("sumpf:birk", {"default:dirt_with_grass"}, minp, maxp, 20, 25, 100, 500, - {"default:water_source"},30,{"default:desert_sand"}) - end) +if sumpf.spawn_plants +and minetest.get_modpath("habitat") then + habitat:generate("sumpf:sapling", {"default:dirt_with_grass"}, + minp, maxp, 20, 25, 100, 500, {"default:water_source"},30,{"default:desert_sand"}) + habitat:generate("sumpf:gras", {"default:dirt_with_grass"}, + minp, maxp, 0, 25, 90, 100, {"default:water_source"},30,{"default:desert_sand"}) end diff --git a/sumpf/init.lua b/sumpf/init.lua index 99b20dd..e3eee69 100644 --- a/sumpf/init.lua +++ b/sumpf/init.lua @@ -53,8 +53,10 @@ minetest.register_node("sumpf:peat", { tiles = {"sumpf_peat.png"}, groups = {crumbly=3, falling_node=1, sand=1}, sounds = default.node_sound_sand_defaults({ - dig = {name="sumpf", gain=0.4}, footstep = {name="sumpf", gain=0.4}, + place = {name="sumpf", gain=0.4}, + dig = {name="sumpf", gain=0.4}, + dug = {name="default_dirt_footstep", gain=0.25} }), }) diff --git a/sumpf/settings.lua b/sumpf/settings.lua index ff2685b..2283deb 100644 --- a/sumpf/settings.lua +++ b/sumpf/settings.lua @@ -1,6 +1,6 @@ --This file contains configuration options for swamp mod. -sumpf.enable_mapgen = true +sumpf.enable_mapgen = false sumpf.always_generate = false @@ -13,7 +13,7 @@ sumpf.enable_plants = true sumpf.swampwater = false --Enables birches (habitat). -sumpf.enable_birches = true +sumpf.spawn_plants = true --says some information. sumpf.info = true