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