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