2019-02-19 19:02:21 -05:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-02-23 22:48:39 -05:00
|
|
|
local math, minetest, nodecore
|
|
|
|
= math, minetest, nodecore
|
2020-06-20 23:48:29 -04:00
|
|
|
local math_floor
|
|
|
|
= math.floor
|
2019-02-19 19:02:21 -05:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
|
|
|
|
local maxy = -8
|
|
|
|
local miny = maxy - 8
|
|
|
|
|
|
|
|
local c_sand = minetest.get_content_id("nc_terrain:sand")
|
|
|
|
local c_water = minetest.get_content_id("nc_terrain:water_source")
|
|
|
|
local c_sponge = minetest.get_content_id(modname .. ":sponge_living")
|
|
|
|
|
2020-06-20 23:48:29 -04:00
|
|
|
local function spawn(area, data, x, y, z, rng)
|
2019-09-23 21:46:23 -04:00
|
|
|
local total = 0
|
|
|
|
nodecore.scan_flood({x = x, y = y, z = z}, 5, function(p)
|
2020-06-20 23:48:29 -04:00
|
|
|
if rng() < 0.01 then return true end
|
|
|
|
if p.y > y and rng() > 0.1 then return false end
|
2019-09-23 21:46:23 -04:00
|
|
|
local idx = area:index(p.x, p.y - 1, p.z)
|
|
|
|
if data[idx] ~= c_sponge and data[idx] ~= c_sand then return false end
|
|
|
|
idx = area:index(p.x, p.y, p.z)
|
|
|
|
if data[idx] ~= c_water then return false end
|
|
|
|
data[idx] = c_sponge
|
|
|
|
total = total + 1
|
|
|
|
if total >= 20 then return true end
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2020-01-12 10:30:02 -05:00
|
|
|
nodecore.register_mapgen_shared({
|
|
|
|
label = "sponges",
|
2020-06-20 23:48:29 -04:00
|
|
|
func = function(minp, maxp, area, data, _, _, _, rng)
|
2020-01-12 10:30:02 -05:00
|
|
|
if minp.y > maxy or maxp.y < miny then return end
|
2019-02-19 19:02:21 -05:00
|
|
|
|
2020-06-20 23:48:29 -04:00
|
|
|
local rawqty = rng() * (maxp.x - minp.x + 1)
|
2020-03-21 09:05:53 -04:00
|
|
|
* (maxp.z - minp.z + 1) / (64 * 64)
|
|
|
|
local qty = math_floor(rawqty)
|
2020-06-20 23:48:29 -04:00
|
|
|
if rng() < (rawqty - qty) then qty = qty + 1 end
|
2020-03-21 09:05:53 -04:00
|
|
|
|
2020-01-12 10:30:02 -05:00
|
|
|
for _ = 1, qty do
|
2020-06-20 23:48:29 -04:00
|
|
|
local x = math_floor(rng() * (maxp.x - minp.x + 1)) + minp.x
|
|
|
|
local z = math_floor(rng() * (maxp.z - minp.z + 1)) + minp.z
|
2020-01-12 10:30:02 -05:00
|
|
|
local starty = maxp.y
|
|
|
|
if starty > (maxy + 1) then starty = (maxy + 1) end
|
|
|
|
local endy = minp.y
|
|
|
|
if endy < miny then endy = miny end
|
|
|
|
local waterabove = nil
|
|
|
|
for y = starty, endy, -1 do
|
|
|
|
local idx = area:index(x, y, z)
|
|
|
|
local cur = data[idx]
|
|
|
|
if cur == c_water then
|
|
|
|
waterabove = true
|
|
|
|
elseif cur == c_sand and waterabove then
|
2020-06-20 23:48:29 -04:00
|
|
|
spawn(area, data, x, y + 1, z, rng)
|
2020-01-12 10:30:02 -05:00
|
|
|
break
|
|
|
|
else
|
|
|
|
break
|
|
|
|
end
|
2019-02-19 19:02:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-01-12 10:30:02 -05:00
|
|
|
})
|