Using lua mapgen to generate layers and minetest to do ores, but I do not like it.
[rocks.git] / rocks / ign.lua
blob6b7ba7e7969384496b92136dd03f0dbb5ee01f7f
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 rocks.register_vein("default:nyancat",{
81 wherein={"rocks:granite", "air"},
82 miny=-160, maxy=20,
83 radius={ average=10, amplitude=0.1, frequency=8 },
84 density=100,
85 rarity=70, -- this^3*mapblock_volume veins per mapblock
86 ores={
87 { ore="default:sand", percent=30 },
88 { ore="default:dirt", percent=30 },
92 local np_layer = {
93 offset = 0, octaves = 3, persist = 0.46,
94 scale = 30,
95 spread = {x=500, y=500, z=500},
96 seed = -5500,
98 local np_intr = {
99 octaves = 3, persist = 0.46,
100 scale = 20,
101 offset = -15,
102 spread = {x=100, y=100, z=100},
103 seed = 3740,
106 minetest.register_on_generated( function( minp, maxp, seed )
107 local t1 = os.clock()
108 local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
109 local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
110 local data = vm:get_data()
112 local chunksize = maxp.x - minp.x + 1
113 local pmapsize = {x = chunksize, y = chunksize, z = 1}
114 local pmapminpxz = {x = minp.x, y = minp.z}
115 local c_stone= minetest.get_content_id("default:stone")
116 local layers= {
117 { min=-100, node="rocks:granite" },
118 { min=-240, node="rocks:diorite"},
119 { node="rocks:gabbro", min=-700},
121 for k,v in pairs(layers) do
122 v.ctx=minetest.get_content_id(v.node)
124 local layers_no=#layers
125 local n_layer= minetest.get_perlin_map(np_layer, pmapsize) : get2dMap_flat(pmapminpxz)
126 local n_intr= minetest.get_perlin_map(np_intr, pmapsize) : get2dMap_flat(pmapminpxz)
127 local nixz= 1
129 for z=minp.z, maxp.z do for x=minp.x, maxp.x do
130 -- loop
131 for y=minp.y, maxp.y do
132 local di=area:index(x,y,z)
133 local yn=y+n_layer[nixz]
134 local vintr=n_intr[nixz]
135 if vintr<1 then vintr=1 end
136 if data[di]==c_stone then
137 yn=yn*vintr -- vertical intrusion
138 for li=1, layers_no do
139 if yn > layers[li].min then
140 data[di]=layers[li].ctx
141 break
146 nixz= nixz+1
147 end end
149 vm:set_data(data)
150 vm:set_lighting({day=15,night=2})
151 minetest.generate_ores(vm)
152 vm:write_to_map(data)
153 minetest.log("action", "rocks/layer/ "..math.ceil((os.clock() - t1) * 1000).." ms ")
154 end)
157 -- ~ Tomas Brod