]> git.lizzy.rs Git - Crafter.git/blob - mods/aether/biomes.lua
Add in Aether Glowstone Portals
[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 perlin= minetest.get_mapgen_params()
28 local np_terrain = {
29         offset = 0,
30         scale = 1,
31         spread = {x = 200, y = 100, z = 200},
32         seed = 5900033, --perlin.seed
33         octaves = 5,
34         persist = 0.63,
35         lacunarity = 2.0,
36         --flags = ""
37 }
38
39
40 -- Set singlenode mapgen (air nodes only).
41 -- Disable the engine lighting calculation since that will be done for a
42 -- mapchunk of air nodes and will be incorrect after we place nodes.
43
44 --minetest.set_mapgen_params({mgname = "singlenode", flags = "nolight"})
45
46
47 -- Get the content IDs for the nodes used.
48
49 local c_dirt = minetest.get_content_id("aether:dirt")
50 local c_stone = minetest.get_content_id("aether:stone")
51 local c_air = minetest.get_content_id("air")
52 local c_grass = minetest.get_content_id("aether:grass")
53
54
55 -- Initialize noise object to nil. It will be created once only during the
56 -- generation of the first mapchunk, to minimise memory use.
57
58 local nobj_terrain = nil
59
60
61 -- Localise noise buffer table outside the loop, to be re-used for all
62 -- mapchunks, therefore minimising memory use.
63
64 local nvals_terrain = {}
65
66
67 -- Localise data buffer table outside the loop, to be re-used for all
68 -- mapchunks, therefore minimising memory use.
69
70 local data = {}
71
72 local n_pos = {}
73
74 local node2 = ""
75
76 local vi = {}
77
78 local content_id = minetest.get_name_from_content_id
79
80 -- On generated function.
81
82 -- 'minp' and 'maxp' are the minimum and maximum positions of the mapchunk that
83 -- define the 3D volume.
84 minetest.register_on_generated(function(minp, maxp, seed)
85         --nether starts at -10033 y
86         if minp.y < 21000 then
87                 return
88         end
89         -- Start time of mapchunk generation.
90         --local t0 = os.clock()
91         
92         -- Noise stuff.
93
94         -- Side length of mapchunk.
95         local sidelen = maxp.x - minp.x + 1
96         -- Required dimensions of the 3D noise perlin map.
97         local permapdims3d = {x = sidelen, y = sidelen, z = sidelen}
98         -- Create the perlin map noise object once only, during the generation of
99         -- the first mapchunk when 'nobj_terrain' is 'nil'.
100         nobj_terrain = minetest.get_perlin_map(np_terrain, permapdims3d) --nobj_terrain or 
101         -- Create a flat array of noise values from the perlin map, with the
102         -- minimum point being 'minp'.
103         -- Set the buffer parameter to use and reuse 'nvals_terrain' for this.
104         nobj_terrain:get3dMap_flat(minp, nvals_terrain)
105
106         -- Voxelmanip stuff.
107
108         -- Load the voxelmanip with the result of engine mapgen. Since 'singlenode'
109         -- mapgen is used this will be a mapchunk of air nodes.
110         local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
111         -- 'area' is used later to get the voxelmanip indexes for positions.
112         local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
113         -- Get the content ID data from the voxelmanip in the form of a flat array.
114         -- Set the buffer parameter to use and reuse 'data' for this.
115         vm:get_data(data)
116
117         -- Generation loop.
118
119         -- Noise index for the flat array of noise values.
120         local ni = 1
121         -- Process the content IDs in 'data'.
122         -- The most useful order is a ZYX loop because:
123         -- 1. This matches the order of the 3D noise flat array.
124         -- 2. This allows a simple +1 incrementing of the voxelmanip index along x
125         -- rows.
126         -- rows.
127         for z = minp.z, maxp.z do
128         for y = minp.y, maxp.y do
129                 -- Voxelmanip index for the flat array of content IDs.
130                 -- Initialise to first node in this x row.
131                 vi = area:index(minp.x, y, z)
132                 for x = minp.x, maxp.x do
133                         -- Consider a 'solidness' value for each node,
134                         -- let's call it 'density', where
135                         -- density = density noise + density gradient.
136                         local density_noise = nvals_terrain[ni]
137                         -- Density gradient is a value that is 0 at water level (y = 1)
138                         -- and falls in value with increasing y. This is necessary to
139                         -- create a 'world surface' with only solid nodes deep underground
140                         -- and only air high above water level.
141                         -- Here '128' determines the typical maximum height of the terrain.
142                         
143                         
144                         --print(density_noise, density_gradient)
145                         -- Place solid nodes when 'density' > 0.
146                         --if density_noise + density_gradient > 0 then
147                         
148                         --print(density_noise + density_gradient)
149                         if density_noise > 0.1 then
150                                 data[vi] = c_dirt
151                         else
152                                 --force create grass
153                                 n_pos = area:index(x,y-1,z)
154                                 node2 = content_id(data[n_pos])
155                                 if node2 == "aether:dirt" then
156                                         data[n_pos] = c_grass
157                                 end
158                         end
159                         -- Otherwise if at or below water level place water.
160                         --elseif y == -10033 then
161                                 --data[vi] = c_bedrock
162                         --elseif y <= 1 then
163                         --      data[vi] = c_water
164                         --elseif y > -15000 then
165                         --      data[vi] = c_air
166                         --else
167                                 --data[vi] = c_lava
168                         --end
169                         
170                         -- Increment noise index.
171                         ni = ni + 1
172                         -- Increment voxelmanip index along x row.
173                         -- The voxelmanip index increases by 1 when
174                         -- moving by 1 node in the +x direction.
175                         vi = vi + 1
176                 end
177         end
178         end
179
180         -- After processing, write content ID data back to the voxelmanip.
181         
182         vm:set_data(data)
183         -- Calculate lighting for what has been created.
184         --vm:calc_lighting()
185         vm:set_lighting({day=15,night=0}, minp, maxp)
186         --minetest.generate_ores(vm)
187         
188         --minetest.generate_decorations(vm)
189         -- Write what has been created to the world.
190         vm:write_to_map()
191                 
192                 
193         -- Liquid nodes were placed so set them flowing.
194         --vm:update_liquids()
195
196         -- Print generation time of this mapchunk.
197         --local chugent = math.ceil((os.clock() - t0) * 1000)
198         --print ("[lvm_example] Mapchunk generation time " .. chugent .. " ms")
199 end)