-- -- dc_diag.lua -- -- Diagnoses dc.lua's auto-detection: what config.lua has explicitly, what -- candidates it finds on the network for the ME bridge / barrels / ports, and -- what it resolved each role to (and why, if something's ambiguous). -- -- dc_diag -- require("/initenv").init_env() local facility = require("facility") local dclib = require("dc") local cfg = facility.load_config() print("=== config.lua explicit fields ===") print("dc_model_store : " .. tostring(cfg.dc_model_store)) print("dc_model_source : " .. tostring(cfg.dc_model_source)) print("dc_input_source : " .. tostring(cfg.dc_input_source)) print("dc_model_port : " .. tostring(cfg.dc_model_port)) print("dc_input_port : " .. tostring(cfg.dc_input_port)) print("dc_output_port : " .. tostring(cfg.dc_output_port)) print("dc_output_sink : " .. tostring(cfg.dc_output_sink)) local BARREL_TYPE = cfg.barrel_type or "minecraft:barrel" -- bridge detection is now CAPABILITY-based (has a list + export method), not a -- type-string guess - print every peripheral's type alongside so a mismatch -- like the "meBridge" vs "me_bridge" one is obvious at a glance print("") print("=== every peripheral on this network ===") for _, n in ipairs(peripheral.getNames()) do print(" " .. n .. " [" .. tostring(peripheral.getType(n)) .. "]") end print("") print("=== candidates on this network ===") local bridges, barrels, ports = {}, {}, {} for _, n in ipairs(peripheral.getNames()) do local t = peripheral.getType(n) local methods = peripheral.getMethods(n) if methods then local has = {} for _, mth in ipairs(methods) do has[mth] = true end local looksLikeBridge = (has.listItems or has.getItems) and (has.exportItemToPeripheral or has.exportItem) if looksLikeBridge then bridges[#bridges+1] = n end end if t == BARREL_TYPE then barrels[#barrels+1] = n end if t == (cfg.port_type or "hostilenetworks:data_center_io_port") then ports[#ports+1] = n end end print("storage bridges (" .. #bridges .. "): " .. table.concat(bridges, ", ")) print("barrels (" .. #barrels .. "): " .. table.concat(barrels, ", ")) print("io ports (" .. #ports .. "): " .. table.concat(ports, ", ")) print("") print("=== barrel contents (used for role classification) ===") for _, n in ipairs(barrels) do local p = peripheral.wrap(n) local ok, list = pcall(p.list) local hasCatalyst, hasModel, itemCount = false, false, 0 if ok and list then for _, item in pairs(list) do itemCount = itemCount + item.count if item.name:find("prediction_matrix") then hasCatalyst = true end if item.name:find("data_model") then hasModel = true end end end print(string.format(" %s: %d item(s), catalyst=%s, model=%s", n, itemCount, tostring(hasCatalyst), tostring(hasModel))) end print("") print("=== storage bridge contents (if any) ===") for _, n in ipairs(bridges) do local b = peripheral.wrap(n) local methods = peripheral.getMethods(n) local has = {} for _, mth in ipairs(methods) do has[mth] = true end local listFn = has.listItems and "listItems" or (has.getItems and "getItems" or nil) print(" " .. n .. " uses: " .. tostring(listFn)) local ok, items if listFn == "listItems" then ok, items = pcall(b.listItems) elseif listFn == "getItems" then ok, items = pcall(b.getItems, {}) else ok, items = false, "no list method found" end if ok and type(items) == "table" then local models = 0 for _, it in ipairs(items) do if it.name and it.name:find("data_model") then models = models + 1 print(" " .. n .. " has: " .. tostring(it.displayName) .. " x" .. tostring(it.amount or it.count) .. " fingerprint=" .. tostring(it.fingerprint)) end end if models == 0 then print(" " .. n .. ": no data models found") end else print(" " .. n .. ": list failed - " .. tostring(items)) end end print("") print("=== dc.lua's actual resolution (may error if 0 ports found) ===") local ok, dc = pcall(dclib.new, cfg) if not ok then print("dc.new() FAILED: " .. tostring(dc)) return end local r = dc.resolved print("input_port = " .. tostring(r.input_port)) print("model_port = " .. tostring(r.model_port)) print("output_port = " .. tostring(r.output_port)) print("model_store = " .. tostring(r.model_store)) print("model_source = " .. tostring(r.model_source)) print("input_source = " .. tostring(r.input_source)) print("output_sink = " .. tostring(r.output_sink)) if not r.output_sink then print(" ^ nil = the 24/7 drain moves nothing. An EMPTY loot barrel looks") print(" identical to the staging barrel, so contents can't tell them") print(" apart; set dc_output_sink explicitly if the positional fallback") print(" (lowest plain barrel = staging, highest = sink) got it wrong.") end print("") print("=== what the coordinator picker would see (scanSourceModels via collect) ===") local okc, st = pcall(dc.collect) if okc then if #st.available == 0 then print("available = EMPTY - this is why the coordinator sees nothing") else for _, mo in ipairs(st.available) do print(" available: " .. mo.disp .. " x" .. mo.count) end end else print("collect() FAILED: " .. tostring(st)) end print("") print("=== live test: push 1 model from model_source into model_port ===") if r.model_source and r.model_port then local srcP = peripheral.wrap(r.model_source) local okl, list = pcall(srcP.list) local slot, itemName if okl and list then for s, item in pairs(list) do if item.name:find("data_model") then slot, itemName = s, item.name; break end end end if not slot then print("no data model currently sitting in " .. r.model_source .. " to test with") print("(the earlier load must have already been consumed, or never landed here)") else print("found " .. tostring(itemName) .. " in slot " .. slot .. " of " .. r.model_source) local ok2, moved = pcall(srcP.pushItems, r.model_port, slot) print("pushItems(" .. r.model_port .. ", slot=" .. slot .. ") -> ok=" .. tostring(ok2) .. " result=" .. tostring(moved)) if ok2 and moved and moved > 0 then print("SUCCESS - it moved. Check the data center's slot grid now.") elseif ok2 then print("pushItems ran but moved 0 - port likely full, wrong proxy mode, or item rejected") else print("pushItems THREW - likely not on the same wired network") end end else print("model_source or model_port didn't resolve, cannot test") end print("") print("=== live test: drain the output port into the sink ===") if r.output_port and r.output_sink then local outP = peripheral.wrap(r.output_port) local okl, list = pcall(outP.list) local n = 0 if okl and list then for _, item in pairs(list) do n = n + item.count end end print("output port " .. r.output_port .. " holds " .. n .. " item(s)") if n == 0 then print("nothing to drain right now - let the data center produce some loot first") else local moved, err = dc.pull_output() print("pull_output() -> " .. tostring(moved) .. " " .. (type(err) == "table" and ("moved=" .. tostring(err.moved)) or tostring(err))) end else print("output_port or output_sink didn't resolve, cannot test") end