performance tweaks

This commit is contained in:
tenplus1 2023-08-01 10:27:43 +01:00
parent e8178108c7
commit d405bbd848

View File

@ -1,5 +1,6 @@
local nethermod = minetest.get_modpath("nether") local nethermod = minetest.get_modpath("nether")
local is_50 = minetest.has_feature("object_use_texture_alpha") local is_50 = minetest.has_feature("object_use_texture_alpha")
local mp = minetest.get_modpath("nssb")
nssb.mymapgenis = tonumber(minetest.settings:get("mymapgenis")) or 7 nssb.mymapgenis = tonumber(minetest.settings:get("mymapgenis")) or 7
@ -71,7 +72,7 @@ function nssb_register_buildings(
minetest.register_on_generated(function(minp, maxp, seed) minetest.register_on_generated(function(minp, maxp, seed)
if underground == false and maxp and maxp.y > 0 then if underground == false and minp and maxp and maxp.y > 0 then
local flag = 0 local flag = 0
local i, j, k, posd, pos1, pos2, pos3, n, u, d local i, j, k, posd, pos1, pos2, pos3, n, u, d
@ -87,24 +88,32 @@ function nssb_register_buildings(
n = minetest.get_node(pos1).name n = minetest.get_node(pos1).name
-- only continue if first node met and random chance is 1
-- random chance is here to save on future get_node's for performance
if n == posschem and random(rand) == 1 then
if downblock == nil then if downblock == nil then
u = nil u = nil
else else
u = minetest.get_node(pos2).name u = minetest.get_node(pos2).name
end end
-- continue if 2nd node met
if u == downblock then
if aboveblock == nil then if aboveblock == nil then
d = nil d = nil
else else
d = minetest.get_node(pos3).name d = minetest.get_node(pos3).name
end end
if n == posschem and u == downblock and d == aboveblock and flag == 0 -- continue if 3rd node met
and random(rand) == 1 then if d == aboveblock then
-- continue if node nearby met
if minetest.find_node_near(pos3, radius, near) then if minetest.find_node_near(pos3, radius, near) then
minetest.place_schematic(pos1, minetest.get_modpath("nssb") minetest.place_schematic(pos1, mp
.. "/schems/" .. build .. ".mts", "0", {}, true) .. "/schems/" .. build .. ".mts", "0", {}, true)
-- minetest.chat_send_all("Added schematic in "..(minetest.pos_to_string(pos1))) -- minetest.chat_send_all("Added schematic in "..(minetest.pos_to_string(pos1)))
@ -115,6 +124,8 @@ function nssb_register_buildings(
end end
end end
end end
end
end
local dy, f, fg, ntu local dy, f, fg, ntu
@ -185,12 +196,10 @@ function nssb_register_buildings(
minetest.chat_send_all("name prima di place_schematic:.."..name) minetest.chat_send_all("name prima di place_schematic:.."..name)
minetest.place_schematic(posplace, minetest.place_schematic(posplace, mp
minetest.get_modpath("nssb")
.. "/schems/memoportal.mts", "0", {}, true) .. "/schems/memoportal.mts", "0", {}, true)
-- minetest.place_schematic(posplace, -- minetest.place_schematic(posplace, mp
minetest.get_modpath("nssb")
.. "/schems/memoportal.mts", "0", {}, true) .. "/schems/memoportal.mts", "0", {}, true)
--minetest.chat_send_all("3") --minetest.chat_send_all("3")
@ -202,16 +211,15 @@ function nssb_register_buildings(
end, posplace) end, posplace)
end end
minetest.place_schematic(posplace, minetest.get_modpath("nssb") minetest.place_schematic(posplace, mp
.. "/schems/memoportal.mts", "0", {}, true) .. "/schems/memoportal.mts", "0", {}, true)
end end
]]-- ]]--
end end
else --underground == true else --underground == true
if minp and minp.y < 0 then if maxp and minp and minp.y < 0 then
-- minetest.chat_send_all("Posmin: " .. (minetest.pos_to_string(minp)).." Posmax: " .. (minetest.pos_to_string(maxp))) -- minetest.chat_send_all("Posmin: " .. (minetest.pos_to_string(minp)).." Posmax: " .. (minetest.pos_to_string(maxp)))
@ -244,11 +252,14 @@ function nssb_register_buildings(
else else
if n == posschem and random(rand) == 1 then if n == posschem and random(rand) == 1 then
minetest.place_schematic(pos1, minetest.get_modpath("nssb") -- error checking
if pos1.x and pos1.y and pos1.z then
minetest.place_schematic(pos1, mp
.. "/schems/" .. build .. ".mts", "0", {}, true) .. "/schems/" .. build .. ".mts", "0", {}, true)
-- minetest.chat_send_all("Added schematic in "..(minetest.pos_to_string(pos1))) -- minetest.chat_send_all("Added schematic in "..(minetest.pos_to_string(pos1)))
end
end end
end end
end end
@ -900,8 +911,9 @@ if posplace then
minetest.after(5, function(posplace) minetest.after(5, function(posplace)
minetest.place_schematic(posplace, minetest.get_modpath("nssb") minetest.place_schematic(posplace, mp
.. "/schems/memoportal.mts", 0, {}, true) .. "/schems/memoportal.mts", 0, {}, true)
end, posplace) end, posplace)
end end
@ -917,8 +929,6 @@ if posarena then
-- teleport the player -- teleport the player
minetest.after(5, function(posarena) minetest.after(5, function(posarena)
local mp = minetest.get_modpath("nssb")
minetest.place_schematic(posarena, mp .. "/schems/arena51.mts", "0", {}, true) minetest.place_schematic(posarena, mp .. "/schems/arena51.mts", "0", {}, true)
minetest.place_schematic({x = posarena.x, y = level - 96, z = posarena.z-9}, minetest.place_schematic({x = posarena.x, y = level - 96, z = posarena.z-9},
@ -983,8 +993,6 @@ minetest.register_abm({
-- minetest.chat_send_all("Ciao ciao pirloni") -- minetest.chat_send_all("Ciao ciao pirloni")
local mp = minetest.get_modpath("nssb")
minetest.place_schematic(posarena, mp .. "/schems/arena51.mts", "0", {}, true) minetest.place_schematic(posarena, mp .. "/schems/arena51.mts", "0", {}, true)
minetest.place_schematic({x = posarena.x, y = level - 96, z = posarena.z-9}, minetest.place_schematic({x = posarena.x, y = level - 96, z = posarena.z-9},