﻿

# Riddles WG

a guest
Jul 7th, 2012
39
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. -- minetest/default/mapgen.lua
2.
3. --
4. -- Aliases for map generator outputs
5. --
6.
7. minetest.register_alias("mapgen_air", "air")
8. minetest.register_alias("mapgen_stone", "default:stone")
9. minetest.register_alias("mapgen_stone_with_gold", "mitchsmod:stone_with_gold")
10. minetest.register_alias("mapgen_stone_with_diamond", "mitchsmod:stone_with_diamond")
11. minetest.register_alias("mapgen_stone_with_obsidian", "mitchsmod:stone_with_obsidian")
12. -- Ore generation
13. --
14.
15. local function generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume, chunk_size, ore_per_chunk, height_min, height_max)
16.     if maxp.y < height_min or minp.y > height_max then
17.         return
18.     end
19.     local y_min = math.max(minp.y, height_min)
20.     local y_max = math.min(maxp.y, height_max)
21.     local volume = (maxp.x-minp.x+1)*(y_max-y_min+1)*(maxp.z-minp.z+1)
22.     local pr = PseudoRandom(seed)
23.     local num_chunks = math.floor(chunks_per_volume * volume)
24.     local inverse_chance = math.floor(chunk_size*chunk_size*chunk_size / ore_per_chunk)
25.     --print("generate_ore num_chunks: "..dump(num_chunks))
26.     for i=1,num_chunks do
27.         local y0 = pr:next(y_min, y_max-chunk_size+1)
28.         if y0 >= height_min and y0 <= height_max then
29.             local x0 = pr:next(minp.x, maxp.x-chunk_size+1)
30.             local z0 = pr:next(minp.z, maxp.z-chunk_size+1)
31.             local p0 = {x=x0, y=y0, z=z0}
32.             for x1=0,chunk_size-1 do
33.             for y1=0,chunk_size-1 do
34.             for z1=0,chunk_size-1 do
35.                 if pr:next(1,inverse_chance) == 1 then
36.                     local x2 = x0+x1
37.                     local y2 = y0+y1
38.                     local z2 = z0+z1
39.                     local p2 = {x=x2, y=y2, z=z2}
40.                     if minetest.env:get_node(p2).name == wherein then
41.                         minetest.env:set_node(p2, {name=name})
42.                     end
43.                 end
44.             end
45.             end
46.             end
47.         end
48.     end
49.     --print("generate_ore done")
50. end
51.
52. minetest.register_on_generated(function(minp, maxp, seed)
53.     -- Generate regular ores
54.
55.     generate_ore("mitchsmod:stone_with_gold", "default:stone", minp, maxp, seed+7, 1/24/24/24, 6,7, -31000,  64)
56.     generate_ore("mitchsmod:stone_with_diamond", "default:stone", minp, maxp, seed+7, 1/24/24/24, 6,7, -31000,  0)
57.     generate_ore("mitchsmod:stone_with_obsidian", "default:stone", minp, maxp, seed+6, 1/24/24/24, 6,6, -31000, -64)
58. end)
RAW Paste Data