use the new habitat
This commit is contained in:
parent
e35aef0eb8
commit
3722ff8f1a
@ -1,4 +0,0 @@
|
|||||||
habitat
|
|
||||||
=======
|
|
||||||
|
|
||||||
adds function for modders to use for spawning for example plants and trees near certain nodes
|
|
107
habitat/init.lua
107
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
|
function habitat:generate(node, surface, minp, maxp, height_min, height_max, spread, habitat_size, habitat_nodes, antitat_size, antitat_nodes)
|
||||||
return true
|
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
|
||||||
end
|
end
|
||||||
|
print(count)
|
||||||
return false
|
end)
|
||||||
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!")
|
print("[Habitat] Loaded!")
|
||||||
|
43
habitat/readme.txt
Normal file
43
habitat/readme.txt
Normal file
@ -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
|
Binary file not shown.
@ -153,10 +153,10 @@ minetest.register_abm({
|
|||||||
end
|
end
|
||||||
,})
|
,})
|
||||||
|
|
||||||
--function anti_generate(node, surfaces, minp, maxp, height_min, height_max, spread, habitat_size, habitat_nodes)
|
if sumpf.spawn_plants
|
||||||
if sumpf.enable_birches then
|
and minetest.get_modpath("habitat") then
|
||||||
minetest.register_on_generated(function(minp, maxp, seed)
|
habitat:generate("sumpf:sapling", {"default:dirt_with_grass"},
|
||||||
generate("sumpf:birk", {"default:dirt_with_grass"}, minp, maxp, 20, 25, 100, 500,
|
minp, maxp, 20, 25, 100, 500, {"default:water_source"},30,{"default:desert_sand"})
|
||||||
{"default:water_source"},30,{"default:desert_sand"})
|
habitat:generate("sumpf:gras", {"default:dirt_with_grass"},
|
||||||
end)
|
minp, maxp, 0, 25, 90, 100, {"default:water_source"},30,{"default:desert_sand"})
|
||||||
end
|
end
|
||||||
|
@ -53,8 +53,10 @@ minetest.register_node("sumpf:peat", {
|
|||||||
tiles = {"sumpf_peat.png"},
|
tiles = {"sumpf_peat.png"},
|
||||||
groups = {crumbly=3, falling_node=1, sand=1},
|
groups = {crumbly=3, falling_node=1, sand=1},
|
||||||
sounds = default.node_sound_sand_defaults({
|
sounds = default.node_sound_sand_defaults({
|
||||||
dig = {name="sumpf", gain=0.4},
|
|
||||||
footstep = {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}
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
--This file contains configuration options for swamp mod.
|
--This file contains configuration options for swamp mod.
|
||||||
|
|
||||||
sumpf.enable_mapgen = true
|
sumpf.enable_mapgen = false
|
||||||
|
|
||||||
sumpf.always_generate = false
|
sumpf.always_generate = false
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ sumpf.enable_plants = true
|
|||||||
sumpf.swampwater = false
|
sumpf.swampwater = false
|
||||||
|
|
||||||
--Enables birches (habitat).
|
--Enables birches (habitat).
|
||||||
sumpf.enable_birches = true
|
sumpf.spawn_plants = true
|
||||||
|
|
||||||
--says some information.
|
--says some information.
|
||||||
sumpf.info = true
|
sumpf.info = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user