Advertisement
Guest User

Farming Turtle 10x14 field by Denemax v1.2

a guest
Jan 21st, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.39 KB | None | 0 0
  1. -- Author: Denemax               --
  2. -- Date: Jan/21/2019              --
  3. -- Version: TEKKIT               --
  4. -- Updated Jan/21/2019 to TEKKIT --
  5.  
  6. clearscr = function()
  7.   term.clear()
  8.   term.setCursorPos(1,1)
  9. end
  10.  
  11. clearscr()
  12.  
  13. print("====== Farmer ======")
  14. print("Ver TEKKIT")
  15. print("By Flyboxx")
  16.  
  17. sleep(1)
  18. clearscr()
  19.  
  20. -- Variables --
  21.  
  22. local args = {...}
  23. farming = true
  24. ystep = 1
  25. xpos = 1
  26. ypos = 0
  27.  
  28. -- Init --
  29.  
  30. -- Functions --
  31.  
  32. setPos = function(x, y)
  33.   xpos = x
  34.   ypos = y
  35. end
  36.  
  37. returnHome = function()
  38.   turtle.turnLeft()
  39.   for i = 1, 8, 1 do
  40.     turtle.forward()
  41.   end
  42.   turtle.turnLeft()
  43.   for i = 1, 9, 1 do
  44.     turtle.forward()
  45.   end
  46.   turtle.turnLeft()
  47.   turtle.turnLeft()
  48. end
  49.  
  50. clearInv = function()
  51.   for i = 1,14,1 do
  52.     turtle.select(i)
  53.     if turtle.getItemCount(i) ~= 0 then
  54.       if turtle.compareTo(15) then
  55.         turtle.dropDown()
  56.       elseif turtle.compareTo(16) then
  57.         turtle.turnLeft()
  58.         turtle.drop()
  59.         turtle.turnRight()
  60.       else
  61.         turtle.dropUp()
  62.       end
  63.     end
  64.   end
  65. end
  66.  
  67. getFuel = function(arg1)
  68.   if arg1 == "first" then
  69.     print("Refueling...")
  70.     turtle.turnRight()
  71.     turtle.select(1)
  72.     turtle.suck()
  73.   end
  74.  
  75.   turtle.refuel(1)
  76.  
  77.   if turtle.getFuelLevel() < 99 then
  78.     getFuel("notfirst")
  79.   else
  80.     turtle.drop()
  81.     turtle.turnLeft()
  82.   end
  83. end
  84.  
  85. initFarm = function()
  86.   clearInv()
  87.  
  88.   if turtle.getFuelLevel() < 99 then
  89.     getFuel("first")
  90.   end
  91.  
  92.   turtle.forward()
  93.   setPos(1,1)
  94. end
  95.  
  96. initPlant = function()
  97.   clearInv()
  98.  
  99.   if turtle.getFuelLevel() < 99 then
  100.     getFuel("first")
  101.   end
  102.  
  103.   turtle.select(1)
  104.   turtle.suckDown(64)
  105.   turtle.select(2)
  106.   turtle.suckDown(16)
  107.   turtle.select(1)
  108.  
  109.   turtle.forward()
  110.   setPos(1,1)
  111. end
  112.  
  113. initFert = function()
  114.   clearInv()
  115.  
  116.   if turtle.getFuelLevel() < 99 then
  117.     getFuel("first")
  118.   end
  119.  
  120.   turtle.select(1)
  121.   turtle.suckUp(64)
  122.   turtle.select(2)
  123.   turtle.suckUp(64)
  124.   turtle.select(3)
  125.   turtle.suckUp(64)
  126.   turtle.select(4)
  127.   turtle.suckUp(64)
  128.  
  129.   checkFertInv(1)
  130.  
  131.   turtle.forward()
  132.   setPos(1,1)
  133.   turtle.select(1)
  134. end
  135.  
  136. checkFertInv = function(slot)
  137.   for i = 1, 4 , 1 do
  138.     if turtle.getItemCount(i) ~= 64 then
  139.       print("Slot " .. i .. " needs to have 64 items!");
  140.       while(turtle.getItemCount(i) ~= 64) do
  141.         sleep(2)
  142.         turtle.select(i)
  143.         turtle.suckUp()
  144.       end
  145.     end
  146.   end
  147.   turtle.select(1)
  148. end
  149.  
  150. fert = function()
  151.   for i = 1, 5, 1 do
  152.     turtle.placeDown()
  153.     if turtle.getItemCount() == 0 then
  154.       turtle.select(turtle.getSelectedSlot() + 1)
  155.     end
  156.   end
  157. end
  158.  
  159. -- ==========*Till Program*========== --
  160. till = function()
  161.   initFarm()
  162.   clearscr()
  163.   print("Tilling...")
  164.  
  165.   while(farming) do
  166.  
  167.     turtle.digDown()
  168.  
  169.     if xpos == 10 and ypos == 14 then
  170.       returnHome()
  171.       clearInv()
  172.       break
  173.     end
  174.  
  175.     if ypos == 14 then
  176.       turtle.turnRight()
  177.       turtle.forward()
  178.       xpos = xpos + 1
  179.       turtle.turnRight()
  180.       turtle.digDown()
  181.       ystep = -1
  182.     end
  183.  
  184.     if ypos == 1 and xpos ~= 1 then
  185.       turtle.turnLeft()
  186.       turtle.forward()
  187.       xpos = xpos + 1
  188.       turtle.turnLeft()
  189.       turtle.digDown()
  190.       ystep = 1
  191.     end
  192.  
  193.     turtle.forward()
  194.     ypos = ypos + ystep
  195.  
  196.   end
  197. end
  198.  
  199. -- ==========*Plant Program*========== --
  200. plant = function()
  201.   initPlant()
  202.   clearscr()
  203.   print("Planting...")
  204.  
  205.   while(farming) do
  206.  
  207.     turtle.placeDown()
  208.    
  209.     if turtle.getItemCount() == 0 then
  210.       turtle.select(turtle.getSelectedSlot() + 1)
  211.     end
  212.  
  213.     if xpos == 10 and ypos == 14 then
  214.       returnHome()
  215.       turtle.select(1)
  216.       break
  217.     end
  218.  
  219.     if ypos == 14 then
  220.       turtle.turnRight()
  221.       turtle.forward()
  222.       xpos = xpos + 1
  223.       turtle.turnRight()
  224.       turtle.placeDown()
  225.       ystep = -1
  226.     end
  227.  
  228.     if ypos == 1 and xpos ~= 1 then
  229.       turtle.turnLeft()
  230.       turtle.forward()
  231.       xpos = xpos + 1
  232.       turtle.turnLeft()
  233.       turtle.placeDown()
  234.       ystep = 1
  235.     end
  236.  
  237.     turtle.forward()
  238.     ypos = ypos + ystep
  239.  
  240.   end
  241. end
  242.  
  243. -- ==========*Harvest Program*========== --
  244. harvest = function()
  245.   initFarm()
  246.   clearscr()
  247.   print("Harvesting...")
  248.  
  249.   while(farming) do
  250.  
  251.     turtle.digDown()
  252.  
  253.     if xpos == 10 and ypos == 14 then
  254.       returnHome()
  255.       clearInv()
  256.       turtle.select(1)
  257.       break
  258.     end
  259.  
  260.     if ypos == 14 then
  261.       turtle.turnRight()
  262.       turtle.forward()
  263.       xpos = xpos + 1
  264.       turtle.turnRight()
  265.       turtle.digDown()
  266.       ystep = -1
  267.     end
  268.  
  269.     if ypos == 1 and xpos ~= 1 then
  270.       turtle.turnLeft()
  271.       turtle.forward()
  272.       xpos = xpos + 1
  273.       turtle.turnLeft()
  274.       turtle.digDown()
  275.       ystep = 1
  276.     end
  277.  
  278.     turtle.forward()
  279.     ypos = ypos + ystep
  280.  
  281.   end
  282. end
  283.  
  284. -- ==========*Fertilize Program*========== --
  285. fertilize = function()
  286.   initFert()
  287.   clearscr()
  288.   print("Fertilizing...")
  289.  
  290.   while(farming) do
  291.  
  292.     pos = {xpos, ypos}
  293.  
  294.     fert()
  295.  
  296.     if xpos == 10 and ypos == 14 then
  297.       returnHome()
  298.       clearInv()
  299.       turtle.select(1)
  300.       break
  301.     end
  302.  
  303.     if ypos == 14 then
  304.       turtle.turnRight()
  305.       turtle.forward()
  306.       xpos = xpos + 1
  307.       turtle.turnRight()
  308.       fert()
  309.       ystep = -1
  310.     end
  311.  
  312.     if ypos == 1 and xpos ~= 1 then
  313.       turtle.turnLeft()
  314.       turtle.forward()
  315.       xpos = xpos + 1
  316.       turtle.turnLeft()
  317.       fert()
  318.       ystep = 1
  319.     end
  320.  
  321.     turtle.forward()
  322.     ypos = ypos + ystep
  323.  
  324.   end
  325. end
  326.  
  327. -- ==========*Main Program*========== --
  328. till()
  329. while(farming) do
  330.   plant()
  331.   fertilize()
  332.   harvest()
  333. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement