mirror of
git://repo.or.cz/rocks.git
synced 2025-01-01 14:00:30 +01:00
Merge branch 'master' into demo
This commit is contained in:
commit
e2f5faa83d
83
a.txt
83
a.txt
@ -15,7 +15,8 @@ Features
|
||||
|
||||
** Work in progress! **
|
||||
|
||||
* Git clone: [https](https://gitorious.org/mt/rocks.git)
|
||||
* git clone git://repo.or.cz/rocks.git ([show](http://repo.or.cz/rocks.git/))
|
||||
* (old) Git clone: [https](https://gitorious.org/mt/rocks.git)
|
||||
|
||||
Screenshots
|
||||
-----------
|
||||
@ -29,82 +30,4 @@ Documentation
|
||||
|
||||
How the underground is generated: *todo*.
|
||||
|
||||
Underground is divided into horizontal layers. Bottom of each layer is at
|
||||
fixed height and moved up or down by 2d perlin noise.
|
||||
|
||||
In every layer there can be multiple veins. Veins are blob-shaped volumes
|
||||
of different rocks. Borders of vein are defined by 3d perlin noise. Veins
|
||||
often contain ores.
|
||||
|
||||
In every vein, ores are distributed randomly. Some ores
|
||||
may occur in specific areas of the vein (where noise is higher than
|
||||
treshold) or distributed randomly in specific amount (chance based on
|
||||
pseudorandom number) or combination of both.
|
||||
|
||||
There is 1 2d perlin noise per layer, 1 3d perlin noise per vein and 1
|
||||
pseudorandom number generator per ore.
|
||||
|
||||
Modding Interface
|
||||
-----------------
|
||||
|
||||
"Rocks" exposes api to add new ores, veins and layers. The api is defined
|
||||
in [register](register.lua).
|
||||
|
||||
### Register layer
|
||||
|
||||
rocks.register_layer=function(name,params,rock)
|
||||
|
||||
|
||||
This function registers a layer. Layer is identified by unique string name.
|
||||
Location of layer is specified in params and node, the layer should be
|
||||
composed of is defined by rock.
|
||||
|
||||
Field "params.gain" sets how height of the layer should vary. Field
|
||||
"params.height" sets height of bottom of the layer. Field "params.limit" is
|
||||
value of noise above which the layer is not generated. Set to 2 to disable
|
||||
this feature. Last field "params.seed" is offset to world seed to seed the
|
||||
noise.
|
||||
|
||||
### Register vein
|
||||
|
||||
rocks.register_vein=function(name,params)
|
||||
|
||||
This function registers a vein with name "name" to be generated according
|
||||
to params.
|
||||
|
||||
Field "params.spread" {x,y,z} defines how the vein should look like. X
|
||||
shoudd be equal to z. If y=x=z then the vein is equal in all directions. To
|
||||
make the vein taller, set y to higher value. Larger values make larger and
|
||||
less frequent veins.
|
||||
|
||||
Field "params.treshold" specifies rarity of the vein. It should be betveen
|
||||
-2 and +2, mapgen will use this or per-ore treshold if per-ore treshold is
|
||||
larger.
|
||||
|
||||
- 2 never generate
|
||||
- 1 extremly rare
|
||||
- 0 50% chance
|
||||
- less than 0 = SPAM
|
||||
|
||||
Field "params.seed" is added to world seed to form seed for noise function.
|
||||
|
||||
Depths, where the wein should generate can be controlled by fields hmin and
|
||||
hmax. They can be set to nil to generate everywhere.
|
||||
|
||||
Layers, where the vein should generate in must be listed in Field
|
||||
"params.layer".
|
||||
|
||||
## Register ore
|
||||
|
||||
rocks.register_ore=function( vein, node, params )
|
||||
|
||||
This function registers ore or rock to be generated in vein "vein". Node to
|
||||
be generated is "node". Params specify parameters, where the rock should
|
||||
spawn.
|
||||
|
||||
If noise is larger than Params.treshold, the ore is spawned (set to 2 to
|
||||
spawn everywhere in the vein, 0.8=only in middle). Params.chance specify
|
||||
the chance (/100%) of ore being spawned (0=never 1=always 0.5=50%).
|
||||
|
||||
If multiple ores pass the treshhold and chance tests, ore with highest
|
||||
treshold and smallest chance is spawned.
|
||||
Mod has been rewritten, so no doc yet.
|
||||
|
124
geologica.lua
124
geologica.lua
@ -1,124 +0,0 @@
|
||||
local CcHard=3
|
||||
local CcStrong=3
|
||||
local CcMed=3
|
||||
local CcSoft=3
|
||||
|
||||
--
|
||||
-- Main rocks (top to bottom)
|
||||
--
|
||||
|
||||
-- Granite In/Felsic hard Very common, below sed on land
|
||||
minetest.register_node( "rocks:granite", {
|
||||
description = S("Granite"),
|
||||
tiles = { "rocks_Granite.png" },
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
groups = {cracky=CcStrong, stone=1},
|
||||
})
|
||||
rocks.register_layer( "granite",{ gain=20, height=-55, limit=2, seed=1 }, "rocks:granite")
|
||||
|
||||
-- Diorite In/Inter vhard Below granite
|
||||
minetest.register_node( "rocks:diorite", {
|
||||
description = S("Diorite"),
|
||||
tiles = { "rocks_Diorite.png" },
|
||||
groups = {cracky=CcHard, stone=1},
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
rocks.register_layer( "diorite",{ gain=20, height=-80, limit=2, seed=2 }, "rocks:diorite")
|
||||
|
||||
-- Basalt Ex/Mafic hard same as diorite, byt limit=0.5
|
||||
minetest.register_node( "rocks:basalt", {
|
||||
description = S("Basalt"),
|
||||
tiles = { "rocks_Basalt.png" },
|
||||
groups = {cracky=CcStrong, stone=1},
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
rocks.register_layer( "basalt",{ gain=20, height=-75, limit=-0.7, seed=2 }, "rocks:basalt")
|
||||
|
||||
-- Gabbro In/Mafic vhard Below basalt/diorite (mtns, ocean)
|
||||
minetest.register_node( "rocks:gabbro", {
|
||||
description = S("Gabbro"),
|
||||
tiles = { "rocks_Gabbro.png" },
|
||||
groups = {cracky=CcHard, stone=1},
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
rocks.register_layer( "gabbro",{ gain=20, height=-120, limit=2, seed=3 }, "rocks:gabbro")
|
||||
|
||||
-- Peridotite In/UMafic vhard Rarely under gabbro
|
||||
minetest.register_node( "rocks:peridotite", {
|
||||
description = S("Peridotite"),
|
||||
tiles = { "rocks_Peridotite.png" },
|
||||
groups = {cracky=CcStrong, stone=1},
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
rocks.register_layer( "peridotite",{ gain=20, height=-130, limit=-0.8, seed=4 }, "rocks:peridotite")
|
||||
|
||||
-- Komatiite Ex/UMafic - Too deep
|
||||
minetest.register_node( "rocks:komatiite", {
|
||||
description = S("Komatiite"),
|
||||
tiles = { "default_stone.png" }, -- no texture, yet
|
||||
groups = {cracky=CcHard, stone=1},
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
rocks.register_layer( "komatiite",{ gain=20, height=-200, limit=2, seed=5 }, "rocks:komatiite")
|
||||
|
||||
--
|
||||
-- top sedimentary rocks
|
||||
--
|
||||
|
||||
-- Mudstone Sed soft Ocean, beach, river, glaciers
|
||||
minetest.register_node( "rocks:mudstone", {
|
||||
description = S("Mudstone"),
|
||||
tiles = { "rocks_Mudstone.png" },
|
||||
groups = {cracky=CcSoft, stone=1},
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
rocks.register_layer( "mudstone",{ gain=10, height=-13, limit=2, seed=4 }, "rocks:mudstone")
|
||||
|
||||
-- Slate MM/barro med Under mud/clay/siltstone
|
||||
minetest.register_node( "rocks:slate", {
|
||||
description = S("slate"),
|
||||
tiles = { "rocks_Slate.png" },
|
||||
groups = {cracky=CcMed, stone=1},
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
rocks.register_layer( "slate",{ gain=10, height=-15, limit=2, seed=5 }, "rocks:slate")
|
||||
|
||||
-- Schist MM/barro med Under slate, sometimes igneous
|
||||
minetest.register_node( "rocks:schist", {
|
||||
description = S("schist"),
|
||||
tiles = { "rocks_Schist.png" },
|
||||
groups = {cracky=CcMed, stone=1},
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
rocks.register_layer( "schist",{ gain=10, height=-18, limit=2, seed=5 }, "rocks:schist")
|
||||
|
||||
-- Gneiss MM/barro hard Under schist, sometimes igneous
|
||||
minetest.register_node( "rocks:gneiss", {
|
||||
description = S("gneiss"),
|
||||
tiles = { "rocks_Gneiss.png" },
|
||||
groups = {cracky=CcStrong, stone=1},
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
rocks.register_layer( "gneiss",{ gain=10, height=-21, limit=2, seed=6 }, "rocks:gneiss")
|
||||
|
||||
--
|
||||
-- peak rocks
|
||||
--
|
||||
|
||||
-- Rhyolite Ex/Felsic hard Mountains, top
|
||||
minetest.register_node( "rocks:rhyolite", {
|
||||
description = S("Rhyolite"),
|
||||
tiles = { "rocks_Rhyolite.png" },
|
||||
groups = {cracky=CcHard, stone=1},
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
rocks.register_layer( "rhyolite",{ gain=8, height=22, limit=2, seed=4 }, "rocks:rhyolite")
|
||||
|
||||
-- Andesite Ex/Inter hard Mountains, below rhyolite
|
||||
minetest.register_node( "rocks:andesite", {
|
||||
description = S("Andesite"),
|
||||
tiles = { "rocks_Andesite.png" },
|
||||
groups = {cracky=CcHard, stone=1},
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
rocks.register_layer( "andesite",{ gain=8, height=10, limit=2, seed=4 }, "rocks:andesite")
|
@ -1,37 +0,0 @@
|
||||
local CcHard=3
|
||||
local CcStrong=3
|
||||
local CcMed=3
|
||||
local CcSoft=3
|
||||
|
||||
--
|
||||
-- nonvein vein
|
||||
--
|
||||
|
||||
-- Claystone Sed soft in mudstone
|
||||
rocks.register_vein("clay",{
|
||||
spread = {x=30, y=10, z=30},
|
||||
treshold=0.2, -- clay should be plenty
|
||||
seed = 9,
|
||||
hmin=-8, hmax=nil,
|
||||
layers={ "mudstone" },
|
||||
})
|
||||
rocks.register_ore( "clay", "default:clay", {treshold=0, chance=85 } )
|
||||
rocks.register_ore( "clay", "default:torch", {treshold=0, chance=15 } )
|
||||
|
||||
-- Breccia Mixture soft in mudstone
|
||||
-- Conglomerate Sed soft in mudstone
|
||||
-- Skarn MM/contact med in mudstone in mountains
|
||||
-- Hornfels MM/contact vhard in mudstone in mountains
|
||||
-- Marble MM/contact hard in mudstone in mountains
|
||||
-- Limestone Sed med in Rhyolite, Andesite in mountains
|
||||
rocks.register_vein("limestone",{
|
||||
spread = {x=10, y=10, z=10},
|
||||
treshold=0.75,
|
||||
seed = 10,
|
||||
hmin=nil, hmax=nil,
|
||||
layers={ "mudstone" },
|
||||
})
|
||||
-- Dolomite Sed med in Rhyolite, Andesite in mountains
|
||||
-- Quartzite MM/contact vhard sandstone
|
||||
|
||||
|
85
ign.lua
Normal file
85
ign.lua
Normal file
@ -0,0 +1,85 @@
|
||||
--
|
||||
-- Igneous Layer
|
||||
--
|
||||
|
||||
local ign={
|
||||
top={
|
||||
offset = -10, scale = 0,
|
||||
spread = {x=80, y=80, z=80},
|
||||
octaves = 0, persist = 0 },
|
||||
bot={
|
||||
offset = -180, scale = 10, seed=rocksl.GetNextSeed(),
|
||||
spread = {x=80, y=80, z=80},
|
||||
octaves = 2, persist = 0.7 },
|
||||
primary={ name="rocks:basalt" },
|
||||
localized={},
|
||||
stats={ count=0, total=0, node={}, totalnodes=0 },
|
||||
debugging=nil
|
||||
}
|
||||
|
||||
-- Basalt Ex/Mafic hard same as diorite, byt limit=0.5
|
||||
minetest.register_node( "rocks:basalt", {
|
||||
description = S("Basalt"),
|
||||
tiles = { "rocks_Basalt.png" },
|
||||
groups = {cracky=3, stone=1},
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
|
||||
-- more rock defs
|
||||
minetest.register_node( "rocks:granite", {
|
||||
description = S("Granite"),
|
||||
tiles = { "rocks_Granite.png" },
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
groups = {cracky=3, stone=1},
|
||||
})
|
||||
minetest.register_node( "rocks:diorite", {
|
||||
description = S("Diorite"),
|
||||
tiles = { "rocks_Diorite.png" },
|
||||
groups = {cracky=3, stone=1},
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
minetest.register_node( "rocks:gabbro", {
|
||||
description = S("Gabbro"),
|
||||
tiles = { "rocks_Gabbro.png" },
|
||||
groups = {cracky=3, stone=1},
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
|
||||
local reg=function(name,param)
|
||||
rocksl.register_stratus(ign,name,param)
|
||||
end
|
||||
rocks.register_igneous_stratus=reg
|
||||
|
||||
-- rock registration
|
||||
reg("rocks:granite", { spread=40, height=32, treshold=0.06})
|
||||
reg("rocks:diorite", { spread=40, height=32, treshold=0.23})
|
||||
reg("rocks:gabbro", { spread=40, height=32, treshold=0.36})
|
||||
|
||||
-- vein stuff
|
||||
ign.veins={}
|
||||
|
||||
rocksl.register_vein(ign.veins,"default:nyancat",{
|
||||
wherein="rocks:granite",
|
||||
miny=-160, maxy=20,
|
||||
radius={ average=10, amplitude=4, frequency=8 },
|
||||
density=1,
|
||||
rarity=0.025, -- this^3*mapblock_volume veins per mapblock
|
||||
})
|
||||
|
||||
-- { primary="rocks:pegmatite_diamond", size=3, count=5,
|
||||
-- rarity=0.3 -- (this/count) chance of spawning cluster in the vein
|
||||
|
||||
minetest.register_on_generated(function(minp, maxp, seed)
|
||||
rocksl.layergen(ign,minp,maxp,seed)
|
||||
rocksl.veingen(ign.veins,minp,maxp,seed)
|
||||
end)
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
if (ign.stats.count==0) then rocksl.print("[rocks](ign) stats not available, no chunks generated") return end
|
||||
rocksl.print("[rocks](ign) generated total "..ign.stats.count.." chunks in "..ign.stats.total.." seconds ("..(ign.stats.total/ign.stats.count).." seconds per "..ign.stats.side.."^3 chunk)")
|
||||
for name,total in pairs(ign.stats.node) do
|
||||
rocksl.print("[rocks](ign) "..name..": "..total.." nodes placed ("..(total*100)/(ign.stats.totalnodes).." %)")
|
||||
end
|
||||
end)
|
||||
|
||||
-- ~ Tomas Brod
|
41
init.lua
41
init.lua
@ -1,3 +1,5 @@
|
||||
minetest.log("info","[rocks] mod initializing")
|
||||
|
||||
-- Load translation library if intllib is installed
|
||||
|
||||
if (minetest.get_modpath("intllib")) then
|
||||
@ -7,32 +9,19 @@ if (minetest.get_modpath("intllib")) then
|
||||
S = function ( s ) return s end
|
||||
end
|
||||
|
||||
local modpath=minetest.get_modpath(minetest.get_current_modname())
|
||||
rocks={}
|
||||
rocksl={}
|
||||
|
||||
dofile(modpath.."/register.lua")
|
||||
|
||||
rocks.noiseparams_layers = {
|
||||
offset = 0,
|
||||
scale = 1,
|
||||
spread = {x=80, y=80, z=80},
|
||||
octaves = 2,
|
||||
persist = 0.7
|
||||
}
|
||||
|
||||
dofile(modpath.."/mapgen.lua")
|
||||
--dofile(modpath.."/testing.lua")
|
||||
dofile(modpath.."/geologica.lua")
|
||||
dofile(modpath.."/geologica_nv.lua")
|
||||
|
||||
print("[rocks] sorting layers")
|
||||
|
||||
for i,d in pairs(rocks.layers_name) do table.insert(rocks.layers,d) end
|
||||
table.sort(rocks.layers,function(a,b)
|
||||
return a.height<b.height
|
||||
end)
|
||||
|
||||
for i,d in pairs(rocks.layers) do
|
||||
print(" init,layer "..i.." "..minetest.serialize(d))
|
||||
rocksl.print=function(text)
|
||||
print("[rocks] "..text)
|
||||
end
|
||||
|
||||
print("[rocks] loaded.")
|
||||
local modpath=minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
dofile(modpath.."/mapgen.lua")
|
||||
dofile(modpath.."/sed.lua")
|
||||
dofile(modpath.."/ign.lua")
|
||||
|
||||
minetest.register_on_mapgen_init(function(mapgen_params)
|
||||
-- todo: disable caves and ores
|
||||
end)
|
||||
|
275
mapgen.lua
275
mapgen.lua
@ -2,123 +2,180 @@
|
||||
-- layer generator
|
||||
--
|
||||
|
||||
local print2=function(text)
|
||||
minetest.log("verbose","rocks/gen/ "..text)
|
||||
end
|
||||
|
||||
minetest.register_on_generated(function(minp, maxp, seed)
|
||||
stone_ctx= minetest.get_content_id("default:stone")
|
||||
air_ctx= minetest.get_content_id("air")
|
||||
rocksl.seedseq=0
|
||||
rocksl.GetNextSeed=function()
|
||||
rocksl.seedseq=rocksl.seedseq+20
|
||||
print2("seed "..rocksl.seedseq)
|
||||
return rocksl.seedseq
|
||||
end
|
||||
|
||||
rocksl.register_stratus=function(layer,name,param)
|
||||
table.insert(layer.localized,{
|
||||
primary=name,
|
||||
spread=(param.spread or 20),
|
||||
height=(param.height or 15),
|
||||
treshold=(param.treshold or 0.85),
|
||||
secondary=param.secondary,
|
||||
seed=(rocksl.GetNextSeed()),
|
||||
})
|
||||
layer.stats.node[name]=0
|
||||
end
|
||||
|
||||
rocksl.register_vein=function(col,name,param)
|
||||
table.insert(col,{
|
||||
primary=name,
|
||||
wherein=param.wherein,
|
||||
miny=param.miny, maxy=param.maxy,
|
||||
radius={ average=param.radius.average, amplitude=param.radius.amplitude, frequency=param.radius.frequency },
|
||||
density=(param.density or 1),
|
||||
rarity=param.rarity,
|
||||
localized={}
|
||||
})
|
||||
end
|
||||
|
||||
rocksl.layergen=function(layer, minp, maxp, seed)
|
||||
if ( (layer.top.offset+layer.top.scale)>minp.y )
|
||||
and ( (layer.bot.offset-layer.bot.scale)<maxp.y )
|
||||
then
|
||||
stone_ctx= minetest.get_content_id("default:stone")
|
||||
air_ctx= minetest.get_content_id("air")
|
||||
dirt_ctx= minetest.get_content_id("default:dirt")
|
||||
if layer.debugging then
|
||||
layer.primary.ctx= air_ctx
|
||||
else
|
||||
layer.primary.ctx= minetest.get_content_id(layer.primary.name)
|
||||
end
|
||||
local timebefore=os.clock();
|
||||
local manipulator, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||
local nodes = manipulator:get_data()
|
||||
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
||||
local side_length = (maxp.x - minp.x) + 1
|
||||
local map_lengths_xyz = {x=side_length, y=side_length, z=side_length}
|
||||
-- noises:
|
||||
local bottom=minetest.get_perlin_map(layer.bot,map_lengths_xyz):get2dMap_flat({x=minp.x, y=minp.z})
|
||||
local localized={}
|
||||
for _,loc in ipairs(layer.localized) do
|
||||
--defaults and overrides
|
||||
local np={ offset = 0, scale = 1, octaves = 1, persist = 0.7,
|
||||
spread = {x=loc.spread, y=loc.height, z=loc.spread}, seed=loc.seed}
|
||||
--get noise and content ids
|
||||
table.insert(localized,
|
||||
{
|
||||
noise=minetest.get_perlin_map(np,map_lengths_xyz):get3dMap_flat(minp),
|
||||
treshold=loc.treshold,
|
||||
ctx= minetest.get_content_id(loc.primary),
|
||||
ndn=loc.primary
|
||||
})
|
||||
end
|
||||
local noise2d_ix = 1
|
||||
local noise3d_ix = 1
|
||||
print2("after noise: "..(os.clock()-timebefore))
|
||||
for z=minp.z,maxp.z,1 do
|
||||
for y=minp.y,maxp.y,1 do
|
||||
for x=minp.x,maxp.x,1 do
|
||||
local pos = area:index(x, y, z)
|
||||
if (y>bottom[noise2d_ix]) and (y<layer.top.offset)
|
||||
and ( (nodes[pos]==stone_ctx) or (nodes[pos]==dirt_ctx) )
|
||||
then
|
||||
layer.stats.totalnodes=layer.stats.totalnodes+1
|
||||
if nodes[pos]==stone_ctx then nodes[pos] = layer.primary.ctx end
|
||||
for k,loc in pairs(localized) do
|
||||
if ( loc.noise[noise3d_ix] > loc.treshold) then
|
||||
nodes[pos]=loc.ctx
|
||||
layer.stats.node[loc.ndn]=layer.stats.node[loc.ndn]+1
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
noise2d_ix=noise2d_ix+1
|
||||
noise3d_ix=noise3d_ix+1
|
||||
end
|
||||
noise2d_ix=noise2d_ix-side_length
|
||||
end
|
||||
noise2d_ix=noise2d_ix+side_length
|
||||
end
|
||||
print2("after loop: "..(os.clock()-timebefore))
|
||||
manipulator:set_data(nodes)
|
||||
--manipulator:calc_lighting()
|
||||
--manipulator:update_liquids()
|
||||
if layer.debugging then
|
||||
manipulator:set_lighting({day=15,night=15})
|
||||
end
|
||||
manipulator:write_to_map()
|
||||
print2("after commit: "..(os.clock()-timebefore))
|
||||
layer.stats.count=layer.stats.count+1
|
||||
layer.stats.total=layer.stats.total+(os.clock()-timebefore)
|
||||
layer.stats.side=side_length
|
||||
end
|
||||
end
|
||||
|
||||
local ignore_wherein=nil
|
||||
|
||||
rocksl.veingen=function(veins,minp,maxp,seed)
|
||||
local side_length=(maxp.y-minp.y)
|
||||
local random=PseudoRandom(seed-79)
|
||||
local timebefore=os.clock();
|
||||
local manipulator, emin, emax = minetest.get_mapgen_object("voxelmanip")
|
||||
local nodes = manipulator:get_data()
|
||||
local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
|
||||
local side_length = (maxp.x - minp.x) + 1
|
||||
local map_lengths_xyz = {x=side_length, y=side_length, z=side_length}
|
||||
|
||||
-- sort out unused layers
|
||||
-- generate noises
|
||||
avl={}
|
||||
for i,d in ipairs(rocks.layers) do
|
||||
-- h je normaalna vyyska horného konca vrstvy
|
||||
if (d.height+d.gain)>=minp.y then -- ak je to mimo zdola tak ju vyhodime
|
||||
-- urobime sum pre vrstvu
|
||||
local np=rocks.noiseparams_layers
|
||||
np.seed=d.seed
|
||||
np.scale=d.gain
|
||||
np.offset=d.height
|
||||
d.nmap=minetest.get_perlin_map(np,map_lengths_xyz):get2dMap_flat({x=minp.x, y=minp.z})
|
||||
-- contene_id kamenov
|
||||
d.rock.ctx=d.rock.ctx or minetest.get_content_id(d.rock.node)
|
||||
-- veiny
|
||||
local veinstodo={}
|
||||
for veinname,vd in pairs(d.veins) do
|
||||
-- todo: do not generate noise for blocks outside the layer
|
||||
veinstodo[veinname]=vd
|
||||
end
|
||||
for veinname,vd in pairs(veinstodo) do
|
||||
-- noise pre vein
|
||||
np=vd.np
|
||||
vd.nmap=minetest.get_perlin_map(np,map_lengths_xyz):get3dMap_flat(minp)
|
||||
vd.prng=PseudoRandom(np.seed)
|
||||
vd.sum=0
|
||||
for i,ore in pairs(vd.ores) do
|
||||
-- contntid pre rudu
|
||||
ore.ctx=ore.ctx or minetest.get_content_id(ore.node)
|
||||
-- sum sanci pre vein
|
||||
vd.sum=vd.sum+ore.chance
|
||||
local did_generate=nil
|
||||
for _,vein in ipairs(veins) do
|
||||
if (minp.y<vein.maxy) and (maxp.y>vein.maxy) then
|
||||
local vr2=vein.radius.average^2
|
||||
local vrm=vein.radius.average+vein.radius.amplitude
|
||||
local noise_map=minetest.get_perlin_map(
|
||||
{
|
||||
seed=-79,
|
||||
scale=vein.radius.amplitude,
|
||||
offset=0, octaves=1, persist=0.7,
|
||||
spread={x=vein.radius.frequency, y=vein.radius.frequency, z=vein.radius.frequency}
|
||||
},{x=(vrm*2)+1, y=(vrm*2)+1, z=(vrm*2)+1}
|
||||
)
|
||||
local iterations_count= (vein.rarity*side_length)^3
|
||||
iterations_count=iterations_count+(random:next(0,100)/100)
|
||||
local primary_ctx=minetest.get_content_id(vein.primary)
|
||||
local wherein_ctx=minetest.get_content_id(vein.wherein)
|
||||
--print("vein "..vein.primary.." ic="..iterations_count.." p="..primary_ctx.." w="..wherein_ctx)
|
||||
for iteration=1, iterations_count do
|
||||
local x0=minp.x+ random:next(0,side_length)
|
||||
local y0=minp.y+ random:next(0,side_length)
|
||||
local z0=minp.z+ random:next(0,side_length)
|
||||
local noise=noise_map:get3dMap_flat({x=x0-vrm, y=y0-vrm, z=z0-vrm})
|
||||
local noise_ix=1
|
||||
local posi = area:index(x0, y0, z0)
|
||||
if ignore_wherein or (nodes[posi]==wherein_ctx) then
|
||||
--print("vein "..vein.primary.." @ "..x0..","..y0..","..z0.." vrm="..vrm)
|
||||
did_generate=1
|
||||
for x=-vrm, vrm do
|
||||
for y=-vrm, vrm do
|
||||
for z=-vrm, vrm do
|
||||
local posc = {x=x+x0,y=y+y0,z=z+z0}
|
||||
posi = area:index(posc.x, posc.y, posc.z)
|
||||
local nv=noise[noise_ix]
|
||||
if ((x^2)+(y^2)+(z^2))<((vein.radius.average+nv)^2) then
|
||||
--minetest.set_node(posc, {name=vein.primary})
|
||||
nodes[posi]=primary_ctx
|
||||
end
|
||||
noise_ix=noise_ix+1
|
||||
end end end
|
||||
else
|
||||
--print("vein "..vein.primary.." bad environmnent -"..minetest.get_node({x0,y0,z0}).name.."="..nodes[posi])
|
||||
end
|
||||
end
|
||||
table.insert(avl,d) -- pridame vrstvu
|
||||
if (d.height-d.gain)>maxp.y then break end -- ak je mimo zhora tak uz dalsie nehladaj
|
||||
else
|
||||
--print(" no higher "..d.height.." than "..minp.y)
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
print("[rocks] gen2 "..os.clock()-timebefore.." #layers="..#avl.." minp.y="..minp.y.." maxp.y"..maxp.y)
|
||||
for lh,ld in ipairs(avl) do
|
||||
print(" "..lh.."->"..ld.name.." top="..ld.height)
|
||||
for vn,vd in pairs(ld.veins) do
|
||||
print(" "..vn.."->"..#vd.ores)
|
||||
end
|
||||
end
|
||||
|
||||
local noise2d_ix = 1
|
||||
local noise3d_ix = 1
|
||||
|
||||
for z=minp.z,maxp.z,1 do
|
||||
for y=minp.y,maxp.y,1 do
|
||||
for x=minp.x,maxp.x,1 do
|
||||
local p_pos = area:index(x, y, z)
|
||||
local layer,vein
|
||||
local rock
|
||||
|
||||
--* select layer
|
||||
for lh,ld in ipairs(avl) do
|
||||
if (y<ld.nmap[noise2d_ix])and(ld.nmap[noise2d_ix]<ld.limit) then
|
||||
layer=ld
|
||||
rock=layer.rock
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if layer then
|
||||
--* select vein
|
||||
for veinname,vd in pairs(layer.veins) do
|
||||
if vd.nmap[noise3d_ix]>vd.treshold then
|
||||
vein=vd
|
||||
--rock not changed
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if vein then
|
||||
--* select ore
|
||||
local chance=vein.prng:next(0,vein.sum)
|
||||
for i,ore in pairs(vein.ores) do
|
||||
chance=chance-ore.chance
|
||||
if chance<=0 then
|
||||
rock=ore
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--* place rocks
|
||||
if (rock) and(nodes[p_pos]==stone_ctx) then
|
||||
nodes[p_pos] = rock.ctx
|
||||
end
|
||||
|
||||
noise3d_ix =noise3d_ix+1
|
||||
noise2d_ix = noise2d_ix+1
|
||||
end
|
||||
noise2d_ix = noise2d_ix-side_length
|
||||
end
|
||||
if did_generate then
|
||||
manipulator:set_data(nodes)
|
||||
--manipulator:calc_lighting()
|
||||
manipulator:write_to_map()
|
||||
print("end veingen "..(os.clock()-timebefore))
|
||||
else
|
||||
print("end veingen (nothin generated)")
|
||||
end
|
||||
manipulator:set_data(nodes)
|
||||
--manipulator:calc_lighting()
|
||||
--manipulator:set_lighting({day=15,night=15})
|
||||
--manipulator:update_liquids()
|
||||
manipulator:write_to_map()
|
||||
print("[rocks] gen0 "..os.clock()-timebefore)
|
||||
end)
|
||||
end
|
||||
|
||||
-- ~ Tomas Brod
|
61
register.lua
61
register.lua
@ -1,61 +0,0 @@
|
||||
-- global table and register_* functions
|
||||
|
||||
rocks = {}
|
||||
|
||||
rocks.layers = {}
|
||||
rocks.layers_name = {}
|
||||
rocks.veins = {}
|
||||
rocks.ores = {}
|
||||
|
||||
rocks.register_layer=function(name,params,rock)
|
||||
assert(name)
|
||||
assert(params)
|
||||
assert(rock)
|
||||
assert(params.gain)
|
||||
assert(params.height)
|
||||
local maxheight
|
||||
|
||||
local ld= {
|
||||
gain=params.gain,
|
||||
height=params.height,
|
||||
maxheight=maxheight,
|
||||
limit=((params.limit or 2)*params.gain)+params.height,
|
||||
seed=params.seed or 0,
|
||||
rock={ node=rock },
|
||||
veins={},
|
||||
name=name
|
||||
}
|
||||
rocks.layers_name[name]= ld
|
||||
print("[rocks] layer "..ld.name)
|
||||
end
|
||||
|
||||
rocks.register_vein=function(name,params)
|
||||
assert(name)
|
||||
assert(params)
|
||||
assert(not rocks.veins[name])
|
||||
rocks.veins[name]={
|
||||
np={
|
||||
offset=0, scale=1, octaves=1, presist=0.8,
|
||||
spread={x=params.spread.x, y=params.spread.y, z=params.spread.z},
|
||||
-- swapped, becouse we generate by horizontal layers
|
||||
seed=params.seed
|
||||
},
|
||||
treshold=params.treshold,
|
||||
hmin=params.hmin, hmax=params.hmax,
|
||||
layers=params.layers,
|
||||
ores={}
|
||||
}
|
||||
for i,layername in pairs(params.layers) do
|
||||
rocks.layers_name[layername].veins[name]=rocks.veins[name]
|
||||
end
|
||||
print("[rocks] vein "..name)
|
||||
end
|
||||
|
||||
rocks.register_ore=function( vein, node, params )
|
||||
-- params= {treshold=0, chance=1 }
|
||||
ore={ node=node }
|
||||
ore.treshold=(params.treshold or rocks.veins[vein].treshold)
|
||||
ore.chance= (params.chance or 1)
|
||||
table.insert(rocks.veins[vein].ores, ore)
|
||||
print("[rocks] ore "..node.." in "..vein.." chance="..ore.chance.." treshold="..ore.treshold)
|
||||
end
|
68
sed.lua
Normal file
68
sed.lua
Normal file
@ -0,0 +1,68 @@
|
||||
--
|
||||
-- Sedimentary Layer
|
||||
--
|
||||
|
||||
local sed={
|
||||
top={
|
||||
offset = 20, scale = 0,
|
||||
spread = {x=80, y=80, z=80},
|
||||
octaves = 0, persist = 0 },
|
||||
bot={
|
||||
offset = -16, scale = 10, seed=rocksl.GetNextSeed(),
|
||||
spread = {x=80, y=80, z=80},
|
||||
octaves = 2, persist = 0.7 },
|
||||
primary={ name="rocks:mudstone" },
|
||||
localized={},
|
||||
stats={ count=0, total=0, node={}, totalnodes=0 },
|
||||
debugging=nil
|
||||
}
|
||||
|
||||
-- Mudstone Sed soft Ocean, beach, river, glaciers
|
||||
minetest.register_node( "rocks:mudstone", {
|
||||
description = S("Mudstone"),
|
||||
tiles = { "rocks_Mudstone.png" },
|
||||
groups = {cracky=1, crumbly=3},
|
||||
is_ground_content = true, sounds = default.node_sound_dirt_defaults(),
|
||||
})
|
||||
|
||||
-- more rock defs
|
||||
minetest.register_node( "rocks:limestone", {
|
||||
description = S("Limestone"),
|
||||
tiles = { "rocks_Limestone.png" },
|
||||
is_ground_content = true, sounds = default.node_sound_stone_defaults(),
|
||||
groups = {cracky=2},
|
||||
})
|
||||
|
||||
|
||||
local reg=function(name,param)
|
||||
rocksl.register_stratus(sed,name,param)
|
||||
end
|
||||
|
||||
rocks.register_sedimentary=reg
|
||||
|
||||
-- Sedimentary rock hardness and distribution
|
||||
-- Rock Hard Distribution
|
||||
--Breccia Weak Localized continental, folded
|
||||
-->Claystone Weak Localized continental, folded, oceanic
|
||||
--Conglomerate Weak Localized continental, folded
|
||||
-->Limestone Medium Localized continental, folded; primary oceanic, hills
|
||||
-->Coal - Large beds, twice as common in swamps
|
||||
reg("rocks:limestone", { spread=64, height=32, treshold=0.36 })
|
||||
--reg("rocks:breccia", { spread=64, height=32, treshold=0.6 })
|
||||
--reg("rocks:conglomerate", { spread=64, height=32, treshold=0.6 })
|
||||
reg("default:stone_with_coal", { spread=48, height=14, treshold=0.40 })
|
||||
reg("default:clay",{ spread=48, height=14, treshold=0.50 })
|
||||
|
||||
minetest.register_on_generated(function(minp, maxp, seed)
|
||||
rocksl.layergen(sed,minp,maxp,seed)
|
||||
end)
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
if (sed.stats.count==0) then rocksl.print("[rocks](sed) stats not available, no chunks generated") return end
|
||||
rocksl.print("[rocks](sed) generated total "..sed.stats.count.." chunks in "..sed.stats.total.." seconds ("..(sed.stats.total/sed.stats.count).." seconds per "..sed.stats.side.."^3 chunk)")
|
||||
for name,total in pairs(sed.stats.node) do
|
||||
rocksl.print("[rocks](sed) "..name..": "..total.." nodes placed ("..(total*100)/(sed.stats.totalnodes).." %)")
|
||||
end
|
||||
end)
|
||||
|
||||
-- ~ Tomas Brod
|
BIN
textures/rocks_Dolomite.png
Normal file
BIN
textures/rocks_Dolomite.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 772 B |
BIN
textures/rocks_Limestone.png
Normal file
BIN
textures/rocks_Limestone.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 794 B |
Loading…
Reference in New Issue
Block a user