Fix craft dispatch: add turtle attach/detach handlers, re-scan on craft, log failures

- Add peripheral_attach handler to auto-detect crafting turtle connecting after boot
- Update peripheral_detach handler to clear craftTurtleName when turtle disconnects
- Re-scan peripherals for turtle in display.lua craft handler if none known
- Add log.warn when craft turtle check fails (was silent notification only)
- Sync ctx.craftTurtleOk from broadcastState so display.lua has current value
This commit is contained in:
MayaTheShy
2026-03-22 22:26:10 -04:00
parent f095e18e95
commit 8b8279878a
2 changed files with 31 additions and 0 deletions

View File

@@ -1141,10 +1141,22 @@ local function buildSmelterPage()
local recipeIdx = event.selected.idx
local recipe = cfg.CRAFTABLE[recipeIdx]
if recipe then
-- Re-scan for turtle if none known
if not ctx.craftTurtleName then
for _, pName in ipairs(peripheral.getNames()) do
if pName:match("^turtle_") then
ctx.craftTurtleName = pName
log.info("CRAFT", "Turtle found on re-scan: %s", pName)
break
end
end
end
local turtleOk = ctx.craftTurtleOk
or (ctx.craftTurtleName
and peripheral.isPresent(ctx.craftTurtleName))
if not turtleOk then
log.warn("CRAFT", "No crafting turtle! (name=%s)",
tostring(ctx.craftTurtleName))
self.notification:error("No crafting turtle!")
return true
end