osmarks

smelt controller

Aug 2nd, 2021 (edited)
265
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local inchest = peripheral.wrap "quark:variant_chest_0"
  2. local outchest = peripheral.wrap "quark:variant_chest_1"
  3. local furns = {peripheral.find "mana-and-artifice:runeforge_tile_entity"}
  4.  
  5. local function find_next()
  6.     for k, v in pairs(inchest.list()) do return k end
  7. end
  8.  
  9. --[[
  10. local smelt = {
  11.     "minecraft:stone",
  12.     "minecraft:baked_potato"
  13. }
  14. local sset = {}
  15. for k, v in pairs(smelt) do sset[v] = true end
  16. ]]
  17.  
  18. local last_inputs = {}
  19.  
  20. local function commit()
  21.     local f = fs.open("state", "w")
  22.     f.write(textutils.serialise(last_inputs))
  23.     f.close()
  24. end
  25.  
  26. if fs.exists "state" then
  27.     local f = fs.open("state", "r")
  28.     last_inputs = textutils.unserialise(f.readAll())
  29.     f.close()
  30. end
  31.  
  32. while true do
  33.     for _, furn in pairs(furns) do
  34.         local nxt = find_next()
  35.         if nxt then
  36.             local idet = inchest.getItemDetail(nxt)
  37.             if inchest.pushItems(peripheral.getName(furn), nxt, 1, 1) then
  38.                 last_inputs[peripheral.getName(furn)] = idet.name
  39.                 print("insert", idet.displayName)
  40.                 commit()
  41.             end
  42.         end
  43.         local det = furn.getItemDetail(1)
  44.         if det and det.name ~= last_inputs[peripheral.getName(furn)] then
  45.             print("extract", det.displayName)
  46.             outchest.pullItems(peripheral.getName(furn), 1, 1)
  47.         end
  48.     end
  49.     sleep(1)
  50. end
RAW Paste Data