Add caves and ores.
This commit is contained in:
parent
c9f3db0729
commit
99ae343620
32
init.lua
32
init.lua
@ -72,8 +72,8 @@ function get_bseed2(minp)
|
||||
return wseed + math.floor(87*minp.x/47) + math.floor(73*minp.z/91) + math.floor(31*minp.y/45)
|
||||
end
|
||||
|
||||
local c_air = minetest.get_content_id("air")
|
||||
local c_ignore = minetest.get_content_id("ignore")
|
||||
c_air = minetest.get_content_id("air")
|
||||
c_ignore = minetest.get_content_id("ignore")
|
||||
|
||||
local function add_leaves(data, vi, c_leaves)
|
||||
if data[vi]==c_air or data[vi]==c_ignore then
|
||||
@ -201,6 +201,7 @@ end
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/nodes.lua")
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/buildings.lua")
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/villages.lua")
|
||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/ores.lua")
|
||||
|
||||
local function get_biome_table(minp, humidity, temperature)
|
||||
l = {}
|
||||
@ -305,6 +306,12 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
local c_grasses = {c_grass_1, c_grass_2, c_grass_3, c_grass_4, c_grass_5}
|
||||
local c_jungle_grass = minetest.get_content_id("default:junglegrass")
|
||||
local c_dry_shrub = minetest.get_content_id("default:dry_shrub")
|
||||
|
||||
local c_iron = minetest.get_content_id("default:stone_with_iron")
|
||||
local c_coal = minetest.get_content_id("default:stone_with_coal")
|
||||
local c_stone_with_mese = minetest.get_content_id("default:stone_with_mese")
|
||||
local c_mese = minetest.get_content_id("default:mese")
|
||||
local c_lava = minetest.get_content_id("default:lava_source")
|
||||
|
||||
local ni = 1
|
||||
local above_top
|
||||
@ -480,8 +487,25 @@ minetest.register_on_generated(function(minp, maxp, seed)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
to_add = generate_village(vx, vz, vs, vh, minp, maxp, data, a)
|
||||
|
||||
generate_vein(c_air,c_ignore,minp,maxp,0, {maxvdistance=79, maxheight=20,
|
||||
seglenghtn=15, seglenghtdev=6, segincln=0, segincldev=0.6, turnangle=57, forkturnangle=57, numperblock=8,
|
||||
radius = 4}, data, a)
|
||||
generate_vein(c_iron,c_stone,minp,maxp,0, {maxvdistance=10.5, maxheight=-16,
|
||||
seglenghtn=15, seglenghtdev=6, segincln=0, segincldev=0.6, turnangle=57, forkturnangle=57, numperblock=2.5}, data, a)
|
||||
generate_vein(c_coal,c_stone,minp,maxp,1, {maxvdistance=10, sizen=54, sizedev=27, maxheight=64,
|
||||
seglenghtn=15, seglenghtdev=6, segincln=0, segincldev=0.36, turnangle=57, forkturnangle=57, radius=1,numperblock=6}, data, a)
|
||||
generate_vein(c_stone_with_mese,c_stone,minp,maxp,2, {maxvdistance=50, sizen=7, sizedev=3, maxheight=-128,
|
||||
seglenghtn=2, seglenghtdev=1, segincln=4, segincldev=1, turnangle=57, forkturnangle=57,numperblock=0.8,
|
||||
numbranchesn=2, numbranchesdev=1, fork_chance=0.1, mothersizen=0, mothersizedev=0}, data, a)
|
||||
generate_vein(c_mese,c_stone,minp,maxp,3, {maxvdistance=50, sizen=7, sizedev=3, maxheight=-1024,
|
||||
seglenghtn=2, seglenghtdev=1, segincln=4, segincldev=1, turnangle=57, forkturnangle=57,
|
||||
numbranchesn=2, numbranchesdev=1, fork_chance=0.1, radius=1}, data, a)
|
||||
generate_vein(c_lava,c_mese,minp,maxp,3, {maxvdistance=50, sizen=7, sizedev=3, maxheight=-1024,
|
||||
seglenghtn=2, seglenghtdev=1, segincln=4, segincldev=1, turnangle=57, forkturnangle=57,
|
||||
numbranchesn=2, numbranchesdev=1, fork_chance=0.1, mothersizen=0, mothersizedev=0}, data, a)
|
||||
|
||||
to_add = generate_village(vx, vz, vs, vh, minp, maxp, data, a)
|
||||
|
||||
vm:set_data(data)
|
||||
|
||||
|
161
ores.lua
Normal file
161
ores.lua
Normal file
@ -0,0 +1,161 @@
|
||||
perlinore2={}
|
||||
|
||||
function in_cuboid(pos, minp, maxp)
|
||||
return (pos.x>=minp.x and pos.y>= minp.y and pos.z>=minp.z and pos.x<=maxp.x and pos.y<=maxp.y and pos.z<=maxp.z)
|
||||
end
|
||||
|
||||
function round_pos(p)
|
||||
return {x=math.floor(p.x+0.5),y=math.floor(p.y+0.5),z=math.floor(p.z+0.5)}
|
||||
end
|
||||
|
||||
function draw_sphere(name, wherein, center, radius, data, a, insideva)
|
||||
local rad2=radius*radius
|
||||
pos0={}
|
||||
for x=-radius, radius do
|
||||
pos0.x=center.x+x
|
||||
for y=-radius, radius do
|
||||
pos0.y=center.y+y
|
||||
for z=-radius, radius do
|
||||
pos0.z=center.z+z
|
||||
if x*x+y*y+z*z<=rad2 and insideva:contains(pos0.x, pos0.y, pos0.z) and (wherein == c_ignore or data[a:index(pos0.x, pos0.y, pos0.z)] == wherein) then
|
||||
data[a:index(pos0.x, pos0.y, pos0.z)] = name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function place_segment(name, wherein, pos1, pos2, minp, maxp, radius, data, a, insideva)
|
||||
local d={x=pos2.x-pos1.x, y=pos2.y-pos1.y, z=pos2.z-pos1.z}
|
||||
local N=math.max(math.abs(d.x),math.abs(d.y),math.abs(d.z))
|
||||
local s={x=d.x/N,y=d.y/N,z=d.z/N}
|
||||
local p=pos1
|
||||
if insideva:contains(pos1.x, pos1.y, pos1.z) and (wherein == c_ignore or data[a:index(pos1.x, pos1.y, pos1.z)] == wherein) then
|
||||
data[a:index(pos1.x, pos1.y, pos1.z)] = name
|
||||
end
|
||||
for i=1,N do
|
||||
p={x=p.x+s.x,y=p.y+s.y,z=p.z+s.z}
|
||||
p0=round_pos(p)
|
||||
if not in_cuboid(p0, minp, maxp) then return end
|
||||
draw_sphere(name,wherein,p0,radius, data, a, insideva)
|
||||
end
|
||||
end
|
||||
|
||||
function generate_vein_segment(name, wherein, minp, maxp, pr, pos, angle, rem_size, options, data, a, insideva)
|
||||
if rem_size<=0 then return end
|
||||
local Ln=options.seglenghtn
|
||||
local Ldev=options.seglenghtdev
|
||||
local L=pr:next(Ln-Ldev,Ln+Ldev)
|
||||
local incln=options.segincln*100
|
||||
local incldev=options.segincldev*100
|
||||
local incl=pr:next(incln-incldev,incln+incldev)/100
|
||||
local turnangle=options.turnangle
|
||||
local forkturnangle=options.forkturnangle
|
||||
local fork_chance=options.fork_chance*100
|
||||
local forkmultn=options.forkmultn*100
|
||||
local forkmultdev=options.forkmultdev*100
|
||||
local radius=options.radius
|
||||
|
||||
local end_pos={x=pos.x+L*math.cos(angle), y=pos.y-L*incl, z=pos.z+L*math.sin(angle)}
|
||||
place_segment(name, wherein, round_pos(pos), round_pos(end_pos), minp, maxp, radius, data, a, insideva)
|
||||
if not in_cuboid(end_pos, minp, maxp) then return end
|
||||
local new_angle=(math.pi*pr:next(-turnangle,turnangle)/180)+angle
|
||||
generate_vein_segment(name, wherein, minp, maxp, pr, end_pos, new_angle, rem_size-L, options, data, a, insideva)
|
||||
|
||||
local numforks=math.floor(fork_chance/100)+1
|
||||
fork_chance=fork_chance/numforks
|
||||
if pr:next(1,100)<=fork_chance then
|
||||
for f=1,numforks do
|
||||
local new_angle=(math.pi*pr:next(-forkturnangle,forkturnangle)/180)+angle
|
||||
local forkmult=pr:next(forkmultn-forkmultdev, forkmultn+forkmultdev)/100
|
||||
if forkmult>1 then forkmult=1 end
|
||||
generate_vein_segment(name, wherein, minp, maxp, pr, end_pos, new_angle, forkmult*(rem_size-L), options, data, a, insideva)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function generate_vein(name, wherein, minp, maxp, seeddiff, options, data, a, insideva, second_call)
|
||||
local seed = get_bseed2(minp)
|
||||
options=get_or_default(options)
|
||||
|
||||
local numperblock=options.numperblock*1000
|
||||
local maxhdistance=options.maxhdistance
|
||||
local maxvdistance=options.maxvdistance
|
||||
local numbranchesn=options.numbranchesn
|
||||
local numbranchesdev=options.numbranchesdev
|
||||
local mothersizen=options.mothersizen*10
|
||||
local mothersizedev=options.mothersizedev*10
|
||||
local sizen=options.sizen
|
||||
local sizedev=options.sizedev
|
||||
|
||||
if second_call==nil then
|
||||
insideva = VoxelArea:new{MinEdge = minp, MaxEdge = maxp}
|
||||
local hblocks=math.floor(maxhdistance/80)+1
|
||||
local vblocks=math.floor(maxvdistance/80)+1
|
||||
for xblocksdiff=-hblocks,hblocks do
|
||||
for yblocksdiff=-vblocks,vblocks do
|
||||
for zblocksdiff=-hblocks,hblocks do
|
||||
if xblocksdiff~=0 or yblocksdiff~=0 or zblocksdiff~=0 then
|
||||
new_minp={x=minp.x+xblocksdiff*80,y=minp.y+yblocksdiff*80,z=minp.z+zblocksdiff*80}
|
||||
new_maxp={x=maxp.x+xblocksdiff*80,y=maxp.y+yblocksdiff*80,z=maxp.z+zblocksdiff*80}
|
||||
generate_vein(name, wherein, new_minp, new_maxp, seeddiff, options, data, a, insideva, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local pr = PseudoRandom(seed)
|
||||
|
||||
local numveins=math.floor(numperblock/1000)
|
||||
numperblock=numperblock-1000*numveins
|
||||
if pr:next(1,1000)<=numperblock then
|
||||
numveins=numveins+1
|
||||
end
|
||||
if numveins>0 then
|
||||
local min_y=math.max(options.minheight,minp.y)
|
||||
local max_y=math.min(options.maxheight,maxp.y)
|
||||
if min_y>max_y then return end
|
||||
for v=1,numveins do
|
||||
local vein_pos={x=pr:next(minp.x,maxp.x),y=pr:next(min_y,max_y),z=pr:next(minp.z,maxp.z)}
|
||||
local numbranches=pr:next(numbranchesn-numbranchesdev,numbranchesn+numbranchesdev)
|
||||
local mothersize=pr:next(mothersizen-mothersizedev,mothersizen+mothersizedev)/10
|
||||
|
||||
draw_sphere(name, wherein,vein_pos, mothersize, data, a, insideva)
|
||||
|
||||
local minpos = {x=vein_pos.x-maxhdistance,y=vein_pos.y-maxvdistance,z=vein_pos.z-maxhdistance}
|
||||
local maxpos = {x=vein_pos.x+maxhdistance,y=vein_pos.y+maxvdistance,z=vein_pos.z+maxhdistance}
|
||||
|
||||
for i=1,numbranches do
|
||||
local start_angle=math.pi*pr:next(0,359)/180
|
||||
local size=pr:next(sizen-sizedev,sizen+sizedev)
|
||||
generate_vein_segment(name, wherein, minpos, maxpos, pr, vein_pos, start_angle, size, options, data, a, insideva)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function get_or_default(options)
|
||||
if options.numperblock==nil then options.numperblock=0.3 end
|
||||
if options.maxhdistance==nil then options.maxhdistance=32 end
|
||||
if options.maxvdistance==nil then options.maxvdistance=32 end
|
||||
if options.numbranchesn==nil then options.numbranchesn=3 end
|
||||
if options.numbranchesdev==nil then options.numbranchesdev=2 end
|
||||
if options.mothersizen==nil then options.mothersizen=1 end
|
||||
if options.mothersizedev==nil then options.mothersizedev=0.5 end
|
||||
if options.sizen==nil then options.sizen=120 end
|
||||
if options.sizedev==nil then options.sizedev=60 end
|
||||
if options.seglenghtn==nil then options.seglenghtn=6 end
|
||||
if options.seglenghtdev==nil then options.seglenghtdev=2 end
|
||||
if options.segincln==nil then options.segincln=0.2 end
|
||||
if options.segincldev==nil then options.segincldev=0.1 end
|
||||
if options.turnangle==nil then options.turnangle=20 end
|
||||
if options.forkturnangle==nil then options.forkturnangle=90 end
|
||||
if options.fork_chance==nil then options.fork_chance=0.2 end
|
||||
if options.forkmultn==nil then options.forkmultn=0.75 end
|
||||
if options.forkmultdev==nil then options.forkmultdev=0.25 end
|
||||
if options.minheight==nil then options.minheight=-31000 end
|
||||
if options.maxheight==nil then options.maxheight=31000 end
|
||||
if options.radius==nil then options.radius=0 end
|
||||
return options
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user