Advertisement
jdroid91

fullFarm

Oct 7th, 2023 (edited)
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.83 KB | None | 0 0
  1. local currentDirection = nil
  2.  
  3. function getCurrentDirection()
  4.     local tp1X, tp1Y, tp1Z = gps.locate()
  5.     turtle.forward()
  6.     local tp2X, tp2Y, tp2Z = gps.locate()
  7.     turtle.back()
  8.  
  9.     if (tp1X == tp2X)
  10.     then
  11.         if (tp1Z < tp2Z)
  12.         then
  13.             currentDirection = "South"
  14.         else
  15.             currentDirection = "North"
  16.         end
  17.     else
  18.         if (tp1X < tp2X)
  19.         then
  20.             currentDirection = "East"
  21.         else
  22.             currentDirection = "West"
  23.         end
  24.     end
  25. end
  26.  
  27. function turnLeft()
  28.     if (currentDirection == "North")
  29.     then
  30.         currentDirection = "West"
  31.     elseif (currentDirection == "West")
  32.     then
  33.         currentDirection = "South"
  34.     elseif (currentDirection == "South")
  35.     then
  36.         currentDirection = "East"
  37.     else
  38.         currentDirection = "North"
  39.     end
  40.     turtle.turnLeft()
  41. end
  42.  
  43. function turnRight()
  44.     if (currentDirection == "North")
  45.     then
  46.         currentDirection = "East"
  47.     elseif (currentDirection == "East")
  48.     then
  49.         currentDirection = "South"
  50.     elseif (currentDirection == "South")
  51.     then
  52.         currentDirection = "West"
  53.     else
  54.         currentDirection = "North"
  55.     end
  56.     turtle.turnRight()
  57. end
  58.  
  59. function gotoPoint(dp)
  60.     dpX = dp.x
  61.     dpY = dp.y
  62.     dpZ = dp.z
  63.     local clX, clY, clZ = gps.locate()
  64.    
  65.     while (clY ~= dpY)
  66.     do
  67.         if (clY > dpY)
  68.         then
  69.             turtle.down()
  70.         else
  71.             turtle.up()
  72.         end
  73.         clX, clY, clZ = gps.locate()    
  74.     end
  75.    
  76.     while (clX ~= dpX)
  77.     do
  78.         if (clX > dpX)
  79.         then
  80.             while (currentDirection ~= "West")
  81.             do
  82.                 turnLeft()
  83.             end
  84.         else
  85.             while (currentDirection ~= "East")
  86.             do
  87.                 turnLeft()
  88.             end
  89.         end
  90.         turtle.forward()
  91.         clX, clY, clZ = gps.locate()
  92.     end
  93.    
  94.     while (clZ ~= dpZ)
  95.     do
  96.         if (clZ > dpZ)
  97.         then
  98.             while (currentDirection ~= "North")
  99.             do
  100.                 turnLeft()
  101.             end
  102.         else
  103.             while (currentDirection ~= "South")
  104.             do
  105.                 turnLeft()
  106.             end
  107.         end
  108.         turtle.forward()
  109.         clX, clY, clZ = gps.locate()
  110.     end
  111. end
  112.  
  113. local home = {
  114.     x = -1437,
  115.     y = -53,
  116.     z = -399
  117. }
  118.  
  119. local sp1 = {
  120.     x = -1438,
  121.     y = -53,
  122.     z = -399
  123. }
  124.  
  125. local wheatField1Start = {
  126.     x = -1438,
  127.     y = -56,
  128.     z = -398
  129. }
  130.  
  131. local wheatField2Start = {
  132.     x = -1446,
  133.     y = -56,
  134.     z = -400
  135. }
  136.  
  137. local potatoField1Start = {
  138.     x = -1448,
  139.     y = -56,
  140.     z = -398
  141. }
  142.  
  143. local potatoField2Start = {
  144.     x = -1456,
  145.     y = -56,
  146.     z = -400
  147. }
  148.  
  149. local carrotField1Start = {
  150.     x = -1458,
  151.     y = -56,
  152.     z = -398
  153. }
  154.  
  155. local carrotField2Start = {
  156.     x = -1466,
  157.     y = -56,
  158.     z = -400
  159. }
  160.  
  161. getCurrentDirection()
  162.  
  163. turnRight()
  164. local wheatChest = peripheral.wrap("front")
  165. local wheatInfo = wheatChest.getItemDetail(wheatChest.size())
  166.  
  167. if (wheatInfo == nil or wheatInfo.count ~= 64)
  168. then
  169.     turtle.suck()
  170.     turnLeft()
  171.     gotoPoint(sp1)
  172.     gotoPoint(wheatField1Start)
  173.     shell.run("farm")
  174.     gotoPoint(wheatField2Start)
  175.     shell.run("farm")
  176.     gotoPoint(wheatField1Start)
  177.     gotoPoint(sp1)
  178.     gotoPoint(home)
  179.     turnLeft()
  180.    
  181.     local index = 0
  182.     while (index < 16)
  183.     do
  184.         turtle.select(index + 1)
  185.         turtle.drop()
  186.         index = index + 1
  187.     end
  188.     turtle.select(1)
  189.     turnLeft()
  190. else
  191.     turnLeft()
  192. end
  193.  
  194. turnLeft()
  195. local potatoChest = peripheral.wrap("front")
  196. local potatoInfo = potatoChest.getItemDetail(potatoChest.size())
  197. if (potatoInfo == nil or potatoInfo.count ~= 64)
  198. then
  199.     turtle.suck()
  200.     turnRight()
  201.  
  202.     gotoPoint(sp1)
  203.     gotoPoint(wheatField1Start)
  204.     gotoPoint(potatoField1Start)
  205.     turnLeft()
  206.     shell.run("farm")
  207.     gotoPoint(potatoField2Start)
  208.     shell.run("farm")
  209.     gotoPoint(potatoField1Start)
  210.     gotoPoint(wheatField1Start)
  211.     gotoPoint(sp1)
  212.     gotoPoint(home)
  213.     turnRight()
  214.  
  215.     index = 0
  216.     while (index < 16)
  217.     do
  218.         turtle.select(index + 1)
  219.         turtle.drop()
  220.         index = index + 1
  221.     end
  222.     turtle.select(1)
  223.     turnRight()
  224. else
  225.     turnRight()
  226. end
  227. turtle.up()
  228. turnRight()
  229. local carrotChest = peripheral.wrap("front")
  230. local carrotInfo = carrotChest.getItemDetail(carrotChest.size())
  231. if (carrotInfo == nil or carrotInfo.count ~= 64)
  232. then
  233.     turtle.suck()
  234.     turnLeft()
  235.     turtle.down()
  236.     gotoPoint(sp1)
  237.     gotoPoint(wheatField1Start)
  238.     gotoPoint(carrotField1Start)
  239.     turnLeft()
  240.     shell.run("farm")
  241.     gotoPoint(carrotField2Start )
  242.     shell.run("farm")
  243.     gotoPoint(carrotField1Start)
  244.     gotoPoint(wheatField1Start)
  245.     gotoPoint(sp1)
  246.     gotoPoint(home)
  247.     turnLeft()
  248.     turtle.up()
  249.  
  250.     index = 0
  251.     while (index < 16)
  252.     do
  253.         turtle.select(index + 1)
  254.         turtle.drop()
  255.         index = index + 1
  256.     end
  257.     turtle.select(1)
  258.     turnLeft()
  259.     turtle.down()
  260. else
  261.     turnLeft()
  262.     turtle.down()
  263. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement