1 -- experimental slow pipe generator
3 local function brush(data
,area
,pos
,radius
,content
,ores
,pr
)
8 for _
,ore
in pairs(ores
) do
9 if pr
:next(0,ore
.scarcity
)==0 then
14 for x
=-radius
, radius
do
15 for y
=-radius
, radius
do
16 for z
=-radius
, radius
do
17 if (x^
2)+(y^
2)+(z^
2)<=rsq
then
18 local di
=area
:index(x
+pos
.x
,y
+pos
.y
,z
+pos
.z
)
19 if oresc
and (pr
:next(0,oresc
)==0) then
28 -- the public table of registered pipes
31 bedrock
={ "rocks:limestone" },
32 startrock
={ "rocks:limestone" },
36 content
="default:wood",
39 { scarcity
=7, density
=4, ore
="default:mese", cnt
=0},
42 table.insert(rocks
.pipes
,examplepipe
)
44 table.insert(rocks
.pipes
,{
45 bedrock
={ "rocks:limestone" },
46 startrock
={ "rocks:limestone" },
50 content
="default:dirt",
53 { scarcity
=5, density
=4, ore
="default:mese", cnt
=0},
57 rocksl
.genpipe
=function(minp
,maxp
,pr
,vm
,area
,descr
)
59 local data
= vm
:get_data()
61 local chunksizer
= maxp
.x
- minp
.x
+ 1
62 local chunksize
= chunksizer
+ 1
63 local pmapsize
= {x
= chunksize
, y
= chunksize
, z
= chunksize
}
64 local minpxz
= {x
= minp
.x
, y
= minp
.z
}
67 for _
,node
in pairs(descr
.bedrock
) do bedrocks
[minetest
.get_content_id(node
)]=true end
69 for _
,node
in pairs(descr
.startrock
) do startrocks
[minetest
.get_content_id(node
)]=true end
70 local content
=minetest
.get_content_id(descr
.content
)
71 for _
,des
in pairs(descr
.scatter
) do
72 des
.c_ore
=minetest
.get_content_id(des
.ore
)
74 local orepr
=PseudoRandom(pr
:next())
76 local numpipes_raw
=(chunksize
/descr
.scarcity
)
77 local numpipes
= math
.floor(numpipes_raw
+ (pr
:next(0,99)/100))
80 local pointA
=vector
.new(pr
:next(0,chunksizer
)+minp
.x
,pr
:next(0,chunksizer
)+minp
.y
,pr
:next(0,chunksizer
)+minp
.z
)
81 if (#startrocks
>0)and(startrocks
[data
[area
:indexp(pointA
)]]
==nil) then break end
82 local pointB
=vector
.new(pr
:next(0,chunksizer
)+minp
.x
,pr
:next(0,chunksizer
)+minp
.y
,pr
:next(0,chunksizer
)+minp
.z
)
83 local pointC
=vector
.new(pr
:next(0,chunksizer
)+minp
.x
,pr
:next(0,chunksizer
)+minp
.y
,pr
:next(0,chunksizer
)+minp
.z
)
84 local step
=(1.8*descr
.radius
)/(vector
.distance(pointA
,pointB
)+vector
.distance(pointB
,pointC
))
86 local p
=vector
.multiply(pointA
,(1-t
)^
2)
87 p
=vector
.add(p
, vector
.multiply(pointB
,2*t
*(1-t
)) )
88 p
=vector
.add(p
, vector
.multiply(pointC
,t
*t
) )
90 brush(data
,area
,p
,descr
.radius
,content
,descr
.scatter
,orepr
)
95 minetest
.log("action", "rocks/genpipe/ "..math
.ceil((os
.clock() - t1
) * 1000).." ms ")