1 minetest.register_biome({
12 node_dungeon_alt = "air",
13 node_dungeon_stair = "air",
18 humidity_point = -100,
22 --this is from https://github.com/paramat/lvm_example/blob/master/init.lua
25 -- Set the 3D noise parameters for the terrain.
26 local perlin= minetest.get_mapgen_params()
30 spread = {x = 384, y = 192, z = 384},
31 seed = 5900033, --perlin.seed
39 -- Set singlenode mapgen (air nodes only).
40 -- Disable the engine lighting calculation since that will be done for a
41 -- mapchunk of air nodes and will be incorrect after we place nodes.
43 --minetest.set_mapgen_params({mgname = "singlenode", flags = "nolight"})
46 -- Get the content IDs for the nodes used.
48 local c_sandstone = minetest.get_content_id("nether:netherrack")
49 local c_bedrock = minetest.get_content_id("nether:bedrock")
50 local c_air = minetest.get_content_id("air")
51 local c_lava = minetest.get_content_id("nether:lava")
54 -- Initialize noise object to nil. It will be created once only during the
55 -- generation of the first mapchunk, to minimise memory use.
57 local nobj_terrain = nil
60 -- Localise noise buffer table outside the loop, to be re-used for all
61 -- mapchunks, therefore minimising memory use.
63 local nvals_terrain = {}
66 -- Localise data buffer table outside the loop, to be re-used for all
67 -- mapchunks, therefore minimising memory use.
72 -- On generated function.
74 -- 'minp' and 'maxp' are the minimum and maximum positions of the mapchunk that
75 -- define the 3D volume.
76 minetest.register_on_generated(function(minp, maxp, seed)
77 --nether starts at -10033 y
78 if maxp.y > -10033 or maxp.y < -20033 then
81 -- Start time of mapchunk generation.
82 --local t0 = os.clock()
86 -- Side length of mapchunk.
87 local sidelen = maxp.x - minp.x + 1
88 -- Required dimensions of the 3D noise perlin map.
89 local permapdims3d = {x = sidelen, y = sidelen, z = sidelen}
90 -- Create the perlin map noise object once only, during the generation of
91 -- the first mapchunk when 'nobj_terrain' is 'nil'.
92 nobj_terrain = minetest.get_perlin_map(np_terrain, permapdims3d) --nobj_terrain or
93 -- Create a flat array of noise values from the perlin map, with the
94 -- minimum point being 'minp'.
95 -- Set the buffer parameter to use and reuse 'nvals_terrain' for this.
96 nobj_terrain:get3dMap_flat(minp, nvals_terrain)
100 -- Load the voxelmanip with the result of engine mapgen. Since 'singlenode'
101 -- mapgen is used this will be a mapchunk of air nodes.
102 local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
103 -- 'area' is used later to get the voxelmanip indexes for positions.
104 local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
105 -- Get the content ID data from the voxelmanip in the form of a flat array.
106 -- Set the buffer parameter to use and reuse 'data' for this.
111 -- Noise index for the flat array of noise values.
113 -- Process the content IDs in 'data'.
114 -- The most useful order is a ZYX loop because:
115 -- 1. This matches the order of the 3D noise flat array.
116 -- 2. This allows a simple +1 incrementing of the voxelmanip index along x
119 for z = minp.z, maxp.z do
120 for y = minp.y, maxp.y do
121 -- Voxelmanip index for the flat array of content IDs.
122 -- Initialise to first node in this x row.
123 local vi = area:index(minp.x, y, z)
124 for x = minp.x, maxp.x do
125 -- Consider a 'solidness' value for each node,
126 -- let's call it 'density', where
127 -- density = density noise + density gradient.
128 local density_noise = nvals_terrain[ni]
129 -- Density gradient is a value that is 0 at water level (y = 1)
130 -- and falls in value with increasing y. This is necessary to
131 -- create a 'world surface' with only solid nodes deep underground
132 -- and only air high above water level.
133 -- Here '128' determines the typical maximum height of the terrain.
134 local density_gradient = (1 - y) / 128
136 --print(density_noise, density_gradient)
137 -- Place solid nodes when 'density' > 0.
138 --if density_noise + density_gradient > 0 then
139 if density_noise > 0 and y ~= -10033 and y ~= -20112 then
140 data[vi] = c_sandstone
141 -- create bedrock layer
142 elseif y == -10033 or y == -20112 then
145 -- data[vi] = c_water
146 elseif y > -15000 then
152 -- Increment noise index.
154 -- Increment voxelmanip index along x row.
155 -- The voxelmanip index increases by 1 when
156 -- moving by 1 node in the +x direction.
162 -- After processing, write content ID data back to the voxelmanip.
164 -- Calculate lighting for what has been created.
167 minetest.generate_ores(vm)
169 vm:set_lighting({day=7,night=7}, minp, maxp)
171 -- Write what has been created to the world.
173 -- Liquid nodes were placed so set them flowing.
174 --vm:update_liquids()
176 -- Print generation time of this mapchunk.
177 --local chugent = math.ceil((os.clock() - t0) * 1000)
178 --print ("[lvm_example] Mapchunk generation time " .. chugent .. " ms")