7 offset
= -13, scale
= 0,
8 spread
= {x
=80, y
=80, z
=80},
9 octaves
= 0, persist
= 0 },
11 offset
= -180, scale
= 10, seed
=100,
12 spread
= {x
=80, y
=80, z
=80},
13 octaves
= 2, persist
= 0.7 },
14 primary
={ name
="rocks:basalt" },
17 stats
={ count
=0, total
=0, node
={}, totalnodes
=0 }
23 local reg
=function(name
,param
)
24 layer
.localized
[name
]={
25 spread
=(param
.spread
or 20),
26 height
=(param
.height
or 15),
27 treshold
=(param
.treshold
or 0.85),
28 secondary
=(param
.secondary
),
31 layer
.stats
.node
[name
]=0
32 layer
.seedseq
=layer
.seedseq
+1
34 rocks
.register_igneous
=reg
37 --eg: reg("default:stone_with_coal", { spread=48, height=14, treshold=0.45 })
39 minetest
.register_on_generated(function(minp
, maxp
, seed
)
40 if ( (layer
.top
.offset
+layer
.top
.scale
)>minp
.y
)
41 and ( (layer
.bot
.offset
-layer
.bot
.scale
)<maxp
.y
)
43 stone_ctx
= minetest
.get_content_id("default:stone")
44 air_ctx
= minetest
.get_content_id("air")
45 dirt_ctx
= minetest
.get_content_id("default:dirt")
46 layer
.primary
.ctx
= minetest
.get_content_id(layer
.primary
.name
)
47 local timebefore
=os
.clock();
48 local manipulator
, emin
, emax
= minetest
.get_mapgen_object("voxelmanip")
49 local nodes
= manipulator
:get_data()
50 local area
= VoxelArea
:new
{MinEdge
=emin
, MaxEdge
=emax
}
51 local side_length
= (maxp
.x
- minp
.x
) + 1
52 local map_lengths_xyz
= {x
=side_length
, y
=side_length
, z
=side_length
}
54 local bottom
=minetest
.get_perlin_map(layer
.bot
,map_lengths_xyz
):get2dMap_flat({x
=minp
.x
, y
=minp
.z
})
56 for name
,loc
in pairs(layer
.localized
) do
57 --defaults and overrides
58 local np
={ offset
= 0, scale
= 1, octaves
= 1, persist
= 0.7,
59 spread
= {x
=loc
.spread
, y
=loc
.height
, z
=loc
.spread
} }
60 --get noise and content ids
61 table.insert(localized
,
63 noise
=minetest
.get_perlin_map(np
,map_lengths_xyz
):get3dMap_flat(minp
),
64 treshold
=loc
.treshold
,
65 ctx
= minetest
.get_content_id(name
),
71 print("[rocks] igneous gen1 "..os
.clock()-timebefore
)
72 for z
=minp
.z
,maxp
.z
,1 do
73 for y
=minp
.y
,maxp
.y
,1 do
74 for x
=minp
.x
,maxp
.x
,1 do
75 local pos
= area
:index(x
, y
, z
)
76 if (y
>bottom
[noise2d_ix
])
77 and ((nodes
[pos
]==stone_ctx
) or (nodes
[pos
]==dirt_ctx
))
79 layer
.stats
.totalnodes
=layer
.stats
.totalnodes
+1
80 if nodes
[pos
]==stone_ctx
then nodes
[pos
] = air_ctx
end --layer.primary.ctx
81 for k
,loc
in pairs(localized
) do
82 if ( loc
.noise
[noise3d_ix
] > loc
.treshold
) then
84 layer
.stats
.node
[loc
.ndn
]=layer
.stats
.node
[loc
.ndn
]+1
88 noise2d_ix
=noise2d_ix
+1
89 noise3d_ix
=noise3d_ix
+1
91 noise2d_ix
=noise2d_ix
-side_length
93 noise2d_ix
=noise2d_ix
+side_length
95 manipulator
:set_data(nodes
)
96 --manipulator:calc_lighting()
97 manipulator
:set_lighting({day
=15,night
=15})
98 --manipulator:update_liquids()
99 manipulator
:write_to_map()
100 print("[rocks] igneous gen2 "..os
.clock()-timebefore
)
101 layer
.stats
.count
=layer
.stats
.count
+1
102 layer
.stats
.total
=layer
.stats
.total
+(os
.clock()-timebefore
)
103 layer
.stats
.side
=side_length
107 minetest
.register_on_shutdown(function()
108 print("[rocks](ign) on_shutdown: generated total "..layer
.stats
.count
.." chunks in "..layer
.stats
.total
.." seconds ("..(layer
.stats
.total
/layer
.stats
.count
).." seconds per "..layer
.stats
.side
.."^3 chunk)")
109 for name
,total
in pairs(layer
.stats
.node
) do
110 print("[rocks](ign) "..name
..": "..total
.." nodes placed ("..(total
*100)/(layer
.stats
.count
*layer
.stats
.totalnodes
).." %)")