let biome_lib place pebbles instead of using custom mapgen code

This commit is contained in:
Vanessa Dannenberg 2021-04-06 04:04:08 -04:00
parent 81b2b0898b
commit 4876fc1265
3 changed files with 31 additions and 50 deletions

View File

@ -7,6 +7,8 @@ local mname = "cavestuff"
-- support for i18n -- support for i18n
local S = minetest.get_translator("cavestuff") local S = minetest.get_translator("cavestuff")
cavestuff = {}
dofile(minetest.get_modpath("cavestuff").."/nodes.lua") dofile(minetest.get_modpath("cavestuff").."/nodes.lua")
dofile(minetest.get_modpath("cavestuff").."/mapgen.lua") dofile(minetest.get_modpath("cavestuff").."/mapgen.lua")

View File

@ -1,52 +1,31 @@
--Map Generation Stuff --Map Generation Stuff
minetest.register_on_generated(function(minp, maxp, seed) biome_lib:register_generate_plant(
if maxp.y >= 2 and minp.y <= 0 then {
-- Generate pebbles surface = { "default:dirt_with_grass" },
local perlin1 = minetest.get_perlin(329, 3, 0.6, 100) max_count = 50,
-- Assume X and Z lengths are equal rarity = 0,
local divlen = 16 plantlife_limit = -1,
local divs = (maxp.x-minp.x)/divlen+1; check_air = true,
for divx=0,divs-1 do random_facedir = {0, 3}
for divz=0,divs-1 do },
local x0 = minp.x + math.floor((divx+0)*divlen) {
local z0 = minp.z + math.floor((divz+0)*divlen) "cavestuff:pebble_1",
local x1 = minp.x + math.floor((divx+1)*divlen) "cavestuff:pebble_2"
local z1 = minp.z + math.floor((divz+1)*divlen) }
-- Determine pebble amount from perlin noise )
local pebble_amount = math.floor(perlin1:get2d({x=x0, y=z0}) ^ 2 * 2)
-- Find random positions for pebbles based on this random
local pr = PseudoRandom(seed+1)
for i=0,pebble_amount do
local x = pr:next(x0, x1)
local z = pr:next(z0, z1)
-- Find ground level (0...15)
local ground_y = nil
for y=30,0,-1 do
if minetest.get_node({x=x,y=y,z=z}).name ~= "air" then
ground_y = y
break
end
end
if ground_y then biome_lib:register_generate_plant(
local p = {x=x,y=ground_y+1,z=z} {
local nn = minetest.get_node(p).name surface = { "default:desert_sand" },
-- Check if the node can be replaced max_count = 50,
if minetest.registered_nodes[nn] and rarity = 0,
minetest.registered_nodes[nn].buildable_to then plantlife_limit = -1,
nn = minetest.get_node({x=x,y=ground_y,z=z}).name check_air = true,
-- If desert sand, add dry shrub random_facedir = {0, 3}
if nn == "default:dirt_with_grass" then },
minetest.swap_node(p,{name="cavestuff:pebble_"..pr:next(1,2), param2=math.random(0,3)}) {
elseif nn == "default:desert_sand" then "cavestuff:desert_pebble_1",
minetest.swap_node(p,{name="cavestuff:desert_pebble_"..pr:next(1,2), param2=math.random(0,3)}) "cavestuff:desert_pebble_2"
end }
end )
end
end
end
end
end
end)

View File

@ -1,2 +1,2 @@
name = cavestuff name = cavestuff
depends = default depends = default,biome_lib