Last active
March 9, 2022 00:50
-
-
Save doyousketch2/0fd70c8075092fee191788ec5f13f759 to your computer and use it in GitHub Desktop.
mapgen function for nssb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
schemepath = minetest .get_modpath('nssb') ..'/schems/' | |
function nssb_register_buildings( | |
build_name, -- name of schematic | |
rand, -- 1/rand is probability of spawning | |
required, -- required block to to spawn on | |
height, -- under this height, schematic can spawn | |
near, -- scan if this node is near | |
width2fill ) -- width of schematic, to fill dirt / ice under | |
minetest .register_on_generated( | |
function( minp, maxp, seed ) | |
height = height or 0 -- default to 0 if nil given | |
if ( height >= 0 and minp.y > 0 ) -- aboveground | |
or maxp.y < height then -- belowground | |
local i, j, k | |
local placed_scheme = false | |
i = math.random( minp.x, maxp.x ) | |
j = math.random( minp.y, maxp.y ) | |
k = math.random( minp.z, maxp.z ) | |
local node = { x = i, y = j, z = k } | |
local nodename = minetest.env :get_node(node) .name | |
if nodename == required_block and math.random( 1, rand ) == 1 then | |
if minetest .find_node_near( node, 4, near ) then | |
minetest .place_schematic( node, | |
schemepath ..build ..'.mts', '0', {}, true ) | |
placed_scheme = true | |
end -- find_node_near() | |
end -- if nodename == required_block and... | |
-- fill space below scheme, if required | |
if placed_scheme and width > 0 then | |
for dx = -width, width *2 do | |
for dz = -width, width *2 do | |
local gap2fill = { x = node.x +dx, | |
y = node.y -1, | |
z = node.z +dz } | |
local nodename = minetest .env :get_node( gap2fill ) .name | |
while nodename == 'air' | |
or nodename == 'default:water_source' | |
or nodename == 'default:water_flowing' | |
or nodename == 'default:lava_flowing' | |
or nodename == 'default:lava_source' do | |
minetest .env :set_node( gap2fill, { name = required } ) | |
gap2fill.y = gap2fill.y -1 | |
nodename = minetest .env :get_node( gap2fill ) .name | |
end -- while air or water or lava | |
end -- dz | |
end -- dx | |
end -- if placed_scheme and width > 0 | |
end -- if height aboveground or underground | |
end -- function( minp, maxp, seed ) | |
) -- .register_on_generated() | |
end -- nssb_register_buildings() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment