Skip to content
Snippets Groups Projects
Commit f1f96dbe authored by tenplus1's avatar tenplus1 Committed by paramat
Browse files

Default/trees: Faster way to detect snow around pine saplings

Instead of using voxelmanip use 'find nodes in area' instead
parent 59436531
Branches
No related tags found
No related merge requests found
......@@ -27,33 +27,10 @@ end
-- 'is snow nearby' function
local function is_snow_nearby(pos)
local x, y, z = pos.x, pos.y, pos.z
local c_snow = minetest.get_content_id("default:snow")
local c_snowblock = minetest.get_content_id("default:snowblock")
local c_dirtsnow = minetest.get_content_id("default:dirt_with_snow")
local vm = minetest.get_voxel_manip()
local minp, maxp = vm:read_from_map(
{x = x - 1, y = y - 1, z = z - 1},
{x = x + 1, y = y + 1, z = z + 1}
)
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
local data = vm:get_data()
for yy = y - 1, y + 1 do
for zz = z - 1, z + 1 do
local vi = a:index(x - 1, yy, zz)
for xx = x - 1, x + 1 do
local nodid = data[vi]
if nodid == c_snow or nodid == c_snowblock or nodid == c_dirtsnow then
return true
end
vi = vi + 1
end
end
end
return false
return #minetest.find_nodes_in_area(
{x = pos.x - 1, y = pos.y - 1, z = pos.z - 1},
{x = pos.x + 1, y = pos.y + 1, z = pos.z + 1},
{"default:snow", "default:snowblock", "default:dirt_with_snow"}) > 0
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment