Advertisement
Daraketh

barrelMove

Jul 4th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.82 KB | None | 0 0
  1. local barrelSide = "front"
  2. local isBarrel = false -- Barrel placed
  3. local updateDelay = 2 -- Time before next check
  4.  
  5. ------------------------------------
  6.  
  7. function barrStats()
  8.  
  9. t = peripheral.wrap(barrelSide)
  10.    
  11.      if t ~= nil then
  12.      
  13.         isBarrel = true
  14.         value = 0  max = 0
  15.         ti = t.getTankInfo(barrelSide)
  16.      
  17.         if isBarrel then
  18.             for i,j in pairs(ti) do
  19.                 for name,data in pairs(j) do
  20.                     if name=="capacity" then
  21.                         max = data
  22.                     elseif name=="amount"
  23.                         then value = data
  24.                     end      
  25.                 end
  26.             end
  27.         end
  28.      
  29.         s = "Barrel: "..value.."/"..max..
  30.         print(s)
  31.  
  32.         if value == max then
  33.             return true
  34.         else
  35.             return false
  36.         end
  37.        
  38.     end
  39.        
  40. end
  41.  
  42. ------------------------------------
  43.  
  44. function turtleCollect()
  45.  
  46.     turtle.select(1) -- just in case
  47.     turtle.dig() -- grab block in front (typically barrel)
  48.  
  49.     -- turn around, move forward, and place item (barrel)
  50.     turtle.turnRight()
  51.     turtle.turnRight()
  52.     turtle.forward()
  53.     turtle.place()
  54.  
  55.     -- turn around, move forward to original position. Change
  56.     -- back to first inventory slot, drop item (token)
  57.     turtle.turnLeft()
  58.     turtle.turnLeft()
  59.     turtle.forward()
  60.        
  61. end
  62.  
  63. ------------------------------------
  64.  
  65. function barrelCheck()
  66.        
  67.     if barrStats() then
  68.         print("Container full!")
  69.         print("Turtle working")
  70.         return true
  71.     else
  72.         print("Not full!")
  73.         return false
  74.     end
  75.    
  76. end
  77.  
  78. ------------------------------------
  79.  
  80. function main()
  81.  
  82.     while true do
  83.  
  84.         barrelFull = barrelCheck()
  85.    
  86.         while barrelFull do
  87.  
  88.             turtleCollect()
  89.            
  90.         end -- end while
  91.  
  92.     end -- end while
  93.  
  94. end --end main()
  95.  
  96. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement