Advertisement
minuslinus

redwood farm with gps for crashing servers

Mar 29th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.56 KB | None | 0 0
  1. local xcord=
  2. local ycord=
  3. local zcord=
  4.  
  5. local function checkFuel()
  6.         if turtle.getFuelLevel() < 100 then
  7.                 turtle.select(1)
  8.                 turtle.refuel(1)
  9.         end
  10. end
  11.  
  12. function locate()
  13.     g = vector.new(gps.locate(5))
  14.     turtle.digUp()
  15.     turtle.up()
  16.     turtle.dig()
  17.     turtle.forward()
  18.     g2 = vector.new(gps.locate(5))
  19.     turtle.back()
  20.     turtle.down()
  21.     if g.x == g2.x then
  22.         if g.y > g2.y then
  23.             turtle.turnLeft()
  24.             turtle.turnLeft()
  25.         else
  26.         end
  27.     else
  28.         if g.x > g2.x then
  29.             turtle.turnLeft()
  30.         else
  31.             turtle.turnRight()
  32.         end
  33.     end
  34. end
  35.  
  36. function calc()
  37.     xmove = xcord - g.x
  38.     if xmove < 0 then xmove=xmove*(-1) end
  39.     ymove = ycord - g.y
  40.     if ymove < 0 then ymove=ymove*(-1) end
  41.     zmove = zcord - g.z
  42.     if zmove < 0 then zmove=zmove*(-1) end
  43. end
  44.  
  45. function digForward()
  46.     turtle.dig()
  47.     turtle.forward()
  48.     checkFuel()
  49. end
  50.  
  51. function move()
  52.     if xcord ~= g.x then
  53.         if xcord < g.x then
  54.             turtle.turnRight()
  55.             for i=1,xmove do
  56.                 digForward()
  57.             end
  58.             turtle.turnLeft()
  59.         else
  60.             turtle.turnLeft()
  61.             for i=1,xmove do
  62.                 digForward()
  63.             end
  64.             turtle.turnRight()
  65.         end
  66.     end
  67.     if ycord ~= g.y then
  68.         if ycord > g.y then
  69.             for i=1,ymove do
  70.                 digForward()
  71.             end
  72.         else
  73.             turtle.turnLeft()
  74.             turtle.turnLeft()
  75.             for i=1,ymove do
  76.                 digForward()
  77.             end
  78.             turtle.turnLeft()
  79.             turtle.turnLeft()
  80.         end
  81.     end
  82.     if zcord ~= g.z then
  83.         if zcord < g.z then
  84.             for i=1,zmove do
  85.                 checkFuel()
  86.                 turtle.digDown()
  87.                 turtle.down()
  88.             end
  89.         else
  90.             for i=1,zmove do
  91.                 checkFuel()
  92.                 turtle.digUp()
  93.                 turtle.up()
  94.             end
  95.         end
  96.     end
  97. end
  98.  
  99. local function startup()
  100.         print("coal in slot 1")
  101.         print("saplings in slot 2")
  102.         print()
  103.         print("starting in 5")
  104.         sleep(5)
  105. end
  106.  
  107. local function column()
  108.         local height = 0
  109.         while turtle.digUp() do
  110.                 turtle.dig()
  111.                 checkFuel()
  112.                 turtle.up()
  113.                 height = height + 1
  114.         end
  115.         turtle.dig()
  116.         checkFuel()
  117.         return height
  118. end
  119.  
  120. local function columnDown(height)
  121.         for i=1,height do
  122.                 checkFuel()
  123.                 turtle.dig()
  124.                 turtle.digDown()
  125.                 turtle.down()
  126.         end
  127.         turtle.dig()
  128. end
  129.  
  130. local function digmove()
  131.         checkFuel()
  132.         turtle.dig()
  133.         turtle.forward()
  134. end
  135.  
  136. local function fell()
  137.         digmove()
  138.         local height = column()
  139.         turtle.turnRight()
  140.         digmove()
  141.         turtle.turnLeft()
  142.         columnDown(height)
  143. end
  144.  
  145. local function fellcrash()
  146.         digmove()
  147.         local height = column()
  148.         turtle.turnLeft()
  149.         digmove()
  150.         turtle.turnRight()
  151.         columnDown(height)
  152. end
  153.  
  154. local function replant()
  155.         turtle.select(2)
  156.         turtle.place()
  157.         turtle.turnLeft()
  158.         turtle.forward()
  159.         turtle.turnRight()
  160.         turtle.place()
  161.         turtle.turnRight()
  162.         turtle.place()
  163.         turtle.turnRight()
  164.         turtle.forward()
  165.         turtle.forward()
  166.         for slot=3,9 do
  167.                 turtle.select(slot)
  168.                 turtle.drop()
  169.         end
  170.         turtle.turnLeft()
  171.         turtle.turnLeft()
  172.         turtle.forward()
  173.         turtle.select(2)
  174.         turtle.place()
  175.         while turtle.compare()==true do
  176.                 sleep(30)
  177.                 turtle.select(2)
  178.         end
  179. end
  180.  
  181. function needCoal()
  182.         return turtle.getItemCount(1) < 10
  183. end
  184.  
  185. function needSap()
  186.         return turtle.getItemCount(2) < 10
  187. end
  188.  
  189. function getSap()
  190.         turtle.select(2)
  191.         turtle.suckDown()
  192.         turtle.select(3)
  193.         turtle.dropDown()
  194.         while turtle.getItemCount(2) < 60 do
  195.                 turtle.suckDown()
  196.                                 turtle.select(3)
  197.                                 turtle.dropDown()
  198.                                 turtle.select(2)
  199.         end
  200. end
  201.  
  202. function getCoal()
  203.         turtle.select(1)
  204.         turtle.turnLeft()
  205.         turtle.suck()
  206.         turtle.select(3)
  207.         turtle.drop()
  208.         while turtle.getItemCount(1) < 60 do
  209.                 turtle.suck()
  210.                                 turtle.select(3)
  211.                                 turtle.drop()
  212.                                 turtle.select(1)
  213.         end
  214.         turtle.turnRight()
  215. end
  216.  
  217. startup()
  218. locate()
  219. calc()
  220. move()
  221. turtle.turnRight()
  222. turtle.forward()
  223. turtle.turnLeft()
  224. fellcrash()
  225. turtle.back()
  226. while true do
  227.     if needSap() then
  228.         getSap()
  229.     end
  230.     if needCoal() then
  231.         getCoal()
  232.     end
  233.     fell()
  234.     replant()
  235. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement