Pick the nearest node you can reach
A vein up a ridge 20 yd away may have no way up, and one behind a hill may be a 120 yd walk. Ask check_spots for
all candidates at once and pick by the real walk, not the straight line.
local bad = {} -- spots found unreachable, by key, so they are not asked again
local function key(p) return ("%d:%d"):format(math.floor(p.x / 2), math.floor(p.y / 2)) end
-- candidates: { { x, y, z }, ... } e.g. the veins your plugin sees (up to 64)
local function go_to_best(candidates, on_done)
local client = _G.AXIOM_NAV and _G.AXIOM_NAV.client
if not client then return end
local ask = {}
for _, p in ipairs(candidates) do
if not bad[key(p)] then ask[#ask + 1] = p end
end
if #ask == 0 then return on_done(false, "nothing reachable") end
client:check_spots(ask, function(ok, results)
if not ok then return on_done(false, "no answer") end
local best, best_walk
for i, r in ipairs(results) do
if r.reachable then
if not best_walk or r.walk < best_walk then best, best_walk = i, r.walk end
elseif not r.gave_up then
bad[key(ask[i])] = true -- surely unreachable: never ask again
end
end
if not best then return on_done(false, "nothing reachable") end
local p = ask[best]
local floor = results[best].floor
client:move_to({ x = p.x, y = p.y, z = floor or p.z }, function(arrived, why)
if not arrived and why == "unreachable" then bad[key(p)] = true end
on_done(arrived, why, p)
end, { jump_fences = true })
end)
endNotes
gave_up = truemeans the search stopped before it knew (far away). It may be reachable: ask again from nearer.- Still handle
unreachablefrommove_to. The world changes (a door, a mob in the way). - A point with no height (a search point on a map): send
z = 0.r.flooris the ground there. - With
jump_fences, low ore rocks are jumped; a walk to a vein still ends beside it, within reach to mine.