Experiments with layers.
[rocks.git] / rocks / ign.lua
blobfe7ed417d165d2bc225e703509f6fc1c80adc047
1 --
2 -- Igneous Layer
3 --
5 -- Basalt Ex/Mafic hard same as diorite, byt limit=0.5
6 minetest.register_node( "rocks:basalt", {
7 description = S("Basalt"),
8 tiles = { "rocks_Basalt.png" },
9 groups = {cracky=3, stone=1},
10 is_ground_content = true, sounds = default.node_sound_stone_defaults(),
12 minetest.register_alias("mapgen_stone", "rocks:basalt")
14 -- ^ does not work. Seems we can not overwrite an alias.
15 -- If the alias in default/mapgen.lua is deleted, this works.
17 -- more rock defs
18 minetest.register_node( "rocks:granite", {
19 description = S("Granite"),
20 tiles = { "rocks_wgr.png" },
21 is_ground_content = true, sounds = default.node_sound_stone_defaults(),
22 groups = {cracky=3, stone=1},
24 minetest.register_node( "rocks:diorite", {
25 description = S("Diorite"),
26 tiles = { "rocks_Diorite.png" },
27 groups = {cracky=3, stone=1},
28 is_ground_content = true, sounds = default.node_sound_stone_defaults(),
30 minetest.register_node( "rocks:gabbro", {
31 description = S("Gabbro"),
32 tiles = { "rocks_Gabbro.png" },
33 groups = {cracky=3, stone=1},
34 is_ground_content = true, sounds = default.node_sound_stone_defaults(),
37 local reg=function(name,param)
38 minetest.register_ore({
39 ore = name,
40 wherein= param.inr,
41 ore_type = "scatter",
42 clust_scarcity = 10^3,
43 clust_num_ores = 20^3,
44 clust_size = 20,
45 height_min = -31000,
46 height_max = 28,
47 noise_threshhold=param.treshold,
48 noise_params={
49 offset = 0, scale = 1, octaves = 1, persist = 0.5,
50 spread = {x=param.spread, y=param.height, z=param.spread},
51 seed=rocksl.GetNextSeed(),
54 end
55 rocks.register_igneous_stratus=reg
57 -- vein stuff
59 local regv=function(name,param)
60 minetest.register_ore({
61 ore = name,
62 wherein= param.wherein,
63 ore_type = "blob",
64 clust_scarcity = param.rarity^3,
65 clust_num_ores = 8,
66 clust_size = param.radius.average*2,
67 height_min = -31000,
68 height_max = 50,
69 noise_threshhold = 0.5, --< determined experimentally
70 noise_params={
71 offset = 1-param.radius.amplitude, scale = param.radius.amplitude, octaves = 3, persist = 0.5,
72 spread = {x=param.radius.frequency, y=param.radius.frequency, z=param.radius.frequency},
73 seed=rocksl.GetNextSeed(),
76 end
78 rocks.register_vein=regv
80 local np_layer = {
81 offset = 0, octaves = 3, persist = 0.46,
82 scale = 30,
83 spread = {x=500, y=500, z=500},
84 seed = -5500,
86 local np_intr = {
87 octaves = 3, persist = 0.46,
88 scale = 20,
89 offset = -15,
90 spread = {x=100, y=100, z=100},
91 seed = 3740,
94 --minetest.register_on_generated( function( minp, maxp, seed )
95 rocksl.genign=function(minp,maxp,seed, vm, area)
96 local t1 = os.clock()
97 local data = vm:get_data()
99 local chunksize = maxp.x - minp.x + 1
100 local pmapsize = {x = chunksize, y = chunksize, z = 1}
101 local pmapminpxz = {x = minp.x, y = minp.z}
102 local c_stone= minetest.get_content_id("default:stone")
103 local layers= {
104 { min=-100, node="rocks:granite" },
105 { min=-240, node="rocks:diorite"},
106 { node="rocks:gabbro", min=-700},
108 for k,v in pairs(layers) do
109 v.ctx=minetest.get_content_id(v.node)
111 local layers_no=#layers
112 local n_layer= minetest.get_perlin_map(np_layer, pmapsize) : get2dMap_flat(pmapminpxz)
113 local n_intr= minetest.get_perlin_map(np_intr, pmapsize) : get2dMap_flat(pmapminpxz)
114 local nixz= 1
116 for z=minp.z, maxp.z do for x=minp.x, maxp.x do
117 -- loop
118 for y=minp.y, maxp.y do
119 local di=area:index(x,y,z)
120 local yn=y+n_layer[nixz]
121 local vintr=n_intr[nixz]
122 if vintr<1 then vintr=1 end
123 if data[di]==c_stone then
124 yn=yn*vintr -- vertical intrusion
125 for li=1, layers_no do
126 if yn > layers[li].min then
127 data[di]=layers[li].ctx
128 break
133 nixz= nixz+1
134 end end
136 vm:set_data(data)
137 --DEBUG: vm:set_lighting({day=15,night=2})
138 minetest.generate_ores(vm)
139 minetest.log("action", "rocks/layer/ "..math.ceil((os.clock() - t1) * 1000).." ms ")
143 -- ~ Tomas Brod