1 local path = minetest.get_modpath("void")
2 dofile(path.."/nodes.lua")
4 minetest.register_biome({
10 node_riverbed = "air",
12 node_cave_liquid = "air",
16 node_dungeon_alt = "air",
17 node_dungeon_stair = "air",
22 humidity_point = -100,
25 --this is from https://github.com/paramat/lvm_example/blob/master/init.lua
28 -- Set the 3D noise parameters for the terrain.
29 local perlin= minetest.get_mapgen_params()
33 spread = {x = 100, y = 50, z = 100},
34 seed = 5900033, --perlin.seed
42 -- Set singlenode mapgen (air nodes only).
43 -- Disable the engine lighting calculation since that will be done for a
44 -- mapchunk of air nodes and will be incorrect after we place nodes.
46 --minetest.set_mapgen_params({mgname = "singlenode", flags = "nolight"})
49 -- Get the content IDs for the nodes used.
51 local c_stone = minetest.get_content_id("nether:bedrock")
52 local c_air = minetest.get_content_id("air")
53 local c_grass = minetest.get_content_id("main:grass")
56 -- Initialize noise object to nil. It will be created once only during the
57 -- generation of the first mapchunk, to minimise memory use.
59 local nobj_terrain = nil
62 -- Localise noise buffer table outside the loop, to be re-used for all
63 -- mapchunks, therefore minimising memory use.
65 local nvals_terrain = {}
68 -- Localise data buffer table outside the loop, to be re-used for all
69 -- mapchunks, therefore minimising memory use.
79 local content_id = minetest.get_name_from_content_id
81 -- On generated function.
83 -- 'minp' and 'maxp' are the minimum and maximum positions of the mapchunk that
84 -- define the 3D volume.
85 minetest.register_on_generated(function(minp, maxp, seed)
86 --nether starts at -10033 y
88 if maxp.y > -20113 then
91 -- Start time of mapchunk generation.
92 --local t0 = os.clock()
96 -- Side length of mapchunk.
97 local sidelen = maxp.x - minp.x + 1
98 -- Required dimensions of the 3D noise perlin map.
99 local permapdims3d = {x = sidelen, y = sidelen, z = sidelen}
100 -- Create the perlin map noise object once only, during the generation of
101 -- the first mapchunk when 'nobj_terrain' is 'nil'.
102 nobj_terrain = minetest.get_perlin_map(np_terrain, permapdims3d) --nobj_terrain or
103 -- Create a flat array of noise values from the perlin map, with the
104 -- minimum point being 'minp'.
105 -- Set the buffer parameter to use and reuse 'nvals_terrain' for this.
106 nobj_terrain:get3dMap_flat(minp, nvals_terrain)
110 -- Load the voxelmanip with the result of engine mapgen. Since 'singlenode'
111 -- mapgen is used this will be a mapchunk of air nodes.
112 local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
113 -- 'area' is used later to get the voxelmanip indexes for positions.
114 local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
115 -- Get the content ID data from the voxelmanip in the form of a flat array.
116 -- Set the buffer parameter to use and reuse 'data' for this.
121 -- Noise index for the flat array of noise values.
123 -- Process the content IDs in 'data'.
124 -- The most useful order is a ZYX loop because:
125 -- 1. This matches the order of the 3D noise flat array.
126 -- 2. This allows a simple +1 incrementing of the voxelmanip index along x
129 for z = minp.z, maxp.z do
130 for y = minp.y, maxp.y do
131 -- Voxelmanip index for the flat array of content IDs.
132 -- Initialise to first node in this x row.
133 vi = area:index(minp.x, y, z)
134 for x = minp.x, maxp.x do
135 -- Consider a 'solidness' value for each node,
136 -- let's call it 'density', where
137 -- density = density noise + density gradient.
138 local density_noise = nvals_terrain[ni]
139 -- Density gradient is a value that is 0 at water level (y = 1)
140 -- and falls in value with increasing y. This is necessary to
141 -- create a 'world surface' with only solid nodes deep underground
142 -- and only air high above water level.
143 -- Here '128' determines the typical maximum height of the terrain.
146 --print(density_noise, density_gradient)
147 -- Place solid nodes when 'density' > 0.
148 --if density_noise + density_gradient > 0 then
150 --print(density_noise + density_gradient)
151 if density_noise > 0.1 then
155 -- n_pos = area:index(x,y-1,z)
156 -- node2 = content_id(data[n_pos])
157 -- if node2 == "aether:dirt" then
158 -- data[n_pos] = c_grass
161 -- Otherwise if at or below water level place water.
162 --elseif y == -10033 then
163 --data[vi] = c_bedrock
165 -- data[vi] = c_water
166 --elseif y > -15000 then
172 -- Increment noise index.
174 -- Increment voxelmanip index along x row.
175 -- The voxelmanip index increases by 1 when
176 -- moving by 1 node in the +x direction.
182 -- After processing, write content ID data back to the voxelmanip.
185 -- Calculate lighting for what has been created.
187 vm:set_lighting({day=15,night=0}, minp, maxp)
188 --minetest.generate_ores(vm)
190 --minetest.generate_decorations(vm)
191 -- Write what has been created to the world.
195 -- Liquid nodes were placed so set them flowing.
196 --vm:update_liquids()
198 -- Print generation time of this mapchunk.
199 --local chugent = math.ceil((os.clock() - t0) * 1000)
200 --print ("[lvm_example] Mapchunk generation time " .. chugent .. " ms")