mirror of
https://github.com/HybridDog/nether-pack.git
synced 2025-01-13 03:10:25 +01:00
use functions from vector_extras which should improve speed
This commit is contained in:
parent
163bd4a021
commit
b5807be921
@ -2,5 +2,6 @@ default
|
|||||||
glow
|
glow
|
||||||
riesenpilz
|
riesenpilz
|
||||||
stairs
|
stairs
|
||||||
|
vector_extras
|
||||||
fence_registration?
|
fence_registration?
|
||||||
watershed?
|
watershed?
|
||||||
|
112
nether/init.lua
112
nether/init.lua
@ -55,6 +55,9 @@ local mushroom_rarity = 80
|
|||||||
-- Frequency of trees in the nether forest (higher is less frequent)
|
-- Frequency of trees in the nether forest (higher is less frequent)
|
||||||
local tree_rarity = 200
|
local tree_rarity = 200
|
||||||
|
|
||||||
|
local abm_tree_interval = 864
|
||||||
|
local abm_tree_chance = 100
|
||||||
|
|
||||||
-- height of the nether generation's end
|
-- height of the nether generation's end
|
||||||
nether.start = f_h_max+100
|
nether.start = f_h_max+100
|
||||||
|
|
||||||
@ -689,6 +692,10 @@ function nether.grow_netherstructure(pos, generated)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local set = vector.set_data_to_pos
|
||||||
|
local get = vector.get_data_from_pos
|
||||||
|
local remove = vector.remove_data_from_pos
|
||||||
|
|
||||||
local function soft_node(id)
|
local function soft_node(id)
|
||||||
return id == c.air or id == c.ignore
|
return id == c.air or id == c.ignore
|
||||||
end
|
end
|
||||||
@ -698,7 +705,6 @@ local function update_minmax(min, max, p)
|
|||||||
max.x = math.max(max.x, p.x)
|
max.x = math.max(max.x, p.x)
|
||||||
min.z = math.min(min.z, p.z)
|
min.z = math.min(min.z, p.z)
|
||||||
max.z = math.max(max.z, p.z)
|
max.z = math.max(max.z, p.z)
|
||||||
return min, max
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local fruit_chances = {}
|
local fruit_chances = {}
|
||||||
@ -769,18 +775,18 @@ function nether.grow_tree(pos, generated)
|
|||||||
for j = 1,r do
|
for j = 1,r do
|
||||||
local x = p.x+j*dir[1]
|
local x = p.x+j*dir[1]
|
||||||
local z = p.z+j*dir[2]
|
local z = p.z+j*dir[2]
|
||||||
trunks[x.." "..p.y.." "..z] = dir[3]
|
set(trunks, z,p.y,x, dir[3])
|
||||||
end
|
end
|
||||||
r = r+1
|
r = r+1
|
||||||
p.x = p.x+r*dir[1]
|
p.x = p.x+r*dir[1]
|
||||||
p.z = p.z+r*dir[2]
|
p.z = p.z+r*dir[2]
|
||||||
trunk_corners[p.x.." "..p.y.." "..p.z] = dir[4] or dir[3]
|
set(trunk_corners, p.z,p.y,p.x, dir[4] or dir[3])
|
||||||
local h = math.random(h_arm_min, h_arm_max)
|
local h = math.random(h_arm_min, h_arm_max)
|
||||||
for i = 1,h do
|
for i = 1,h do
|
||||||
trunks[p.x.." "..p.y+i.." "..p.z] = true
|
set(trunks, p.z,p.y+i,p.x, true)
|
||||||
end
|
end
|
||||||
p.y = p.y+h
|
p.y = p.y+h
|
||||||
--n = #todo+1 -- causes small trees
|
--n = #todo+1 -- caused small trees
|
||||||
todo[#todo+1] = p
|
todo[#todo+1] = p
|
||||||
end
|
end
|
||||||
if p.y > pos.y+h_trunk_max then
|
if p.y > pos.y+h_trunk_max then
|
||||||
@ -793,13 +799,17 @@ function nether.grow_tree(pos, generated)
|
|||||||
local fruits = {}
|
local fruits = {}
|
||||||
local trunk_ps = {}
|
local trunk_ps = {}
|
||||||
local count = 0
|
local count = 0
|
||||||
for n,par in pairs(trunks) do
|
local ps, trmin, trmax, trunk_count = vector.get_data_pos_table(trunks)
|
||||||
local p = {}
|
|
||||||
p.x, p.y, p.z = unpack(string.split(n, " "))
|
update_minmax(min, max, trmin)
|
||||||
if par ~= true then
|
update_minmax(min, max, trmax)
|
||||||
p.par = par
|
|
||||||
|
for _,d in pairs(ps) do
|
||||||
|
if d[4] == true then
|
||||||
|
d[4] = nil
|
||||||
end
|
end
|
||||||
table.insert(trunk_ps, p)
|
trunk_ps[#trunk_ps+1] = d
|
||||||
|
local pz, py, px = unpack(d)
|
||||||
count = count+1
|
count = count+1
|
||||||
if count > leaf_thickness then
|
if count > leaf_thickness then
|
||||||
count = 0
|
count = 0
|
||||||
@ -807,18 +817,21 @@ function nether.grow_tree(pos, generated)
|
|||||||
local fruit_chance = fruit_chances[y]
|
local fruit_chance = fruit_chances[y]
|
||||||
for z = -2,2 do
|
for z = -2,2 do
|
||||||
for x = -2,2 do
|
for x = -2,2 do
|
||||||
local dist = math.sqrt(x*x+y*y+z*z)
|
local distq = x*x+y*y+z*z
|
||||||
if math.floor(dist) ~= 0
|
if distq ~= 0
|
||||||
and math.random(1, dist) == 1 then
|
and math.random(1, math.sqrt(distq)) == 1 then
|
||||||
local pstr = p.x+x.." "..p.y+y.." "..p.z+z
|
local x = x+px
|
||||||
if not trunks[pstr] then
|
local y = y+py
|
||||||
if math.random(1, fruit_rarity) == 1
|
local z = z+pz
|
||||||
and fruit_chance
|
if not get(trunks, z,y,x) then
|
||||||
|
if fruit_chance
|
||||||
|
and math.random(1, fruit_rarity) == 1
|
||||||
and math.random(1, fruit_chance) == 1 then
|
and math.random(1, fruit_chance) == 1 then
|
||||||
fruits[pstr] = true
|
set(fruits, z,y,x, true)
|
||||||
else
|
else
|
||||||
leaves[pstr] = true
|
set(leaves, z,y,x, true)
|
||||||
end
|
end
|
||||||
|
update_minmax(min, max, {x=x, z=z})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -827,37 +840,8 @@ function nether.grow_tree(pos, generated)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local leaf_ps = {}
|
|
||||||
for n,_ in pairs(leaves) do
|
|
||||||
local p = {}
|
|
||||||
p.x, p.y, p.z = unpack(string.split(n, " "))
|
|
||||||
table.insert(leaf_ps, p)
|
|
||||||
min, max = update_minmax(min, max, p)
|
|
||||||
end
|
|
||||||
|
|
||||||
for n,_ in pairs(trunks) do
|
|
||||||
local p = {}
|
|
||||||
p.x, _, p.z = unpack(string.split(n, " "))
|
|
||||||
min, max = update_minmax(min, max, p)
|
|
||||||
end
|
|
||||||
|
|
||||||
for i = -1,h_stem+1 do
|
for i = -1,h_stem+1 do
|
||||||
table.insert(trunk_ps, {x=pos.x, y=pos.y+i, z=pos.z, par=0})
|
trunk_ps[#trunk_ps+1] = {pos.z, pos.y+i, pos.x, 0} -- par 0 because of leaves
|
||||||
end
|
|
||||||
|
|
||||||
local trunk_corner_ps = {}
|
|
||||||
for n,par in pairs(trunk_corners) do
|
|
||||||
local p = {}
|
|
||||||
p.x, p.y, p.z = unpack(string.split(n, " "))
|
|
||||||
p.par = par
|
|
||||||
table.insert(trunk_corner_ps, p)
|
|
||||||
end
|
|
||||||
|
|
||||||
local fruit_ps = {}
|
|
||||||
for n,_ in pairs(fruits) do
|
|
||||||
local p = {}
|
|
||||||
p.x, p.y, p.z = unpack(string.split(n, " "))
|
|
||||||
table.insert(fruit_ps, p)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local manip = minetest.get_voxel_manip()
|
local manip = minetest.get_voxel_manip()
|
||||||
@ -866,8 +850,8 @@ function nether.grow_tree(pos, generated)
|
|||||||
local nodes = manip:get_data()
|
local nodes = manip:get_data()
|
||||||
local param2s = manip:get_param2_data()
|
local param2s = manip:get_param2_data()
|
||||||
|
|
||||||
for _,p in pairs(leaf_ps) do
|
for _,p in pairs(vector.get_data_pos_table(leaves)) do
|
||||||
p = area:indexp(p)
|
p = area:index(p[3], p[2], p[1])
|
||||||
if soft_node(nodes[p]) then
|
if soft_node(nodes[p]) then
|
||||||
nodes[p] = c.nether_leaves
|
nodes[p] = c.nether_leaves
|
||||||
param2s[p] = math.random(0,179)
|
param2s[p] = math.random(0,179)
|
||||||
@ -875,30 +859,28 @@ function nether.grow_tree(pos, generated)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _,p in pairs(fruit_ps) do
|
for _,p in pairs(vector.get_data_pos_table(fruits)) do
|
||||||
p = area:indexp(p)
|
p = area:index(p[3], p[2], p[1])
|
||||||
if soft_node(nodes[p]) then
|
if soft_node(nodes[p]) then
|
||||||
nodes[p] = c.nether_apple
|
nodes[p] = c.nether_apple
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _,p in pairs(trunk_ps) do
|
for _,p in pairs(trunk_ps) do
|
||||||
local par = p.par
|
local par = p[4]
|
||||||
p = area:indexp(p)
|
p = area:index(p[3], p[2], p[1])
|
||||||
if par then
|
if par then
|
||||||
param2s[p] = par
|
param2s[p] = par
|
||||||
end
|
end
|
||||||
nodes[p] = c.nether_tree
|
nodes[p] = c.nether_tree
|
||||||
end
|
end
|
||||||
|
|
||||||
for _,p in pairs(trunk_corner_ps) do
|
for _,p in pairs(vector.get_data_pos_table(trunk_corners)) do
|
||||||
local par = p.par
|
local vi = area:index(p[3], p[2], p[1])
|
||||||
p = area:indexp(p)
|
nodes[vi] = c.nether_tree_corner
|
||||||
nodes[p] = c.nether_tree_corner
|
param2s[vi] = p[4]
|
||||||
param2s[p] = par
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--calculating took ca. 0.07 - 0.18 [s]
|
|
||||||
manip:set_data(nodes)
|
manip:set_data(nodes)
|
||||||
manip:set_param2_data(param2s)
|
manip:set_param2_data(param2s)
|
||||||
manip:write_to_map()
|
manip:write_to_map()
|
||||||
@ -906,7 +888,7 @@ function nether.grow_tree(pos, generated)
|
|||||||
if generated then
|
if generated then
|
||||||
spam = 3
|
spam = 3
|
||||||
end
|
end
|
||||||
nether:inform("a nether tree grew at ("..pos.x.."|"..pos.y.."|"..pos.z..")", spam, t1)
|
nether:inform("a nether tree with "..trunk_count.." branch trunk nodes grew at ("..pos.x.."|"..pos.y.."|"..pos.z..")", spam, t1)
|
||||||
if not generated then
|
if not generated then
|
||||||
local t1 = os.clock()
|
local t1 = os.clock()
|
||||||
manip:update_map()
|
manip:update_map()
|
||||||
@ -935,8 +917,8 @@ minetest.register_abm({
|
|||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
nodenames = {"nether:tree_sapling"},
|
nodenames = {"nether:tree_sapling"},
|
||||||
neighbors = {"group:nether_dirt"},
|
neighbors = {"group:nether_dirt"},
|
||||||
interval = 864,
|
interval = abm_tree_interval,
|
||||||
chance = 100,
|
chance = abm_tree_chance,
|
||||||
action = function(pos)
|
action = function(pos)
|
||||||
if minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z}).name == "air"
|
if minetest.get_node({x=pos.x, y=pos.y+2, z=pos.z}).name == "air"
|
||||||
and minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" then
|
and minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" then
|
||||||
|
Loading…
Reference in New Issue
Block a user