]> git.lizzy.rs Git - Crafter.git/blob - mods/nether/biomes.lua
encapsulate the nether with bedrock
[Crafter.git] / mods / nether / biomes.lua
1 minetest.register_biome({
2         name = "Nether",
3         node_top = "air",
4         depth_top = 0,
5         node_filler = "air",
6         depth_filler = 0,
7         node_riverbed = "air",
8         depth_riverbed= 0,
9         node_stone = "air",
10         node_water = nil,
11         node_dungeon = "air",
12         node_dungeon_alt = "air",
13         node_dungeon_stair = "air",
14         vertical_blend = 0,
15         y_max = -10033,
16         y_min = -20113,
17         heat_point = -100,
18         humidity_point = -100,
19 })
20
21
22 --this is from https://github.com/paramat/lvm_example/blob/master/init.lua
23 --hi paramat :D
24
25 -- Set the 3D noise parameters for the terrain.
26 local perlin= minetest.get_mapgen_params()
27 local np_terrain = {
28         offset = 0,
29         scale = 1,
30         spread = {x = 384, y = 192, z = 384},
31         seed = 5900033, --perlin.seed
32         octaves = 5,
33         persist = 0.63,
34         lacunarity = 2.0,
35         --flags = ""
36 }
37
38
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.
42
43 --minetest.set_mapgen_params({mgname = "singlenode", flags = "nolight"})
44
45
46 -- Get the content IDs for the nodes used.
47
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")
52
53
54 -- Initialize noise object to nil. It will be created once only during the
55 -- generation of the first mapchunk, to minimise memory use.
56
57 local nobj_terrain = nil
58
59
60 -- Localise noise buffer table outside the loop, to be re-used for all
61 -- mapchunks, therefore minimising memory use.
62
63 local nvals_terrain = {}
64
65
66 -- Localise data buffer table outside the loop, to be re-used for all
67 -- mapchunks, therefore minimising memory use.
68
69 local data = {}
70
71
72 -- On generated function.
73
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
79                 return
80         end
81         -- Start time of mapchunk generation.
82         --local t0 = os.clock()
83         
84         -- Noise stuff.
85
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)
97
98         -- Voxelmanip stuff.
99
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.
107         vm:get_data(data)
108
109         -- Generation loop.
110
111         -- Noise index for the flat array of noise values.
112         local ni = 1
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
117         -- rows.
118         -- rows.
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
135                         
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
143                                 data[vi] = c_bedrock
144                         --elseif y <= 1 then
145                         --      data[vi] = c_water
146                         elseif y > -15000 then
147                                 data[vi] = c_air
148                         else
149                                 data[vi] = c_lava
150                         end
151
152                         -- Increment noise index.
153                         ni = ni + 1
154                         -- Increment voxelmanip index along x row.
155                         -- The voxelmanip index increases by 1 when
156                         -- moving by 1 node in the +x direction.
157                         vi = vi + 1
158                 end
159         end
160         end
161
162         -- After processing, write content ID data back to the voxelmanip.
163         vm:set_data(data)
164         -- Calculate lighting for what has been created.
165         --vm:calc_lighting()
166         
167         minetest.generate_ores(vm)
168         
169         vm:set_lighting({day=7,night=7}, minp, maxp)
170         
171         -- Write what has been created to the world.
172         vm:write_to_map()
173         -- Liquid nodes were placed so set them flowing.
174         --vm:update_liquids()
175
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")
179 end)