From f9d6fbdceaad9301751d4dd4086e7ac8c2af7ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Brada?= Date: Fri, 3 Jul 2015 21:26:19 +0200 Subject: [PATCH] Vein stuff. --- depositgen/init.lua | 2 +- depositgen/veins.lua | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/depositgen/init.lua b/depositgen/init.lua index 30ab51f..83d9147 100644 --- a/depositgen/init.lua +++ b/depositgen/init.lua @@ -15,7 +15,7 @@ l.OnInit={} l.ToResolve={} local includes={ -"pipes" --,"veins" +"pipes","veins" } minetest.register_on_generated(function(minp,maxp,seed) diff --git a/depositgen/veins.lua b/depositgen/veins.lua index bc22850..c847e0c 100644 --- a/depositgen/veins.lua +++ b/depositgen/veins.lua @@ -41,7 +41,7 @@ local sample_vein_def={ depositgen.register_vein(sample_vein_def) end -rocksl.genvein=function(minp,maxp,pr,vm,area) +local function generate(minp,maxp,pr,vm,area) local t1 = os.clock() local data = vm:get_data() @@ -49,9 +49,10 @@ rocksl.genvein=function(minp,maxp,pr,vm,area) local chunksize = chunksizer + 1 local pmapsize = {x = chunksize, y = chunksize, z = chunksize} local minpxz = {x = minp.x, y = minp.z} - local c_sample=minetest.get_content_id("default:stone") - local c_sample_ore=minetest.get_content_id("default:mese") + for _,descr in pairs(regs) do + local num = math.floor( (chunksize/descr.scarcity) + (pr:next(0,99)/100) ) + for vc=1, num do local A=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z) local B=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z) @@ -59,8 +60,7 @@ rocksl.genvein=function(minp,maxp,pr,vm,area) local D=vector.new(pr:next(0,chunksizer)+minp.x,pr:next(0,chunksizer)+minp.y,pr:next(0,chunksizer)+minp.z) local l1=vector.distance(A,C)+vector.distance(C,B) local l2=vector.distance(A,D)+vector.distance(D,B) - local step=1.4/math.max(l1,l2) - print("step="..step.." l1="..l1.." l2="..l2) + local step=2/math.max(l1,l2) local scarcity=6 local ocn=pr:next(0,scarcity)+(scarcity/2) for t=0, 1, step do @@ -71,17 +71,19 @@ rocksl.genvein=function(minp,maxp,pr,vm,area) local step2=1/vector.distance(P,Q) for u=0, 1, step2 do local R=vector.add(vector.multiply(P,(1-u)), vector.multiply(Q,u) ) + -- local di=area:indexp(vector.round(R)) - if ocn<1 then - data[di]=c_sample_ore - ocn=pr:next(0,scarcity)+(scarcity/2) - else - data[di]=c_sample - ocn=ocn-1 + if data[di] then + data[di]=descr.content.id end + -- end end + end + end vm:set_data(data) - minetest.log("action", "rocks/genvein/ "..math.ceil((os.clock() - t1) * 1000).." ms ") -end \ No newline at end of file + print("vein "..math.ceil((os.clock() - t1) * 1000).." ms ") +end + +table.insert(depositgen.l.OnGenerate,generate)