Advertisement
DuckStrom

Computercraft Comb Centrifuge Controller

Apr 8th, 2019
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.57 KB | None | 0 0
  1. -- Location of machine relative to interface
  2. ex_dir = "down"
  3. -- limit of items per type to do in a row
  4. limit_per_type = 256
  5.  
  6. wl_enabled = true
  7. bl_enabled = true
  8.  
  9. me = peripheral.find("tileinterface")
  10. curr = nil
  11.  
  12. -- List of processable items with item name stored as key, and processable metadatas stored as values
  13. -- Evaluated before the blacklist
  14. whitelist = {
  15.   -- ["RotaryCraft:rotarycraft_item_canola"]={0,2},
  16.   ["RotaryCraft:rotarycraft_item_powders"]={2}
  17. }
  18.  
  19. -- List of processable items with item name stored as key, and NON-processable metadatas stored as values
  20. blacklist = {
  21.   ["ChromatiCraft:chromaticraft_item_coloredmod"]={},
  22.   ["ExtraBees:honeyComb"]={},
  23.   ["Forestry:beeCombs"]={},
  24.   ["MagicBees:comb"]={},
  25.   ["RotaryCraft:rotarycraft_item_modinterface"]={},
  26.   ["computronics:computronics.partsForestry"]={},
  27.   ["gendustry:HoneyComb"]={},
  28.   ["Forestry:propolis"]={0,1,2},
  29.   ["MagicBees:propolis"]={0},
  30.   ["ExtraBees:propolis"]={0}
  31. }
  32.  
  33. function isOre(name,ID)
  34.   if wl_enabled and whitelist[name] ~= nil then
  35.     for k,v in ipairs(whitelist[name]) do
  36.       if v == ID then
  37.         return true
  38.       end
  39.     end
  40.   end
  41.  
  42.   if bl_enabled and blacklist[name] ~= nil then
  43.     for k,v in ipairs(blacklist[name]) do
  44.       if v == ID then
  45.         return false
  46.       end
  47.     end
  48.    
  49.     return true
  50.   end
  51.   return false
  52. end
  53.  
  54. function extractFlakes()
  55.   ct = 0
  56.   i = 1
  57.   while i < 9 do
  58.     t = me.pullItem(ex_dir,i,128)
  59.     ct = ct + t
  60.     if t then
  61.       i = i + 1
  62.     else
  63.       i = 9
  64.     end
  65.   end
  66.   return ct
  67. end
  68.  
  69. function mainLoop()
  70.   no_ore = 0
  71.   while true do
  72.     no_ore = math.min(no_ore + 1, 10)
  73.     inv = me.getAvailableItems()
  74.     if inv[1] ~= nil then
  75.       for k,v in ipairs(inv) do
  76.         if isOre(v.fingerprint.id, v.fingerprint.dmg) then
  77.           no_ore = 0
  78.           print("Processing " .. v.fingerprint.id .. ":" .. v.fingerprint.dmg)
  79.           curr = v
  80.           remaining = v.size < limit_per_type and v.size or limit_per_type
  81.           while remaining > 0 do
  82.             extractFlakes()
  83.             pc, results = pcall(me.exportItem, v.fingerprint, ex_dir, remaining > 64 and 64 or remaining)
  84.             if pc == true then
  85.               remaining = remaining - results.size
  86.               sleep(0.1)
  87.             else
  88.               remaining = 0
  89.             end
  90.           end
  91.           v = nil
  92.         end -- if isOre()
  93.       end --  for k,v in ipairs(inv) do
  94.     end --  if inv[1] ~= nil then
  95.     if (no_ore > 0) then -- hack to make sure flakes get extracted fully
  96.       ex_rem = 2
  97.       while (ex_rem > 1) do
  98.         ex_rem = ex_rem + extractFlakes()
  99.         ex_rem = ex_rem / 2
  100.         -- print("ex_rem: " .. ex_rem)
  101.         sleep(2)
  102.       end
  103.     end
  104.     sleep(no_ore > 0 and math.min(math.pow(2,no_ore),64) or 0)
  105.   end -- while true do
  106. end
  107.  
  108. function skipLoop()
  109.   while true do
  110.     event, key = os.pullEvent("key")
  111.       if key == keys.enter then
  112.         if curr ~= nil then
  113.           print("Skipping " .. curr.fingerprint.id .. ":" .. curr.fingerprint.dmg)
  114.           remaining = 0
  115.         else
  116.           print("Nothing to skip")
  117.         end
  118.       elseif key == keys.b then
  119.         bl_enabled = not bl_enabled
  120.         print("Blackist processing " .. tostring(bl_enabled))
  121.       elseif key == keys.w then
  122.         wl_enabled = not wl_enabled
  123.         print("Whitelist processing " .. tostring(wl_enabled))
  124.       end
  125.    end
  126. end
  127.  
  128. extractFlakes()
  129. print("Blacklist enabled: " .. tostring(bl_enabled) .. "\nWhitelist enabled: " .. tostring(wl_enabled) .. "\nWorking...")
  130. parallel.waitForAll(mainLoop,skipLoop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement