]> git.lizzy.rs Git - Crafter.git/blob - mods/aether/biomes.lua
Fix A LOT of things
[Crafter.git] / mods / aether / biomes.lua
1
2 minetest.register_biome({
3         name = "aether",
4         node_top = "air",
5         depth_top = 1,
6         node_filler = "air",
7         depth_filler = 3,
8         node_riverbed = "air",
9         depth_riverbed= 0,
10         node_stone = "air",
11         node_water = "air",
12         node_dungeon = "air",
13         node_dungeon_alt = "air",
14         node_dungeon_stair = "air",
15         node_cave_liquid = "air",
16         vertical_blend = 0,
17         y_max = 31000,
18         y_min = 21000,
19         heat_point = -100,
20         humidity_point = -100,
21 })
22
23 --this is from https://github.com/paramat/lvm_example/blob/master/init.lua
24 --hi paramat :D
25
26 -- Set the 3D noise parameters for the terrain.
27 local np_terrain = {
28         offset = 0,
29         scale = 1,
30         spread = {x = 200, y = 100, z = 200},
31         seed = tonumber(minetest.get_mapgen_setting("seed")) or math.random(0,999999999),
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_dirt = minetest.get_content_id("aether:dirt")
49 local c_stone = minetest.get_content_id("aether:stone")
50 local c_air = minetest.get_content_id("air")
51 local c_grass = minetest.get_content_id("aether:grass")
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 local n_pos = {}
72
73 local node2 = ""
74
75 local vi = {}
76
77 local content_id = minetest.get_name_from_content_id
78
79 -- On generated function.
80
81 -- 'minp' and 'maxp' are the minimum and maximum positions of the mapchunk that
82 -- define the 3D volume.
83 minetest.register_on_generated(function(minp, maxp, seed)
84         --nether starts at -10033 y
85         if minp.y < 21000 then
86                 return
87         end
88         -- Start time of mapchunk generation.
89         --local t0 = os.clock()
90         
91         -- Noise stuff.
92
93         -- Side length of mapchunk.
94         local sidelen = maxp.x - minp.x + 1
95         -- Required dimensions of the 3D noise perlin map.
96         local permapdims3d = {x = sidelen, y = sidelen, z = sidelen}
97         -- Create the perlin map noise object once only, during the generation of
98         -- the first mapchunk when 'nobj_terrain' is 'nil'.
99         nobj_terrain = minetest.get_perlin_map(np_terrain, permapdims3d) --nobj_terrain or 
100         -- Create a flat array of noise values from the perlin map, with the
101         -- minimum point being 'minp'.
102         -- Set the buffer parameter to use and reuse 'nvals_terrain' for this.
103         nobj_terrain:get3dMap_flat(minp, nvals_terrain)
104
105         -- Voxelmanip stuff.
106
107         -- Load the voxelmanip with the result of engine mapgen. Since 'singlenode'
108         -- mapgen is used this will be a mapchunk of air nodes.
109         local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
110         -- 'area' is used later to get the voxelmanip indexes for positions.
111         local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
112         -- Get the content ID data from the voxelmanip in the form of a flat array.
113         -- Set the buffer parameter to use and reuse 'data' for this.
114         vm:get_data(data)
115
116         -- Generation loop.
117
118         -- Noise index for the flat array of noise values.
119         local ni = 1
120         -- Process the content IDs in 'data'.
121         -- The most useful order is a ZYX loop because:
122         -- 1. This matches the order of the 3D noise flat array.
123         -- 2. This allows a simple +1 incrementing of the voxelmanip index along x
124         -- rows.
125         -- rows.
126         for z = minp.z, maxp.z do
127         for y = minp.y, maxp.y do
128                 -- Voxelmanip index for the flat array of content IDs.
129                 -- Initialise to first node in this x row.
130                 vi = area:index(minp.x, y, z)
131                 for x = minp.x, maxp.x do
132                         -- Consider a 'solidness' value for each node,
133                         -- let's call it 'density', where
134                         -- density = density noise + density gradient.
135                         local density_noise = nvals_terrain[ni]
136                         -- Density gradient is a value that is 0 at water level (y = 1)
137                         -- and falls in value with increasing y. This is necessary to
138                         -- create a 'world surface' with only solid nodes deep underground
139                         -- and only air high above water level.
140                         -- Here '128' determines the typical maximum height of the terrain.
141                         
142                         
143                         --print(density_noise, density_gradient)
144                         -- Place solid nodes when 'density' > 0.
145                         --if density_noise + density_gradient > 0 then
146                         
147                         --print(density_noise + density_gradient)
148                         if density_noise > 0.1 then
149                                 data[vi] = c_dirt
150                         else
151                                 --force create grass
152                                 n_pos = area:index(x,y-1,z)
153                                 node2 = content_id(data[n_pos])
154                                 if node2 == "aether:dirt" then
155                                         data[n_pos] = c_grass
156                                 end
157                         end
158                         -- Otherwise if at or below water level place water.
159                         --elseif y == -10033 then
160                                 --data[vi] = c_bedrock
161                         --elseif y <= 1 then
162                         --      data[vi] = c_water
163                         --elseif y > -15000 then
164                         --      data[vi] = c_air
165                         --else
166                                 --data[vi] = c_lava
167                         --end
168                         
169                         -- Increment noise index.
170                         ni = ni + 1
171                         -- Increment voxelmanip index along x row.
172                         -- The voxelmanip index increases by 1 when
173                         -- moving by 1 node in the +x direction.
174                         vi = vi + 1
175                 end
176         end
177         end
178
179         -- After processing, write content ID data back to the voxelmanip.
180         
181         vm:set_data(data)
182         -- Calculate lighting for what has been created.
183         --vm:calc_lighting()
184         vm:set_lighting({day=15,night=0}, minp, maxp)
185         --minetest.generate_ores(vm)
186         
187         --minetest.generate_decorations(vm)
188         -- Write what has been created to the world.
189         vm:write_to_map()
190                 
191                 
192         -- Liquid nodes were placed so set them flowing.
193         --vm:update_liquids()
194
195         -- Print generation time of this mapchunk.
196         --local chugent = math.ceil((os.clock() - t0) * 1000)
197         --print ("[lvm_example] Mapchunk generation time " .. chugent .. " ms")
198 end)