-- -- extract_test.lua -- -- Can we get a data model OUT of a sim chamber by ANY CC method? Run on the -- chamber RTU computer with a model in a chamber and one empty barrel present. -- -- extract_test -- local CHAMBER = "hostilenetworks:sim_chamber" local BARREL = "minecraft:barrel" local MODEL = "data_model" local CAT = "prediction_matrix" local function names(t) local o = {} for _, n in ipairs(peripheral.getNames()) do if peripheral.getType(n) == t then o[#o+1] = n end end table.sort(o); return o end -- chamber with a model local chName, chP, mSlot, catSlot for _, n in ipairs(names(CHAMBER)) do local p = peripheral.wrap(n) local ok, list = pcall(p.list) if ok and list then local ms, cs for s, it in pairs(list) do if it.name and it.name:find(MODEL) then ms = s elseif it.name and it.name:find(CAT) then cs = s end end if ms then chName, chP, mSlot, catSlot = n, p, ms, cs; break end end end if not chName then print("no chamber holds a model"); return end -- an empty barrel local barName for _, n in ipairs(names(BARREL)) do local ok, list = pcall(peripheral.wrap(n).list) if ok and (not list or next(list) == nil) then barName = n; break end end if not barName then print("no empty barrel available"); return end local barP = peripheral.wrap(barName) print("chamber: " .. chName .. " modelSlot=" .. tostring(mSlot) .. " catSlot=" .. tostring(catSlot)) print("barrel : " .. barName) print("") local function barHasModel() local ok, list = pcall(barP.list) if ok and list then for s, it in pairs(list) do if it.name:find(MODEL) then return s end end end end -- TEST 1: barrel PULLS the model from the chamber local okA, mA = pcall(barP.pullItems, chName, mSlot, 1) print(string.format("1) barrel.pullItems(chamber, modelSlot) -> ok=%s moved=%s", tostring(okA), tostring(mA))) local bs = barHasModel() if bs then print(" => the model IS extractable via pullItems! putting it back."); pcall(barP.pushItems, chName, bs) return end -- TEST 2: chamber PUSHES the model to the barrel local okB, mB = pcall(chP.pushItems, barName, mSlot, 1) print(string.format("2) chamber.pushItems(barrel, modelSlot) -> ok=%s moved=%s", tostring(okB), tostring(mB))) bs = barHasModel() if bs then print(" => extractable via pushItems! putting it back."); pcall(barP.pushItems, chName, bs) return end -- TEST 3: can we even pull the CATALYST out? (is ANY slot extractable?) if catSlot then local okC, mC = pcall(barP.pullItems, chName, catSlot, 1) print(string.format("3) barrel.pullItems(chamber, catSlot) -> ok=%s moved=%s", tostring(okC), tostring(mC))) -- return any catalyst we pulled local ok, list = pcall(barP.list) if ok and list then for s, it in pairs(list) do if it.name:find(CAT) then pcall(barP.pushItems, chName, s) end end end end print("") print("If (1) and (2) both moved 0 but (3) moved a catalyst, the chamber blocks") print("MODEL extraction specifically. If (3) is also 0, the whole chamber is") print("locked to automation and models can't be pulled by CC at all.")