planetoids/mapgen_oreplanet.lua

83 lines
1.7 KiB
Lua
Raw Normal View History

2019-05-08 19:06:25 +02:00
local has_vacuum_mod = minetest.get_modpath("vacuum")
-- http://dev.minetest.net/PerlinNoiseMap
-- basic planet noise
local planet_params = {
2019-06-28 10:16:57 +02:00
offset = 0,
scale = 1,
spread = {x=2000, y=200, z=2000},
seed = 345465738,
octaves = 3,
persist = 0.6
2019-05-08 19:06:25 +02:00
}
local c_base = minetest.get_content_id("default:stone")
local c_air = minetest.get_content_id("air")
local c_ignore = minetest.get_content_id("ignore")
local c_vacuum
if has_vacuum_mod then
c_vacuum = minetest.get_content_id("vacuum:vacuum")
end
local planet_perlin
local planet_perlin_map = {}
planetoids.mapgen_oreplanet = function(minp, maxp, vm, area)
2019-06-28 10:16:57 +02:00
local data = vm:get_data()
2019-05-08 19:06:25 +02:00
2019-06-28 10:16:57 +02:00
local side_length = maxp.x - minp.x + 1 -- 80
local map_lengths_xyz = {x=side_length, y=side_length, z=side_length}
2019-05-08 19:06:25 +02:00
2019-06-28 10:16:57 +02:00
planet_perlin = planet_perlin or minetest.get_perlin_map(planet_params, map_lengths_xyz)
planet_perlin:get_3d_map_flat(minp, planet_perlin_map)
2019-05-08 19:06:25 +02:00
2019-06-28 10:16:57 +02:00
local i = 1
for z=minp.z,maxp.z do
for y=minp.y,maxp.y do
for x=minp.x,maxp.x do
2019-05-08 19:06:25 +02:00
2019-06-28 10:16:57 +02:00
local index = area:index(x,y,z)
2019-05-08 19:06:25 +02:00
2019-06-28 10:16:57 +02:00
if data[index] == c_air or data[index] == c_vacuum or data[index] == c_ignore then
-- unpopulated node
local planet_n = planet_perlin_map[i]
2019-05-08 19:06:25 +02:00
2019-06-28 10:16:57 +02:00
if planet_n > planetoids.min_chance then
2019-05-08 19:06:25 +02:00
2019-06-28 10:16:57 +02:00
-- planet
data[index] = c_base
2019-12-12 09:04:26 +01:00
for _,ore in pairs(planetoids.ores) do
if planet_n > ore.chance then
2020-01-09 14:53:10 +01:00
if ore.id then
-- "plain" layer
data[index] = ore.id
elseif ore.id_list then
-- mixed layer
data[index] = ore.id_list[math.random(1,#ore.id_list)]
end
2019-12-12 09:04:26 +01:00
break
end
end
2019-06-28 10:16:57 +02:00
end
end
2019-06-28 10:16:57 +02:00
i = i + 1
2019-05-08 19:06:25 +02:00
2019-06-28 10:16:57 +02:00
end --x
end --y
end --z
2019-05-08 19:06:25 +02:00
2019-06-28 10:18:05 +02:00
vm:set_data(data)
2019-06-28 11:19:33 +02:00
minetest.generate_ores(vm, minp, maxp)
2019-05-08 19:06:25 +02:00
end