modularize get_building
function from mapgen helper
This commit is contained in:
parent
27bc4f5fe3
commit
5b3cbd2513
54
mapgen.lua
54
mapgen.lua
@ -104,25 +104,7 @@ function building_lib.create_mapgen(opts)
|
|||||||
return mapblock_pos.y == opts.water_level and height <= mapblock_pos.y
|
return mapblock_pos.y == opts.water_level and height <= mapblock_pos.y
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_generated(minp, maxp)
|
local function get_building(mapblock_pos)
|
||||||
local min_mapblock = mapblock_lib.get_mapblock(minp)
|
|
||||||
local max_mapblock = mapblock_lib.get_mapblock(maxp)
|
|
||||||
|
|
||||||
if max_mapblock.y < opts.from_y or min_mapblock.y > opts.to_y then
|
|
||||||
-- check broad y-range
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
for x=min_mapblock.x,max_mapblock.x do
|
|
||||||
for y=min_mapblock.y,max_mapblock.y do
|
|
||||||
for z=min_mapblock.z,max_mapblock.z do
|
|
||||||
if y < opts.from_y or y > opts.to_y then
|
|
||||||
-- check exact y-range
|
|
||||||
break
|
|
||||||
end
|
|
||||||
|
|
||||||
local mapblock_pos = { x=x, y=y, z=z }
|
|
||||||
local height = get_height(mapblock_pos)
|
local height = get_height(mapblock_pos)
|
||||||
|
|
||||||
local temperature, humidity = get_temperature_humidity(mapblock_pos)
|
local temperature, humidity = get_temperature_humidity(mapblock_pos)
|
||||||
@ -130,10 +112,10 @@ function building_lib.create_mapgen(opts)
|
|||||||
|
|
||||||
if is_water(mapblock_pos) then
|
if is_water(mapblock_pos) then
|
||||||
-- nothing above, place water building
|
-- nothing above, place water building
|
||||||
building_lib.build_mapgen(mapblock_pos, biome.buildings.water, 0)
|
return biome.buildings.water, 0
|
||||||
elseif mapblock_pos.y < height or mapblock_pos.y < opts.water_level then
|
elseif mapblock_pos.y < height or mapblock_pos.y < opts.water_level then
|
||||||
-- underground
|
-- underground
|
||||||
building_lib.build_mapgen(mapblock_pos, biome.buildings.underground, 0)
|
return biome.buildings.underground, 0
|
||||||
elseif mapblock_pos.y == height then
|
elseif mapblock_pos.y == height then
|
||||||
-- surface
|
-- surface
|
||||||
|
|
||||||
@ -184,6 +166,31 @@ function building_lib.create_mapgen(opts)
|
|||||||
rotation = 0
|
rotation = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return building_name, rotation
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function on_generated(minp, maxp)
|
||||||
|
local min_mapblock = mapblock_lib.get_mapblock(minp)
|
||||||
|
local max_mapblock = mapblock_lib.get_mapblock(maxp)
|
||||||
|
|
||||||
|
if max_mapblock.y < opts.from_y or min_mapblock.y > opts.to_y then
|
||||||
|
-- check broad y-range
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
for x=min_mapblock.x,max_mapblock.x do
|
||||||
|
for y=min_mapblock.y,max_mapblock.y do
|
||||||
|
for z=min_mapblock.z,max_mapblock.z do
|
||||||
|
if y < opts.from_y or y > opts.to_y then
|
||||||
|
-- check exact y-range
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
local mapblock_pos = { x=x, y=y, z=z }
|
||||||
|
local building_name, rotation = get_building(mapblock_pos)
|
||||||
|
if building_name then
|
||||||
building_lib.build_mapgen(mapblock_pos, building_name, rotation)
|
building_lib.build_mapgen(mapblock_pos, building_name, rotation)
|
||||||
end
|
end
|
||||||
end --z
|
end --z
|
||||||
@ -191,7 +198,9 @@ function building_lib.create_mapgen(opts)
|
|||||||
end --x
|
end --x
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- exposed mapgen helper functions
|
||||||
return {
|
return {
|
||||||
|
-- main function for "minetest.register_on_generated"
|
||||||
on_generated = on_generated,
|
on_generated = on_generated,
|
||||||
get_height = get_height,
|
get_height = get_height,
|
||||||
get_temperature_humidity = get_temperature_humidity,
|
get_temperature_humidity = get_temperature_humidity,
|
||||||
@ -199,6 +208,7 @@ function building_lib.create_mapgen(opts)
|
|||||||
local temperature, humidity = get_temperature_humidity(mapblock_pos)
|
local temperature, humidity = get_temperature_humidity(mapblock_pos)
|
||||||
return select_biome(opts.biomes, temperature, humidity)
|
return select_biome(opts.biomes, temperature, humidity)
|
||||||
end,
|
end,
|
||||||
is_water = is_water
|
is_water = is_water,
|
||||||
|
get_building = get_building
|
||||||
}
|
}
|
||||||
end
|
end
|
Loading…
x
Reference in New Issue
Block a user