12 KiB
global MapGen
methods
MapGen.new
function MapGen.new(def: MapGenDef {
nodes = table<string,string>,
}) -> MapGen {
layersByName = table<string,MapGen.Layer>,
layersList = MapGen.Layer[],
staticsByName = table<string,MapGen.StaticLayer>,
staticsList = MapGen.StaticLayer[],
layersNoisesInitialized = boolean,
cavernsNoiseInitialized = boolean,
isRunning = boolean,
nodeIDs = table<string,number>,
new = function,
getLayerByHeight = function,
getStaticByHeight = function,
registerLayer = function,
registerLayerNoiseColor = function,
registerStaticLayer = function,
registerPeak = function,
register2DPeak = function,
register2DPeaks = function,
register2DPeaksFromFile = function,
registerBiome = function,
registerCavern = function,
initLayersTriangultaion = function,
initLayersNoises = function,
initBiomesDiagram = function,
initCavernsNoise = function,
getNoises2dValue = function,
onMapGenerated = function,
run = function,
}
MapGen.getLayerByHeight
function MapGen.getLayerByHeight(yPos: number) -> MapGen.Layer?
Determines which layer a node belongs to based on its height coordinate.
MapGen.getStaticByHeight
function MapGen.getStaticByHeight(yPos: number) -> MapGen.StaticLayer?
Determines which statics layer a node belongs to based on its height coordinate.
MapGen.registerLayer
function MapGen.registerLayer(
name: string,
def: MapGen.LayerDef {
minY = number,
maxY = number,
minTemp = number,
maxTemp = number,
minHumidity = number,
maxHumidity = number,
waterLevel = number?,
calcTemp = (fun(self: MapGen.Layer, value: number, height: number) -> number)?,
calcHumidity = (fun(self: MapGen.Layer, value: number, height: number) -> number)?,
biomesGorizontalScattering = number?,
biomesVerticalScattering = number?,
}
) -> nil
@param name - The name that will be assigned to the layer. The name must be unique for each layer.
@param def - Layer description table, see details MapGen.LayerDef.
Mark the world area between two heights as a MapGen.Layer.
Note: layers must not overlap.
MapGen.registerLayerNoiseColor
function MapGen.registerLayerNoiseColor(
layerName: string,
category: MapGen.Layer.Category,
color: ColorString,
noiseParams: NoiseParams
) -> nil
@param layerName - The name of the layer for which the color will be registered.
@param category - Category indicating what will be generated by noise.
@param color - Noise color. Must be unique.
@param noiseParams - Fractal noise parameters.
Register the color and the noise parameters that correspond to it.
MapGen.registerStaticLayer
function MapGen.registerStaticLayer(
name: string,
def: MapGen.StaticLayerDef {
minY = number,
maxY = number,
staticNode = string,
generateStaticNode = generateFunc,
}
) -> nil
@param name - The name that will be assigned to the static layer. The name must be unique for each layer.
@param def - Static layer description table, see details MapGen.StaticLayerDef.
Mark the world area between two heights as a MapGen.StaticLayer.
Note: layers must not overlap.
MapGen.registerPeak
function MapGen.registerPeak(
layerName: string,
category: MapGen.Layer.Category,
def: MapGen.PeakDef {
pos = vector,
color = ColorString,
groups = table<string,number>?,
}
) -> nil
@param layerName - The name of the layer in which the new peak will be included.
@param category - Category indicating what will be generated by peak.
@param def - Peak description table, see details MapGen.PeakDef.
Mark a world point as MapGen.Peak and assign it a specific color that will affect the generation.
Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
MapGen.register2DPeak
function MapGen.register2DPeak(
layerName: string,
category: MapGen.Layer.Category,
def: MapGen.PeakDef {
pos = vector,
color = ColorString,
groups = table<string,number>?,
}
) -> nil
@param layerName - The name of the layer in which the new peak will be included.
@param category - Category indicating what will be generated by peak.
@param def - Peak description table, see details MapGen.PeakDef.
Mark a world point as MapGen.Peak and assign it a specific color that will affect the generation.
The Y coordinate will be forced to zero, and the is2d group will be added to the groups field.
Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
MapGen.register2DPeaks
function MapGen.register2DPeaks(
layerName: string,
category: MapGen.Layer.Category,
defs: MapGen.PeakDef[]
) -> nil
@param layerName - The name of the layer in which the new peaks will be included.
@param category - Category indicating what will be generated by peaks.
@param defs - Peaks description table, see details MapGen.PeakDef.
Mark the world points as MapGen.Peak and assign them all a specific noise that will affect generation.
The Y coordinate will be forced to zero, and the is2d group will be added to the groups field.
Note: The peaks shouldn't overlap. This won't cause any errors, but it might ruin the generation.
MapGen.register2DPeaksFromFile
function MapGen.register2DPeaksFromFile(
layerName: string,
map: string,
scale: number,
zeroPos: Position2d,
category: MapGen.Layer.Category,
groups: table<string,number>?
) -> nil
@param layerName - The name of the layer in which the new peaks will be included.
@param map - The name of the image from which the peaks will be extracted. It should be located in the <mod_name>/textures/maps folder and have the following format <image_name>.ff
@param scale - Multiplier of how many blocks (nodes) will be between image pixels. It is not recommended to set the value below 50 for performance reasons.
@param zeroPos - The position in pixels where the zero world coordinate will be in the image.
@param category - Category indicating what will be generated by peaks.
@param groups - Groups that will be added to all peaks.
Extract the MapGen.Peak from the image and assign them all a specific color that will affect the generation.
MapGen.registerBiome
function MapGen.registerBiome(
layerName: string,
biomeName: string,
def: MapGen.BiomeDef {
tempPoint = number,
humidityPoint = number,
minY = number,
maxY = number,
groundNodes = MapGen.Biome.GroundNodes,
soilHeight = number,
generateAir = generateFunc?,
generateCavernAir = generateFunc?,
generateWater = generateFunc?,
generateRock = generateFunc?,
generateTurf = generateFunc?,
generateSoil = generateFunc?,
generateBottom = generateFunc?,
}
) -> nil
@param layerName - The name of the layer in which the new biome will be included.
@param biomeName - The name to be assigned to the biome. The name must be unique for each biome.
@param def - Biome description table, see details MapGen.BiomeDef
Mark a point on the biomes diagram and constrain the world area by height to mark it as MapGen.Biome.
MapGen.registerCavern
function MapGen.registerCavern(
layerName: string,
cavernName: string,
def: MapGen.CavernDef {
minY = number,
maxY = number,
noiseParams = NoiseParams,
smoothDistance = number,
threshold = number?,
groups = table<string,number>?,
}
) -> nil
@param layerName - The name of the layer in which the new cavern will be included.
@param cavernName - The name to be assigned to the cavern. The name must be unique for each cavern.
@param def - Cavern description table, see details MapGen.CavernDef
Mark the world area between two heights as a MapGen.Cavern and assign the noise that the cave will be generated from.
MapGen.initLayersTriangultaion
function MapGen.initLayersTriangultaion() -> nil
Divide all layers into triangles whose vertices are the Mapgen.Peak belonging to these layers.
MapGen.initLayersNoises
function MapGen.initLayersNoises() -> nil
Initialize all layer noises. This should be called after the map object is loaded.
MapGen.initBiomesDiagram
function MapGen.initBiomesDiagram() -> nil
Initialization of the biome diagram using the Voronoi method.
MapGen.initCavernsNoise
function MapGen.initCavernsNoise() -> nil
Initialize caverns's noises. This should be called after the map object is loaded.
MapGen.getNoises2dValue
function MapGen.getNoises2dValue(
category: MapGen.Layer.Category,
layer: MapGen.Layer {
name = string,
minY = integer,
maxY = integer,
minTemp = integer,
maxTemp = integer,
minHumidity = integer,
maxHumidity = integer,
waterLevel = integer,
peaksList = { humidity: MapGen.Peak[], landscape: MapGen.Peak[], temp: MapGen.Peak[] },
noisesByColor = { humidity: table<ColorString,ValueNoise>, landscape: table<ColorString,ValueNoise>, temp: table<ColorString,ValueNoise> },
noisesParamsByColor = { humidity: table<ColorString,NoiseParams>, landscape: table<ColorString,NoiseParams>, temp: table<ColorString,NoiseParams> },
biomesByName = table<string,MapGen.Biome>,
biomesList = MapGen.Biome[],
biomesDiagram = table,
biomesGorizontalScattering = integer,
biomesVerticalScattering = integer,
cavernsByName = table<string,MapGen.Cavern>,
cavernsList = MapGen.Cavern[],
trianglesList = { humidity: MapGen.Triangle[], landscape: MapGen.Triangle[], temp: MapGen.Triangle[] },
tetrahedronsList = MapGen.Tetrahedron[],
calcTemp = function,
calcHumidity = function,
new = function,
addPeak = function,
addNoiseParamsColor = function,
getNoiseByColor = function,
addBiome = function,
addCavern = function,
initNoises = function,
initBiomesDiagram = function,
},
x: integer,
y: integer,
z: integer
) -> number?
Calculates a smoothed 2D noise value based on a preliminary space partitioning.
Returns nil if the point is not included in any triangle.
MapGen.onMapGenerated
function MapGen.onMapGenerated(
voxelManip: VoxelManip,
minPos: Position,
maxPos: Position,
blockseed: number
) -> nil
Chunk generation handler.
MapGen.run
function MapGen.run() -> nil
Run world generation through this mapgen object
Note: only one instance of a MapGen class can be running.
FOR MAPGEN ENVIRONMENT ONLY
fields
MapGen.layersByName
MapGen.layersByName : table<string,MapGen.Layer>
MapGen.layersList
MapGen.layersList : MapGen.Layer[]
MapGen.staticsByName
MapGen.staticsByName : table<string,MapGen.StaticLayer>
MapGen.staticsList
MapGen.staticsList : MapGen.StaticLayer[]
MapGen.layersNoisesInitialized
MapGen.layersNoisesInitialized : boolean
Is the fractal noise of the layer initialized? This is necessary for a one-time noise initialization.
MapGen.cavernsNoiseInitialized
MapGen.cavernsNoiseInitialized : boolean
Is the fractal noise of the caverns initialized? This is necessary for a one-time noise initialization.
MapGen.isRunning
MapGen.isRunning : boolean
A static field that guarantees that only one instance of the MapGen class will work.
MapGen.nodeIDs
MapGen.nodeIDs : table<string,number>