Advertisement
BlueMond

turtlefarm

Feb 13th, 2014
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.99 KB | None | 0 0
  1. local version = 1.0
  2. local filename = "farm"
  3. local paste = "yg4au0jZ"
  4.  
  5. local function update()
  6.     local url = "http://pastebin.com/raw.php?i="..paste
  7.     local temp = http.get(url)
  8.     local ver = temp.readLine()
  9.     if tonumber(string.sub(ver, 17)) ~= version then
  10.         fs.delete(filename)
  11.         shell.run("pastebin get "..paste.." "..filename)
  12.         shell.run(filename)
  13.         return true
  14.     end
  15.     return false
  16. end
  17.  
  18. local test = update()
  19. if test == true then
  20.     error()
  21. end
  22.  
  23. local raise = 10
  24. local farmLength = 35
  25. local lane = 5
  26. local direction = 0
  27. local x = nil
  28. local y = nil
  29. local z = nil
  30. local fCoords = {}
  31. local sCoords = {}
  32. local cCoords = {}
  33. x, y, z = gps.locate(10)
  34.  
  35. local function getDir()
  36.     if not fs.exists("Direction") then
  37.         write("Firsttime direction entry: ")
  38.         direction = read()
  39.         local dir = fs.open("Direction","w")
  40.         dir.writeLine(direction)
  41.         dir.close()
  42.     else
  43.         local dir = fs.open("Direction","r")
  44.         direction = tonumber(dir.readLine())
  45.         dir.close()
  46.     end
  47. end
  48.  
  49. local saveDir()
  50.     local dir = fs.open("Direction","w")
  51.     dir.writeLine(direction)
  52.     dir.close()
  53. end
  54.  
  55. local function editData()
  56.     getDir()
  57.     if not fs.exists("FarmLoc") then
  58.         shell.run("clear")
  59.         print("Determining farm starting coordinates..")
  60.         fCoords = gps.locate(10)
  61.         print("Farm start = "..x..", "..y..", "..z)
  62.         local dir = fs.open("FarmLoc","w")
  63.         dir.writeLine(x)
  64.         dir.writeLine(y)
  65.         dir.writeLine(z)
  66.         dir.close()
  67.     else
  68.         local dir = fs.open("FarmLoc","r")
  69.         fCoords[1] = tonumber(dir.readLine())
  70.         fCoords[2] = tonumber(dir.readLine())
  71.         fCoords[3] = tonumber(dir.readLine())
  72.         dir.close()
  73.     end
  74.     local dir2 = fs.open("seedChest","r")
  75.     sCoords[1] = tonumber(dir.readLine())
  76.     sCoords[2] = tonumber(dir.readLine())
  77.     sCoords[3] = tonumber(dir.readLine())
  78.     dir.close()
  79.     local dir3 = fs.open("cropChest","r")
  80.     cCoords[1] = tonumber(dir.readLine())
  81.     cCoords[2] = tonumber(dir.readLine())
  82.     cCoords[3] = tonumber(dir.readLine())
  83.     dir.close()
  84. end
  85.  
  86. function vertical(dir,amount)
  87.     repeat
  88.         if dir == 1 then
  89.             turtle.up()
  90.         else
  91.             turtle.down()
  92.         end
  93.         amount = amount - 1
  94.     until amount == 0
  95. end
  96.  
  97. function switchLane(dir)
  98.     if dir == "right" then
  99.         face(direction+1)
  100.         turtle.forward()
  101.         face(direction+1)
  102.     elseif dir == "left" then
  103.         face(direction-1)
  104.         turtle.forward()
  105.         face(direction-1)
  106.     end
  107. end
  108.  
  109. function farmIt(forward)
  110.     turtle.select(1)
  111.     turtle.digDown()
  112.     turtle.select(2)
  113.     turtle.placeDown()
  114.    
  115.     if forward then
  116.         turtle.forward()
  117.     end
  118. end
  119.  
  120. function go(amount)
  121.     repeat
  122.         amount = amount - 1
  123.         turtle.forward()
  124.     until amount == 0
  125. end
  126.  
  127. function placeIn(slot)
  128.     turtle.suck()
  129.     amount = turtle.getItemCount(slot)
  130.     turtle.drop(amount-1)
  131. end
  132.  
  133. function face(num)
  134.     while direction ~= num do
  135.         if direction == 3 then
  136.             direction = 0
  137.         else
  138.             direction = direction + 1
  139.         end
  140.         turtle.turnRight()
  141.     end
  142.     saveDir()
  143. end
  144.  
  145. function goto(x1,y1,z1,f)
  146.     vertical(1,raise)
  147.  
  148.     if x1 > x then
  149.       face(3)
  150.       go(x1-x)
  151.     end
  152.     if x1 < x then
  153.       face(1)
  154.       go(x-x1)
  155.     end
  156.     if z1 > z then
  157.       face(0)
  158.       go(z1-z)
  159.     end
  160.     if z1 < z then
  161.       face(2)
  162.       go(z-z1)
  163.     end
  164.    
  165.     vertical(0,raise)
  166.     if y1 > y then
  167.       vertical(1,y1-y)
  168.     end
  169.     if y1 < y then
  170.       vertical(0,y-y1)
  171.     end
  172.    
  173.     face(f)
  174.     x = x1
  175.     y = y1
  176.     z = z1
  177. end
  178.  
  179. function farm(direc, last)
  180.     amount = farmLength-1
  181.     repeat
  182.         farmIt(true)
  183.         amount = amount - 1
  184.     until amount == 0
  185.     farmIt(false)
  186.    
  187.     if not last then
  188.         if direc == "right" then
  189.             switchLane("right")
  190.         elseif direc == "left" then
  191.             switchLane("left")
  192.         end
  193.     end
  194. end
  195.  
  196. function completeFarm(lanes)
  197.     turn = "right"
  198.     for x=1,lanes do
  199.         if x == lanes then
  200.             farm(turn, true)
  201.         else
  202.             farm(turn, false)
  203.         end
  204.        
  205.         if turn == "right" then
  206.             turn = "left"
  207.         elseif turn == "left" then
  208.             turn = "right"
  209.         end
  210.     end
  211. end
  212.  
  213. goto(xGo,yGo,zGo,dGo)
  214.  
  215. print("Press any key to launch..")
  216. repeat
  217.     local event = os.pullEvent()
  218. until event == "key"
  219.  
  220. x = -263
  221. y = 72
  222. z = 397
  223. direction = 0
  224.  
  225. xGo = -275
  226. yGo = 69
  227. zGo = 351
  228. dGo = 2
  229.  
  230. goto(xGo,yGo,zGo,dGo)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement