Advertisement
FakoTheGreat

TurtIOSly

Jun 12th, 2014
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1. -- Original: http://pastebin.com/4HwCLB6m
  2.  
  3. local exportChest = peripheral.wrap("top")
  4. local enderChest = peripheral.wrap("bottom")
  5.  
  6. local startingImportSlot = 1
  7. local endingImportSlot = 18
  8. local startingExportSlot = 19
  9. local endingExportSlot = 25
  10.  
  11. function findExportSlot()
  12.   local stacks = enderChest.getAllStacks()
  13.   for i = startingExportSlot,endingExportSlot do
  14.     if stacks[i] == nil then
  15.       return i
  16.     end
  17.   end
  18.   return nil
  19. end
  20.  
  21. function waitForExportSlot()
  22.   local slot = findExportSlot()
  23.   while slot == nil do
  24.     slot = findExportSlot()
  25.     os.sleep(1)
  26.   end
  27.   return slot
  28. end
  29.  
  30. function exportStack(i, stack)
  31.   local slot = waitForExportSlot()
  32.   print("Found slot ", slot)  
  33.   exportChest.pushItem("down", i, 64, 1)
  34.   os.sleep(.125)
  35.   enderChest.pullItem("up", 1, 64, slot)
  36. end
  37.  
  38. function checkExports()
  39.   local stacks = exportChest.getAllStacks()
  40.   for i = 1,exportChest.getInventorySize() do
  41.     local stack = stacks[i]
  42.     if stack then
  43.       exportStack(i, stack)
  44.     end
  45.   end
  46. end
  47.  
  48. function watchExports()
  49.   while true do
  50.     checkExports()
  51.     os.sleep(.5)
  52.   end
  53. end
  54.  
  55. function checkImports()
  56.   local stacks = enderChest.getAllStacks()
  57.   for i = startingImportSlot, endingImportSlot do
  58.     if stacks[i] then
  59.       enderChest.pushItem("south", i, 64, 1)
  60.       os.sleep(.1)
  61.     end
  62.   end
  63. end
  64.  
  65. function watchImports()
  66.   while true do
  67.     checkImports()
  68.     os.sleep(.5)
  69.   end  
  70. end
  71.  
  72. os.sleep(3)
  73.  
  74. parallel.waitForAny(
  75.   watchImports,
  76.   watchExports
  77. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement