Advertisement
FakoTheGreat

TurtleIO1

Apr 7th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. --[[
  2. Original: http://pastebin.com/4HwCLB6m
  3.  
  4. This is used with a construct consisting of a vertical stack of
  5.  
  6. * some chest (I used wood/copper, it does not have to be big)
  7. * a turtle (with this code)
  8. * ender chest, bound to a pouch
  9.  
  10. Followed by these items to the NORTH!
  11.  
  12. logistics remote order pipe  (next to chest)
  13. logistics provider pipe (next to turtle)
  14. me interface (next to Ender Chest)
  15.  
  16. Bind your remote orderer to the remote order pipe,
  17.  
  18. The turtle monitors the ranges of import and export slots specified,
  19. importing items it finds in the Import range into the ME and pushing
  20. items from the chest into the export slots if one is open.
  21.  
  22. ]]
  23.  
  24. local exportChest = peripheral.wrap("top")
  25. local enderChest = peripheral.wrap("bottom")
  26.  
  27. local startingImportSlot = 1
  28. local endingImportSlot = 18
  29. local startingExportSlot = 19
  30. local endingExportSlot = 27
  31.  
  32. function findExportSlot()
  33.   local stacks = enderChest.getAllStacks()
  34.   for i = startingExportSlot,endingExportSlot do
  35.     if stacks[i] == nil then
  36.       return i
  37.     end
  38.   end
  39.   return nil
  40. end
  41.  
  42. function waitForExportSlot()
  43.   local slot = findExportSlot()
  44.   while slot == nil do
  45.     slot = findExportSlot()
  46.     os.sleep(1)
  47.   end
  48.   return slot
  49. end
  50.  
  51. function exportStack(i, stack)
  52.   local slot = waitForExportSlot()
  53.   print("Found slot ", slot)  
  54.   exportChest.pushItem("down", i, 64, 1)
  55.   os.sleep(.125)
  56.   enderChest.pullItem("up", 1, 64, slot)
  57. end
  58.  
  59. function checkExports()
  60.   local stacks = exportChest.getAllStacks()
  61.   for i = 1,exportChest.getInventorySize() do
  62.     local stack = stacks[i]
  63.     if stack then
  64.       exportStack(i, stack)
  65.     end
  66.   end
  67. end
  68.  
  69. function watchExports()
  70.   while true do
  71.     checkExports()
  72.     os.sleep(.5)
  73.   end
  74. end
  75.  
  76. function checkImports()
  77.   local stacks = enderChest.getAllStacks()
  78.   for i = startingImportSlot, endingImportSlot do
  79.     if stacks[i] then
  80.       enderChest.pushItem("north", i, 64, 1)
  81.       os.sleep(.1)
  82.     end
  83.   end
  84. end
  85.  
  86. function watchImports()
  87.   while true do
  88.     checkImports()
  89.     os.sleep(.5)
  90.   end  
  91. end
  92.  
  93. parallel.waitForAny(
  94.   watchImports,
  95.   watchExports
  96. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement