Advertisement
Wassaa

extract

Jan 7th, 2014
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.09 KB | None | 0 0
  1. local chest = peripheral.wrap("back")
  2. local oreExt = peripheral.wrap("extractor_6")   -- ore extractor
  3. local dustExt = peripheral.wrap("extractor_7") -- dust extractor
  4. local size = chest.getInventorySize()
  5. local oresDir = "south"
  6. local dustsDir = "north"
  7. local redOre = "left"
  8. local redDust = "right"
  9. sentOres = 0
  10. sentDusts = 0
  11. rs.setOutput(redDust, true)
  12. rs.setOutput(redOre, true)
  13. local oArray = {"15:0", --iron ore
  14.                      "30888:17", --iron solution
  15.                      "14:0", --gold
  16.                      "30888:18"}
  17. local dArray =  {"30888:1", --iron dust
  18.                      "30888:9", --iron slurry
  19.                      "30888:2", --gold dust
  20.                      "30888:10"}
  21. print("size is: " .. size)
  22. --see if item is extractable
  23. function isOre(ore)
  24.     for k,v in pairs(oArray) do
  25.       if (ore == v) then
  26.         return true
  27.       end
  28.     end
  29.     return false
  30. end
  31. function isDust(dust)
  32.     for x,y in pairs(dArray) do
  33.       if (dust == y) then
  34.         return true
  35.       end
  36.     end
  37.     return false
  38. end
  39. --isOre(15)
  40. --loop throught the inventory
  41. function sendStuff()
  42.     sentOres = 0
  43.     sentDusts = 0
  44.     chest.condenseItems()
  45.   for i=1,size do
  46.           --print (i)
  47.           local id = chest.getStackInSlot(i)
  48.       if (id ~= nil) then
  49.                  local combID = tostring(id["id"])..":"..tostring(id["dmg"])
  50.                  --print (combID)
  51.                  --print (type(combID))
  52.                  if (isOre(combID)) then
  53.                       --print(id["name"])
  54.                       sentOres = sentOres + chest.pushItem(oresDir,i,64)
  55.                       if (sentOres > 0) then
  56.                         rs.setOutput(redOre, true)
  57.                       end
  58.                  elseif (isDust(combID)) then
  59.                     --print(id["name"])
  60.                     sentDusts = sentOres + chest.pushItem(dustsDir,i,64)
  61.                     if (sentDusts > 0) then
  62.                         rs.setOutput(redDust, true)
  63.                     end
  64.                  end
  65.        end
  66.     end
  67.     print (tostring(sentOres) .. " ore and " .. tostring(sentDusts) .. " dusts")
  68.   end
  69.  
  70.  
  71. function pullOres(slot)
  72.     oreExt.pushItem(dustsDir, slot, 64)
  73. end
  74. function pullDusts(slot)
  75.     dustExt.pushItem(oresDir, slot, 64)
  76. end
  77.  
  78.    
  79.  
  80. while true do
  81.     if  (oreExt.getStackInSlot(2) ~= nil) then
  82.         if  (oreExt.getStackInSlot(2)["qty"] > 62) then
  83.             pullOres(2)
  84.             print ("1")
  85.         else
  86.             print ("*/*/*")
  87.         end
  88.     end
  89.     if (oreExt.getStackInSlot(8) ~= nil) then
  90.         if (oreExt.getStackInSlot(8)["qty"] > 62) then
  91.             pullOres(8)
  92.             print ("2")
  93.         else
  94.             print ("*/*/*")
  95.         end
  96.     end
  97.     if (dustExt.getStackInSlot(6) ~= nil) then
  98.         if (dustExt.getStackInSlot(6)["qty"] > 62) then
  99.             pullDusts(6)
  100.             print ("3")
  101.         else
  102.             print ("*/*/*")
  103.         end
  104.     end
  105.     if (dustExt.getStackInSlot(4) ~= nil) then
  106.         if (dustExt.getStackInSlot(4)["qty"] > 62) then
  107.             pullDusts(4)
  108.             print ("2")
  109.         else
  110.             print ("*/*/*")
  111.         end
  112.     end
  113.     if oreExt.getStackInSlot(7)() == nil then
  114.         if oreExt.getStackInSlot(1) == nil then
  115.             rs.setOutput(redOre, false)
  116.             sendStuff()
  117.             print("5.5")
  118.         else
  119.         print ("5")
  120.         sendStuff()
  121.         end
  122.     else
  123.         print ("*/*/*")
  124.     end
  125.     if (dustExt.getStackInSlot(5) == nil) then
  126.         if (dustExt.getStackInSlot(3) == nil) then
  127.             rs.setOutput(redDust, false)
  128.             sendStuff()
  129.             print ("6.5")
  130.         else
  131.             print("6")
  132.         end
  133.     else
  134.         print ("*/*/*")
  135.     end
  136.     --if (dustSlot(3)) then
  137.         --sendStuff()
  138.         --print ("7")
  139.     --end
  140.     --if (oreSlot(1)) then
  141.         --sendStuff()
  142.         --print ("8")
  143.     --end
  144.    
  145.         --pullOres(2)
  146.         --pullOres(8)
  147.         --elseif (oreSlot(1) or oreSlot(7)) then
  148.         --sendStuff()
  149.         --pullOres(2)
  150.         --print("2")
  151.         --pullOres(8)
  152.         --rs.setOutput("back", false)
  153.         --print("3")
  154.         --rs.setOutput("back", true)
  155.         --print("4")
  156.         --rs.setOutput(redDust, false)
  157.         --print("5")
  158.         --elseif (dustSlot(3) or dustSlot(5)) then
  159.         --sendStuff()
  160.         --pullDusts(4)
  161.         --pulldusts(6)
  162.         --print("6")
  163.         --print("7")
  164.         --print("8")
  165. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement