Please Note:
- They are not designed to follow the conventions of the default mapgen API. In addition significant portions of the mapgen API are not supported by these mods.
- They are primarily designed for ease of use, not performance. However these mods should not add significant performance overheads.
- The APIs that are presented are subject to change.
- These mods should work well together, but interfaces which are incompatible may be released.
This mod provides a combined interface for noise creation, buffer management, composition and indexing.
Spoiler
-- Download: https://github.com/Qwertymine/mgnm/archive/master.zip
-- API: https://github.com/Qwertymine/mgnm/blob/master/api.txt
-- Github: https://github.com/Qwertymine/mgnm
Use:
There is a larger interface than I can reasonably describe here, so I will provide some abstract code samples (used to design the interfaces) and a sample mod.
Code: Select all
local noise_params = {
-- REQUIRED FIELDS
size = {x=5,y=5,z=5},
dims = 2,
}
local noise = mgnm:noise(noise_params) or mgnm:auto(noise_params)
minetest.register_on_generated(function(minp,maxp)
noise:init(minp)
noise[noise:index(x,y,z)]
end)
local ore_noise = {
coal = nil, -- NoiseDef
iron = nil, -- NoiseDef
}
local ores = mgnm:group(ore_noise)
local world_noise = {
coal = ore_noise.coal,
sand = nil,
}
local world = mgnm:group(world_noise)
local all = {
world = world_noise,
ores = ores,
}
all = mgnm:group(all) or mgnm:auto(all)
minetest.register_on_generated(function(minp,maxp)
ores:init(minp)
ores.coal[ores.coal:index(x,y,z)]
world:init(minp)
world.ores.coal[world.ores.coal:index(x,y,z)]
end)
local vmanip = mgnm:vmanip()
minetest.register_on_generated(function(minp,maxp)
local emin,emax = vmanip:init()
vmanip:get_data()
vmanip.data[vmanip:index(x,y,z)]
vmanip:set_lighting()
vmanip.vmanip:set_lighting()
vmanip:set_data()
-- Cleanup ANY used tables
vmanip:tini()
end)
local caves = {
noise1 = nil, -- NoiseDef
noise2 = nil, -- NoiseDef
combiner = function(self,noises) -- Function
for i,v in ipairs(noises.noise1) do
self[i] = noises.noise1[i] + noises.noise2[i]
end
end,
size = mgnm.mapchunk_size, -- Size
dims = 2,
}
local limited_caves = {
caves = caves,
limits = nil, -- NoiseDef
combiner = nil,
size = mgnm.emerge_size,
dims = 3,
}
mgnm:combine(limited_caves) or mgnm:auto(limited_caves)
minetest.register_on_generated(function(minp,maxp)
limited_caves:init(minp)
limited_caves[index]
end)
This mod allows for all created noises to be scaled, to help view/test large scale noises.
Spoiler
-- Download: https://github.com/Qwertymine/mgmini/archive/master.zip
-- Github: https://github.com/Qwertymine/mgmini
Use:
Code: Select all
-- Call before any perlin noises have been initialised
mgmini:minify({x=15,y=2,z=15})
local noisedef = {
--REQUIRED FIELDS
octaves = 3,
lacunarity = 2.0,
persistance = 0.5,
spread = {x=350,y=350,z=350},
offset = 2,
scale = 1, -- etc
-- Dimensions must be added to the noise def to allow correct scaling of 2D noise
dims = 2,
}
local noise = minetest.get_perlin_map(noisedef)
For 2D noises x divides x, y divides the noise scale and z divides y (and the unused z).
This mod modifies a noise definition, such that the resulting noise has a range of +-noise.scale.
Spoiler
-- Download: https://github.com/Qwertymine/nlnoise/a ... master.zip
-- Github: https://github.com/Qwertymine/nlnoise
Use:
Code: Select all
local noise_def = nlnoise.normalise{
-- REQUIRED DEF FIELDS
octaves = 3,
persistance = 0.5,
scale = 1, -- etc
}
local noise = minetest.get_perlin(noise_def)
-- or
noise = nlnoise.get_perlin{
-- REQUIRED DEF FIELDS
octaves = 3,
persistance = 0.5,
scale = 1, -- etc
}