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