Advertisement
hevohevo

Harvest Cactus 0_2

May 21st, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 0 0
  1. -- ######################################
  2. -- harvest cactus
  3. -- version 0.2
  4. -- http://hevohevo.hatenablog.com/
  5.  
  6. -- Turtle goes forward and harvests cactuses basically.
  7. -- When he reaches an order block, run the order; stop, turn right, turn left.
  8.  
  9. -- I recommend that this program names "startup".
  10.  
  11. -- ############### Side View
  12. --   T: Trutle, C: Cactus
  13. -- T=> C
  14. --     C
  15. --     C
  16.  
  17. -- ############### Top View:
  18. --   T: Trutle, C: Cactus, S: Block for stopping(e.g. a chest),
  19. --   R: Block for turning right, L: Block for turning left
  20.  
  21. -- R   R
  22. --    R   R
  23. -- C C C C
  24. -- C C C C
  25. -- C C C C
  26. -- C C C C
  27. --      
  28. --ST    
  29. --      LR
  30. --   L
  31.  
  32. -- Config
  33. BLOCK_TURN_LEFT = 13
  34. BLOCK_TURN_RIGHT = 14
  35. BLOCK_STOP = 15
  36. FUEL = 16
  37.  
  38. MIN_FUEL_LEVEL = 100
  39. SLEEP_TIME = 600 -- seconds
  40.  
  41. function get_cactus()
  42.   turtle.select(1)
  43.   turtle.forward()
  44.   turtle.suck()
  45.   turtle.dig()
  46.   turtle.digDown()
  47. end
  48.  
  49. while true do
  50.   repeat   -- start
  51.     get_cactus()
  52.     turtle.select(BLOCK_TURN_RIGHT)
  53.     if turtle.compare() then turtle.turnRight() end
  54.  
  55.     turtle.select(BLOCK_TURN_LEFT)
  56.     if turtle.compare() then turtle.turnLeft() end
  57.  
  58.     turtle.select(BLOCK_STOP)
  59.   until turtle.compare()    -- end
  60.  
  61.   -- drop cactus to the chest
  62.   for i=1,12 do
  63.     turtle.select(i)
  64.     if not turtle.drop() then break end
  65.   end
  66.  
  67.   turtle.turnRight()
  68.   os.sleep(SLEEP_TIME)
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement