Skip to content

Commit f1f96db

Browse files
tenplus1paramat
authored andcommittedJul 10, 2016
Default/trees: Faster way to detect snow around pine saplings
Instead of using voxelmanip use 'find nodes in area' instead
1 parent 5943653 commit f1f96db

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed
 

Diff for: ‎mods/default/trees.lua

+4-27
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,10 @@ end
2727
-- 'is snow nearby' function
2828

2929
local function is_snow_nearby(pos)
30-
local x, y, z = pos.x, pos.y, pos.z
31-
local c_snow = minetest.get_content_id("default:snow")
32-
local c_snowblock = minetest.get_content_id("default:snowblock")
33-
local c_dirtsnow = minetest.get_content_id("default:dirt_with_snow")
34-
35-
local vm = minetest.get_voxel_manip()
36-
local minp, maxp = vm:read_from_map(
37-
{x = x - 1, y = y - 1, z = z - 1},
38-
{x = x + 1, y = y + 1, z = z + 1}
39-
)
40-
local a = VoxelArea:new({MinEdge = minp, MaxEdge = maxp})
41-
local data = vm:get_data()
42-
43-
for yy = y - 1, y + 1 do
44-
for zz = z - 1, z + 1 do
45-
local vi = a:index(x - 1, yy, zz)
46-
for xx = x - 1, x + 1 do
47-
local nodid = data[vi]
48-
if nodid == c_snow or nodid == c_snowblock or nodid == c_dirtsnow then
49-
return true
50-
end
51-
vi = vi + 1
52-
end
53-
end
54-
end
55-
56-
return false
30+
return #minetest.find_nodes_in_area(
31+
{x = pos.x - 1, y = pos.y - 1, z = pos.z - 1},
32+
{x = pos.x + 1, y = pos.y + 1, z = pos.z + 1},
33+
{"default:snow", "default:snowblock", "default:dirt_with_snow"}) > 0
5734
end
5835

5936

0 commit comments

Comments
 (0)
Please sign in to comment.