]> git.lizzy.rs Git - Crafter.git/blob - mods/nether/biomes.lua
95ab047aaf8b8e8978cdcf5237ebc626e6856a9f
[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_cave_liquid = "air",
10         node_stone = "air",
11         node_water = nil,
12         node_dungeon = "air",
13         node_dungeon_alt = "air",
14         node_dungeon_stair = "air",
15         vertical_blend = 0,
16         y_max = -10033,
17         y_min = -20113,
18         heat_point = -100,
19         humidity_point = -100,
20 })
21
22 --[[
23 minetest.register_decoration({
24         name = "Nether Eternal Fire",
25         deco_type = "simple",
26         place_on = {"nether:netherrack"},
27         sidelen = 16,
28         fill_ratio = 0.03,
29         biomes = {"Nether"},
30         y_max = -10033,
31         y_min = -15000,
32         decoration = "fire:fire",
33         height = 1,
34 })
35 ]]--
36
37 --this is from https://github.com/paramat/lvm_example/blob/master/init.lua
38 --hi paramat :D
39
40 -- Set the 3D noise parameters for the terrain.
41 local perlin= minetest.get_mapgen_params()
42 local np_terrain = {
43         offset = 0,
44         scale = 1,
45         spread = {x = 384, y = 192, z = 384},
46         seed = 5900033, --perlin.seed
47         octaves = 5,
48         persist = 0.63,
49         lacunarity = 2.0,
50         --flags = ""
51 }
52
53 minetest.register_decoration({
54         name = "nether:tree",
55         deco_type = "schematic",
56         place_on = {"nether:netherrack"},
57         sidelen = 16,
58         noise_params = {
59                 offset = 0.024,
60                 scale = 0.015,
61                 spread = {x = 250, y = 250, z = 250},
62                 seed = 2,
63                 octaves = 3,
64                 persist = 0.66
65         },
66         --biomes = {},
67         y_max = -10000,
68         y_min = -15000,
69         schematic = nethertreeSchematic,
70         flags = "place_center_x, place_center_z",
71         rotation = "random",
72         spawn_by = "air",
73         num_spawn_by = 1,
74 })
75
76
77
78 -- Set singlenode mapgen (air nodes only).
79 -- Disable the engine lighting calculation since that will be done for a
80 -- mapchunk of air nodes and will be incorrect after we place nodes.
81
82 --minetest.set_mapgen_params({mgname = "singlenode", flags = "nolight"})
83
84
85 -- Get the content IDs for the nodes used.
86
87 local c_sandstone = minetest.get_content_id("nether:netherrack")
88 local c_bedrock = minetest.get_content_id("nether:bedrock")
89 local c_air = minetest.get_content_id("air")
90 local c_lava = minetest.get_content_id("nether:lava")
91
92
93 -- Initialize noise object to nil. It will be created once only during the
94 -- generation of the first mapchunk, to minimise memory use.
95
96 local nobj_terrain = nil
97
98
99 -- Localise noise buffer table outside the loop, to be re-used for all
100 -- mapchunks, therefore minimising memory use.
101
102 local nvals_terrain = {}
103
104
105 -- Localise data buffer table outside the loop, to be re-used for all
106 -- mapchunks, therefore minimising memory use.
107
108 local data = {}
109
110
111 -- On generated function.
112
113 -- 'minp' and 'maxp' are the minimum and maximum positions of the mapchunk that
114 -- define the 3D volume.
115
116
117
118 local sidelen
119 local permapdims3d
120 local vm
121 local emin
122 local emax
123 local area
124 local vi
125 local density_noise
126 local density_gradient
127 minetest.register_on_generated(function(minp, maxp, seed)
128         --nether starts at -10033 y
129         if maxp.y > -10033 or maxp.y < -20033 then
130                 return
131         end
132         -- Start time of mapchunk generation.
133         --local t0 = os.clock()
134         
135         -- Noise stuff.
136
137         -- Side length of mapchunk.
138         sidelen = maxp.x - minp.x + 1
139         -- Required dimensions of the 3D noise perlin map.
140         permapdims3d = {x = sidelen, y = sidelen, z = sidelen}
141         -- Create the perlin map noise object once only, during the generation of
142         -- the first mapchunk when 'nobj_terrain' is 'nil'.
143         nobj_terrain = minetest.get_perlin_map(np_terrain, permapdims3d) --nobj_terrain or 
144         -- Create a flat array of noise values from the perlin map, with the
145         -- minimum point being 'minp'.
146         -- Set the buffer parameter to use and reuse 'nvals_terrain' for this.
147         nobj_terrain:get3dMap_flat(minp, nvals_terrain)
148
149         -- Voxelmanip stuff.
150
151         -- Load the voxelmanip with the result of engine mapgen. Since 'singlenode'
152         -- mapgen is used this will be a mapchunk of air nodes.
153         vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
154         -- 'area' is used later to get the voxelmanip indexes for positions.
155         area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
156         -- Get the content ID data from the voxelmanip in the form of a flat array.
157         -- Set the buffer parameter to use and reuse 'data' for this.
158         vm:get_data(data)
159
160         -- Generation loop.
161
162         -- Noise index for the flat array of noise values.
163         
164         -- Process the content IDs in 'data'.
165         -- The most useful order is a ZYX loop because:
166         -- 1. This matches the order of the 3D noise flat array.
167         -- 2. This allows a simple +1 incrementing of the voxelmanip index along x
168         -- rows.
169         -- rows.
170         
171         local ni = 1
172         for z = minp.z, maxp.z do
173         for y = minp.y, maxp.y do
174                 -- Voxelmanip index for the flat array of content IDs.
175                 -- Initialise to first node in this x row.
176                 vi = area:index(minp.x, y, z)
177                 for x = minp.x, maxp.x do
178                         -- Consider a 'solidness' value for each node,
179                         -- let's call it 'density', where
180                         -- density = density noise + density gradient.
181                         density_noise = nvals_terrain[ni]
182                         -- Density gradient is a value that is 0 at water level (y = 1)
183                         -- and falls in value with increasing y. This is necessary to
184                         -- create a 'world surface' with only solid nodes deep underground
185                         -- and only air high above water level.
186                         -- Here '128' determines the typical maximum height of the terrain.
187                         density_gradient = (1 - y) / 128
188                         
189                         --print(density_noise, density_gradient)
190                         -- Place solid nodes when 'density' > 0.
191                         --if density_noise + density_gradient > 0 then
192                         if density_noise > 0  and y ~= -10033 and y ~= -20112 then
193                                 data[vi] = c_sandstone
194                         -- create bedrock layer
195                         elseif y == -10033 or y == -20112 then
196                                 data[vi] = c_bedrock
197                         --elseif y <= 1 then
198                         --      data[vi] = c_water
199                         --elseif y > -15000 then
200                                 --data[vi] = c_air
201                         elseif y <= -15000 then
202                                 data[vi] = c_lava
203                         end
204
205                         -- Increment noise index.
206                         ni = ni + 1
207                         -- Increment voxelmanip index along x row.
208                         -- The voxelmanip index increases by 1 when
209                         -- moving by 1 node in the +x direction.
210                         vi = vi + 1
211                 end
212         end
213         end
214         
215         -- After processing, write content ID data back to the voxelmanip.
216         vm:set_data(data)
217         -- Calculate lighting for what has been created.
218         --vm:calc_lighting()
219         minetest.generate_ores(vm)
220         
221         minetest.generate_decorations(vm)
222         
223         --minetest.generate_decorations(vm)
224         vm:set_lighting({day=7,night=7}, minp, maxp)
225         
226         -- Write what has been created to the world.
227         vm:write_to_map()
228         -- Liquid nodes were placed so set them flowing.
229         --vm:update_liquids()
230
231         -- Print generation time of this mapchunk.
232         --local chugent = math.ceil((os.clock() - t0) * 1000)
233         --print ("[lvm_example] Mapchunk generation time " .. chugent .. " ms")
234 end)