@@ -172,33 +172,10 @@ end
172172
173173-- GetTreeMat returns the material of the tree at the given tile or nil if the tile does not have a
174174-- tree or giant mushroom.
175- -- Currently roots are ignored.
176175function GetTreeMat (x , y , z )
177176 local pos = prepPos (x , y , z )
178-
179- local function coordInTree (pos , tree )
180- local x1 = tree .pos .x - math.floor (tree .tree_info .dim_x / 2 )
181- local x2 = tree .pos .x + math.floor (tree .tree_info .dim_x / 2 )
182- local y1 = tree .pos .y - math.floor (tree .tree_info .dim_y / 2 )
183- local y2 = tree .pos .y + math.floor (tree .tree_info .dim_y / 2 )
184- local z1 = tree .pos .z
185- local z2 = tree .pos .z + tree .tree_info .body_height
186-
187- if not ((pos .x >= x1 and pos .x <= x2 ) and (pos .y >= y1 and pos .y <= y2 ) and (pos .z >= z1 and pos .z <= z2 )) then
188- return false
189- end
190-
191- return not tree .tree_info .body [pos .z - tree .pos .z ]:_displace ((pos .y - y1 ) * tree .tree_info .dim_x + (pos .x - x1 )).blocked
192- end
193-
194- for _ , tree in ipairs (df .global .world .plants .all ) do
195- if tree .tree_info ~= nil then
196- if coordInTree (pos , tree ) then
197- return dfhack .matinfo .decode (419 , tree .material )
198- end
199- end
200- end
201- return nil
177+ local plant = dfhack .maps .getPlantAtTile (pos )
178+ return plant and plant .tree_info and dfhack .matinfo .decode (419 , plant .material ) or nil
202179end
203180
204181-- GetShrubMat returns the material of the shrub at the given tile or nil if the tile does not
@@ -289,7 +266,7 @@ BasicMats = {
289266 [df .tiletype_material .DRIFTWOOD ] = GetLayerMat ,
290267 [df .tiletype_material .POOL ] = GetLayerMat ,
291268 [df .tiletype_material .BROOK ] = GetLayerMat ,
292- [df .tiletype_material .ROOT ] = GetLayerMat ,
269+ [df .tiletype_material .ROOT ] = GetTreeMat ,
293270 [df .tiletype_material .TREE ] = GetTreeMat ,
294271 [df .tiletype_material .MUSHROOM ] = GetTreeMat ,
295272 [df .tiletype_material .UNDERWORLD_GATE ] = nil , -- I guess this is for the gates found in vaults?
@@ -327,6 +304,7 @@ OnlyPlantMats = {
327304 [df .tiletype_material .GRASS_DRY ] = GetGrassMat ,
328305 [df .tiletype_material .GRASS_DEAD ] = GetGrassMat ,
329306 [df .tiletype_material .PLANT ] = GetShrubMat ,
307+ [df .tiletype_material .ROOT ] = GetTreeMat ,
330308 [df .tiletype_material .TREE ] = GetTreeMat ,
331309 [df .tiletype_material .MUSHROOM ] = GetTreeMat ,
332310}
0 commit comments