use swap_node where possible, for speed

This commit is contained in:
Vanessa Dannenberg 2018-10-25 10:27:29 -04:00
parent 61d1c54faf
commit 90a2d33707
3 changed files with 22 additions and 22 deletions

View File

@ -28,7 +28,7 @@ ftrunk.after_destruct = function(pos, oldnode)
-- minetest.dig_node(coconutpos) does not cause nearby coconuts to be dropped :-( ...
--minetest.dig_node(coconutpos)
local items = minetest.get_node_drops(minetest.get_node(coconutpos).name)
minetest.remove_node(coconutpos)
minetest.swap_node(coconutpos, biome_lib.air)
for _, itemname in pairs(items) do
minetest.add_item(coconutpos, itemname)
end
@ -56,7 +56,7 @@ local coconut_regrow_abm_spec = {
local coconutpos = {x=pos.x+dx, y=pos.y, z=pos.z+dz}
local coconutnode = minetest.get_node(coconutpos)
if coconutnode.name == "air" then
minetest.set_node(coconutpos, {name="moretrees:coconut_0"})
minetest.swap_node(coconutpos, {name="moretrees:coconut_0"})
end
end
end
@ -85,7 +85,7 @@ minetest.register_abm({
local gen
local count = 0
for _,gen in pairs(genlist) do
minetest.set_node(gen.pos, {name = "moretrees:coconut_3"})
minetest.swap_node(gen.pos, {name = "moretrees:coconut_3"})
count = count + 1
if count == 4 then
break
@ -115,7 +115,7 @@ local coconut_growfn = function(pos, elapsed)
minetest.add_item(pos, itemname)
end
end
minetest.remove_node(pos)
minetest.swap_node(pos, biome_lib.air)
end
else
-- Grow coconuts to the next stage
@ -240,7 +240,7 @@ if moretrees.coconuts_convert_existing_palms then
minetest.swap_node(tpos, {name = "moretrees:palm_fruit_trunk"})
coconuts = minetest.find_nodes_in_area({x=tpos.x-1, y=tpos.y, z=tpos.z-1}, {x=tpos.x+1, y=tpos.y, z=tpos.z+1}, "moretrees:coconut")
for _, coconutpos in pairs(coconuts) do
minetest.set_node(coconutpos, {name = "moretrees:coconut_3"})
minetest.swap_node(coconutpos, {name = "moretrees:coconut_3"})
end
end
end,

View File

@ -49,7 +49,7 @@ ftrunk.after_destruct = function(pos, oldnode)
for _,datespos in pairs(dates) do
-- minetest.dig_node(datespos) does not cause nearby dates to be dropped :-( ...
local items = minetest.get_node_drops(minetest.get_node(datespos).name)
minetest.remove_node(datespos)
minetest.swap_node(datespos, biome_lib.air)
for _, itemname in pairs(items) do
minetest.add_item(datespos, itemname)
end
@ -92,9 +92,9 @@ local date_regrow_abm_spec = {
local datenode = minetest.get_node(datepos)
if datenode.name == "air" then
if node.name == "moretrees:date_palm_ffruit_trunk" then
minetest.set_node(datepos, {name="moretrees:dates_f0"})
minetest.swap_node(datepos, {name="moretrees:dates_f0"})
else
minetest.set_node(datepos, {name="moretrees:dates_m0"})
minetest.swap_node(datepos, {name="moretrees:dates_m0"})
end
end
end
@ -126,9 +126,9 @@ minetest.register_abm({
for _,genpos in pairs(dates1) do
if math.random(100) <= 20 then
if type == "m" then
minetest.set_node(genpos, {name = "moretrees:dates_n"})
minetest.swap_node(genpos, {name = "moretrees:dates_n"})
else
minetest.set_node(genpos, {name = "moretrees:dates_f4"})
minetest.swap_node(genpos, {name = "moretrees:dates_f4"})
end
end
end
@ -136,9 +136,9 @@ minetest.register_abm({
for _,genpos in pairs(dates2) do
if math.random(100) <= 5 then
if type == "m" then
minetest.set_node(genpos, {name = "moretrees:dates_n"})
minetest.swap_node(genpos, {name = "moretrees:dates_n"})
else
minetest.set_node(genpos, {name = "moretrees:dates_f4"})
minetest.swap_node(genpos, {name = "moretrees:dates_f4"})
end
end
end
@ -538,7 +538,7 @@ local dates_growfn = function(pos, elapsed)
elseif string.find(node.name, "moretrees:dates_m") then
minetest.swap_node(pos, {name="moretrees:dates_n"})
else
minetest.remove_node(pos)
minetest.swap_node(pos, biome_lib.air)
end
return
elseif node.name == "moretrees:dates_f0" and math.random(100) <= 100 * dates_regrow_prob then
@ -578,7 +578,7 @@ local dates_growfn = function(pos, elapsed)
elseif string.match(node.name, "n$") then
-- Remove stems.
if math.random(stems_drop_ichance) == 1 then
minetest.remove_node(pos)
minetest.swap_node(pos, biome_lib.air)
return "stemdrop"
end
action = "nostemdrop"

View File

@ -185,7 +185,7 @@ end
-- Code to spawn a birch tree
function moretrees.grow_birch(pos)
minetest.remove_node(pos)
minetest.swap_node(pos, biome_lib.air)
if math.random(1,2) == 1 then
minetest.spawn_tree(pos, moretrees.birch_model1)
else
@ -196,7 +196,7 @@ end
-- Code to spawn a spruce tree
function moretrees.grow_spruce(pos)
minetest.remove_node(pos)
minetest.swap_node(pos, biome_lib.air)
if math.random(1,2) == 1 then
minetest.spawn_tree(pos, moretrees.spruce_model1)
else
@ -250,10 +250,10 @@ function moretrees.grow_jungletree(pos)
moretrees.jungletree_model.rules_b = moretrees.jt_rules_b2
end
minetest.remove_node(pos)
minetest.swap_node(pos, biome_lib.air)
local leaves = minetest.find_nodes_in_area({x = pos.x-1, y = pos.y, z = pos.z-1}, {x = pos.x+1, y = pos.y+10, z = pos.z+1}, "default:leaves")
for leaf in ipairs(leaves) do
minetest.remove_node(leaves[leaf])
minetest.swap_node(leaves[leaf], biome_lib.air)
end
minetest.spawn_tree(pos, moretrees.jungletree_model)
end
@ -277,10 +277,10 @@ function moretrees.grow_fir(pos)
moretrees.fir_model.iterations = 7
moretrees.fir_model.random_level = 5
minetest.remove_node(pos)
minetest.swap_node(pos, biome_lib.air)
local leaves = minetest.find_nodes_in_area({x = pos.x, y = pos.y, z = pos.z}, {x = pos.x, y = pos.y+5, z = pos.z}, "default:leaves")
for leaf in ipairs(leaves) do
minetest.remove_node(leaves[leaf])
minetest.swap_node(leaves[leaf], biome_lib.air)
end
minetest.spawn_tree(pos,moretrees.fir_model)
end
@ -304,10 +304,10 @@ function moretrees.grow_fir_snow(pos)
moretrees.fir_model.iterations = 2
moretrees.fir_model.random_level = 2
minetest.remove_node(pos)
minetest.swap_node(pos, biome_lib.air)
local leaves = minetest.find_nodes_in_area({x = pos.x, y = pos.y, z = pos.z}, {x = pos.x, y = pos.y+5, z = pos.z}, "default:leaves")
for leaf in ipairs(leaves) do
minetest.remove_node(leaves[leaf])
minetest.swap_node(leaves[leaf], biome_lib.air)
end
minetest.spawn_tree(pos,moretrees.fir_model)
end