Advertisement
zortag

5x5farm

May 13th, 2014
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.09 KB | None | 0 0
  1. -- Script by zortag - The turtle reach the starting position from everywhere and face correctly, farm a 5x5 field then drop in a
  2. -- chest, come back to starting point, check fuel and refuel if needed. The script automatically skips useless steps
  3. -- This script needs this other script to work pastebin.com/UYfrBtbj named "moveto"
  4. -- This script needs a GPS tower (www.computercraft.info/forums2/index.php?/topic/3088-how-to-guide-gps-global-position-system/)
  5. -- It is better to configure the GPS tower coordinates with the real position where computers are, so it is easier configure the
  6. -- turtle starting point using real coordinates. Rename the script "startup" (it auto resume from averywhere)
  7. -- The turtle needs an hoe and a wireless modem installed
  8. -- You have to configure the coordinates for the turtle (press F3 and use feet position):
  9. -- Starting point: line 123
  10. -- Align point: line 124 (same as starting coordinates but +2 at the facing axis)
  11. -- Starting point check: line 195 (same as starting point, be sure axis are correct)
  12. -- Field design (image at i.imgur.com/hvtTQNV.jpg)
  13. -- H = dirt, W = water, S = starting point, D = drop point
  14. -- fuel pickup is 1 block under the starting position (can be a chest under the turtle)
  15. -- drop chest is at the same level the turtle is
  16. --
  17. --      HHHHH
  18. --      HHHHH
  19. --      HHWHH
  20. --      HHHHH
  21. --      HHHHH
  22. --          S
  23. --          |
  24. --          +---D
  25.  
  26. function dig()
  27.     turtle.digDown()
  28.     turtle.forward()
  29.     turtle.digDown()
  30.     turtle.forward()
  31.     turtle.digDown()
  32.     turtle.forward()
  33.     turtle.digDown()
  34.     turtle.forward()
  35.     turtle.digDown()
  36. end
  37.  
  38. function left()  
  39.     turtle.turnLeft()
  40.     turtle.forward()
  41.     turtle.turnLeft()
  42. end
  43.  
  44. function right()   
  45.     turtle.turnRight()
  46.     turtle.forward()
  47.     turtle.turnRight()
  48. end
  49.  
  50. function left2()
  51.     turtle.turnLeft()
  52.     turtle.turnLeft()
  53. end
  54.  
  55. function place()
  56.     turtle.select(1)
  57.     turtle.placeDown()
  58.     turtle.forward()
  59.     turtle.placeDown()
  60.     turtle.forward()
  61.     turtle.placeDown()
  62.     turtle.forward()
  63.     turtle.placeDown()
  64.     turtle.forward()
  65.     turtle.placeDown()
  66. end
  67.  
  68. function fuel()
  69.     term.setCursorPos(1, 1)
  70.     write("Fuel left ")
  71.     write(turtle.getFuelLevel())
  72. end
  73.  
  74. function eat()
  75.     if turtle.getFuelLevel() < 1000 then
  76.     term.clear()
  77.     term.setCursorPos(1, 1)
  78.     print("Refuelling...")
  79.     turtle.select(16)
  80.     turtle.suckDown()
  81.     turtle.refuel()
  82.     term.clear()
  83.     term.setCursorPos(1, 1)
  84.     print("Done!")
  85.     sleep(2)
  86.     else
  87.     term.clear()
  88.     term.setCursorPos(1, 1)
  89.     print("I'm fine, let's go working!")
  90.     sleep(2)
  91.     end
  92. end
  93.  
  94. function sleeping()
  95.     local w = 0
  96.     while w <= 40 do
  97.         if w == 0 then
  98.         term.clear()
  99.         term.setCursorPos(1, 1)
  100.         fuel()
  101.         term.setCursorPos(1, 2)
  102.         print("Waiting 40 minutes")
  103.         sleep(60)
  104.         w = w + 1
  105.         elseif w ==40 then
  106.         print("Restarting...")
  107.         sleep(2)
  108.         break
  109.         else
  110.     term.setCursorPos(1, 1)
  111.     fuel()
  112.     term.setCursorPos(1, 3)
  113.     print(w, " minutes passed")
  114.     sleep(60)
  115.     w = w + 1
  116.         end
  117.     end
  118. end
  119.  
  120. function gohome()
  121.     term.clear()
  122.     write("Positioning...")
  123.     shell.run("moveto", 335,66,15)
  124.     shell.run("moveto", 335,66,13)
  125.     turtle.back()
  126.     turtle.back()
  127.     turtle.down()
  128.     term.setCursorPos(1,2)
  129.     term.write("I'm at home")
  130.     sleep(2)
  131. end
  132.  
  133. function job()
  134.     term.clear()
  135.     fuel()
  136.     term.setCursorPos(1, 2)
  137.     write("Farming...")
  138.     turtle.select(1)
  139.     turtle.up()
  140.     turtle.forward()
  141.     dig()
  142.     left()
  143.     dig()
  144.     right()
  145.     dig()
  146.     left()
  147.     dig()
  148.     right()
  149.     dig()
  150.     left2()
  151.     place()
  152.     left()
  153.     place()
  154.     right()
  155.     place()
  156.     left()
  157.     place()
  158.     right()
  159.     place()
  160.         turtle.forward()
  161.         turtle.forward()
  162.         turtle.forward()
  163.         turtle.turnLeft()
  164.         turtle.forward()
  165.         turtle.forward()
  166.         turtle.forward()
  167.         turtle.forward()
  168.        
  169.             term.clear()
  170.             fuel()
  171.             term.setCursorPos(1, 2)
  172.             write("Dropping...")
  173. function dropItems()
  174.     for slot = 2, 15 do
  175.         turtle.select(slot)
  176.         turtle.dropDown()
  177. end
  178.     end
  179.         dropItems()
  180.         left2()
  181.         turtle.forward()
  182.         turtle.forward()
  183.         turtle.forward()
  184.         turtle.forward()
  185.         turtle.turnRight()
  186.         turtle.forward()
  187.         turtle.forward()
  188.         turtle.down()
  189.         sleeping()
  190. end
  191. while true do
  192.  
  193. local x, y, z = gps.locate(5)
  194.  
  195.     if x == 335 and y == 65 and z == 15 then
  196.     job()
  197.         else
  198.         gohome()
  199.     end
  200.     eat()
  201. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement