Advertisement
Daraketh

barrelSort

Jul 3rd, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1. local dispSide = "left" -- Auto Placer side
  2. local barrelSide = "top"
  3. local isBarrel = false -- Barrel placed?
  4.  
  5. local updateDelay = 2 -- Time before next check
  6.  
  7. ----
  8.  
  9. function placeOne()
  10.  
  11.     rs.setOutput(dispSide, true)
  12.     sleep(1)
  13.     rs.setOutput(dispSide, false)
  14.  
  15. end
  16.  
  17. ----
  18.  
  19. function barrStats()
  20.  
  21. t = peripheral.wrap(tankSide)
  22.    
  23.         if t ~= nil then
  24.      
  25.         value = 0  max = 0
  26.         ti = t.getTankInfo(tankSide)
  27.      
  28.         if isBarrel then
  29.             for i,j in pairs(ti) do
  30.                 for name,data in pairs(j) do
  31.                     if name=="capacity" then
  32.                         max = data
  33.                     elseif name=="amount"
  34.                         then value = data
  35.                     end      
  36.                 end
  37.             end
  38.         end
  39.      
  40.         s = "Barrel: "..value.."/"..max..
  41.  
  42.         if value = max
  43.             return true
  44.         else
  45.             return false
  46.         end
  47.        
  48. end
  49.  
  50. ----
  51.  
  52. turtleCollect()
  53.  
  54.  
  55.  
  56. end
  57.  
  58. function main()
  59.  
  60.     while true do
  61.  
  62.         if ~isBarrel then
  63.             placeOne()
  64.             isBarrel = true
  65.         end
  66.        
  67.         if barrStats() then
  68.             if turtleCollect() then
  69.                 isBarrel = false
  70.             end
  71.         else
  72.           print("Not Full!")
  73.         end
  74.      
  75.         sleep(updateDelay)
  76.      
  77.     end
  78.    
  79. end
  80.  
  81. main()
  82.  
  83. ----
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement