Wizard_Alfren

Minecraft - ComputerCraft - Turtle Extreme Farming

Apr 12th, 2020 (edited)
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.83 KB | None | 0 0
  1. --Created by Wizard_Alfren--
  2. --Created on 12 April 2020--
  3. --Current as of 16 April 2020--
  4. --This Lua script is for a Farming Turtle--
  5. --1.  Turtle must be 1 block off the ground--
  6. --2.  Turtle will start the farm on the 1st block at ground level in front if it--
  7. --3.  A storage/chest needs to be placed behind the turtle to store the harvest--
  8. --4.  Remember to clear the area of grass/objects--
  9. --5a. You will be asked for the dimensions of the farm and then the type of seeds to plant--
  10. --5b. Example:      Width: 9     Length: 18 --
  11. --5c. The turtle's route is (length: 18) forward, and (Width: 9) rows to the right--
  12. --5d. This script is able to use 1 of 3 types of seeds. (minecraft:wheat_seeds, minecraft:carrot, minecraft:potatoe)--
  13. --6.  Seeds can be placed in the top row of the turtle's inventory (slots 1,2,3,4)--
  14. --7a. Fuel can be placed in the bottom row of the turtle's inventory (slots 13,14,15,16)--
  15. --7b. The accepted fuel types are minecraft:coal, railcraft:fuel_coke, ic2:coke--
  16. function GO()
  17.     term.clear()
  18.     term.setCursorPos(1,1)
  19.     if RUNS == 1 then
  20.         Startup1()
  21.     end
  22.     turtle.forward()
  23.     A = 1
  24.     T = 0
  25.     while T < Width do
  26.         if turtle.getFuelLevel() < 300 then
  27.             FuelCheck()
  28.         end
  29.         term.clear()
  30.         term.setCursorPos(1,4)
  31.         print('Harvesting Row:',T)
  32.         for ii = 1, Length - 1 do
  33.             if Seed_Count < 1 then
  34.                 SeedCheck()
  35.             end
  36.             for iii = 0, 1 do
  37.                 term.setCursorPos(1,3)
  38.                 term.clearLine()
  39.                 print('Fuel Level:',turtle.getFuelLevel())
  40.                 term.setCursorPos(1,5)
  41.                 term.clearLine()
  42.                 print('Block:',ii)
  43.                 plantORharvest()
  44.                 SeedQuantityCheck()
  45.             end
  46.             turtle.forward()
  47.             plantORharvest()
  48.             turtle.suckDown()
  49.         end
  50.         if T < Width - 1 then
  51.             if A == 1 then
  52.                 turtle.turnRight()
  53.                 turtle.forward()
  54.                 turtle.turnRight()
  55.                 A = 3
  56.             end
  57.             if A == 2 then
  58.                 turtle.turnLeft()
  59.                 turtle.forward()
  60.                 turtle.turnLeft()
  61.                 A = 1
  62.             end
  63.             if A == 3 then
  64.             A = 2
  65.             end
  66.         end
  67.         T = T + 1
  68.     end
  69.     ReturnToStart()
  70.     DepositeItems()  
  71.     Reset()
  72.     RUNS = RUNS + 1
  73.     GO()
  74. end
  75. ---------------------------------------
  76. function Startup1()
  77.     term.clear()
  78.     term.setCursorPos(1,1)
  79.     print('SEEDS: Top 4 slots.\nFUEL: Bottom 4 slots.\n')
  80.     print('1. Start me 1 block off the ground.\n   The farm starts in front of me.\n')
  81.     print('2. Place a chest behind me so I can\n   store the harvest.\n')
  82.     print('3. Don\'t forget to clear the land.\n')
  83.     print('Press ENTER to continue..')
  84.     io.read()
  85.     Startup2()
  86. end
  87. ---------------------------------------
  88. function Startup2()
  89.     term.clear()
  90.     term.setCursorPos(1,1)
  91.     print('---Farm Size Options---\nType farm dimensions and press ENTER\n')
  92.     print('Length (forward) x Width (Right)')
  93.     print('Example: 18x9\n\nWidth: ')
  94.     Width_Input = io.read()
  95.     Width_Input = tonumber(Width_Input)
  96.     print('\nLength:')
  97.     Length_Input = io.read()
  98.     Length_Input = tonumber(Length_Input)
  99.     -- logic --
  100.     if type(Width_Input) == 'number' and type(Length_Input) == 'number' then
  101.         Width = Width_Input
  102.         Length = Length_Input
  103.     else
  104.         print('\n\n\nUm.. try again..')
  105.         sleep(2)
  106.         Startup2()
  107.     end
  108.     Startup3()
  109. end
  110. ---------------------------------------
  111. function Startup3()
  112.     term.clear()
  113.     term.setCursorPos(1,1)
  114.     print('---Plant Options---\nSelect (1, 2, or 3) and press ENTER\n')
  115.     print('1: Wheat\n2: Potatoes\n3: Carrots\n\n')
  116.     PLANT_NAME = io.read()
  117.     -- logic --
  118.     if PLANT_NAME == '1' then
  119.         PLANT = 'minecraft:wheat'
  120.         PLANT_TEXT = 'Wheat'
  121.         PLANT_SEED = 'minecraft:wheat_seeds'
  122.     elseif PLANT_NAME == '2' then
  123.         PLANT = 'minecraft:potatoe_seeds'
  124.         PLANT_TEXT = 'Potatoes'
  125.         PLANT_SEED = 'minecraft:potato'
  126.     elseif PLANT_NAME == '3' then
  127.         PLANT = 'minecraft:carrots'
  128.         PLANT_TEXT = 'Carrot'
  129.         PLANT_SEED = 'minecraft:carrot'
  130.     else
  131.         print('\n\n\nPlease Try Again..')
  132.         sleep(2)
  133.         Startup3()
  134.     end
  135.     term.clear()
  136.     term.setCursorPos(1,6)
  137.     print(Width_Input..'x'..Length_Input,PLANT_TEXT,'farm!\n\nHere We Go!')
  138.     sleep(2)
  139.     SeedCheck()
  140. end
  141. ---------------------------------------
  142. function SeedQuantityCheck()
  143.     Seed_Slot_Count = {turtle.getItemCount(1),turtle.getItemCount(2),turtle.getItemCount(3),turtle.getItemCount(4)}
  144.     Seed_Count = 0
  145.     for S = 1, 4 do
  146.         if Seed_Slot_Count[S] > 0 then
  147.             if turtle.getItemDetail(S).name == PLANT_SEED then
  148.                 turtle.select(S)
  149.                 Seed_Count = Seed_Count + Seed_Slot_Count[S]
  150.                 S = S + 1
  151.             end
  152.         end
  153.         if Seed_Slot_Count[S] > 0 then
  154.             break
  155.         end
  156.     end
  157. end
  158. ---------------------------------------
  159. function SeedCheck()
  160.     SeedQuantityCheck()
  161.     if Seed_Count < 1 then
  162.         while Seed_Count < 1 do
  163.             SeedQuantityCheck()
  164.             if Seed_Count > 0 then
  165.             else
  166.                 term.clear()
  167.                 term.setCursorPos(1,5)
  168.                 print('Detecting seeds..\n\nSeed count:',Seed_Count,'\n\nWaiting for more seeds..')
  169.                 sleep(1)
  170.             end
  171.         end
  172.     else
  173.         term.clear()
  174.         term.setCursorPos(1,5)
  175.     end
  176. end
  177. ---------------------------------------
  178. function FuelCheck()
  179.     Fuel_Slot_Count = {turtle.getItemCount(13),turtle.getItemCount(14),turtle.getItemCount(15),turtle.getItemCount(16)}
  180.     Fuel_Count = 0
  181.     for f = 1, 4 do
  182.         if Fuel_Slot_Count[f] > 0 then
  183.             Temp = turtle.getItemDetail(12+f).name
  184.             if Temp == Fuel_Types[1] or Temp == Fuel_Types[2] or Temp == Fuel_Types[3] then
  185.                 Fuel_Count = Fuel_Count + Fuel_Slot_Count[f]
  186.                 term.clear()
  187.                 term.setCursorPos(1,1)
  188.                 print('Total Fuel Item(s):',Fuel_Count)
  189.             end
  190.         end
  191.         f = f + 1
  192.     end
  193.     term.clear()
  194.     term.setCursorPos(1,1)
  195.     if Fuel_Count > 0 then
  196.         for F = 1, 4 do
  197.             while turtle.getFuelLevel() < 300 do
  198.                 if Fuel_Slot_Count[F] > 0 then
  199.                     Temp = turtle.getItemDetail(F+12).name
  200.                     if Temp == Fuel_Types[1] or Temp == Fuel_Types[2] or Temp == Fuel_Types[3] then
  201.                         turtle.select(F+12)
  202.                         turtle.refuel(2)
  203.                     end
  204.                 end
  205.             end
  206.             if turtle.getFuelLevel() > 300 then
  207.                 break
  208.             end
  209.         end
  210.        
  211.     else
  212.         term.setCursorPos(1,5)
  213.         term.clearLine()
  214.         print("Waiting for fuel... Slot(s) 13-16\n(Coal, Charcoal, Coal Coke)")
  215.         sleep(1)
  216.     end
  217.     SeedQuantityCheck()
  218. end
  219. ---------------------------------------
  220. function plantORharvest()
  221.     local success, inspectDown = turtle.inspectDown()
  222.     if success then
  223.         if inspectDown.name == PLANT and inspectDown.state.age == 7 then
  224.             turtle.placeDown()
  225.             turtle.placeDown()
  226.             turtle.suckDown()
  227.             turtle.suckDown()
  228.         end
  229.     elseif not success then
  230.         turtle.digDown()
  231.         Seed_Count = Seed_Count - 1
  232.         turtle.placeDown()
  233.         turtle.placeDown()
  234.         turtle.suckDown()
  235.         turtle.suckDown()
  236.     end
  237. end
  238. ---------------------------------------
  239. function ReturnToStart()
  240.     if (Width % 2) == 1 then
  241.         turtle.turnRight()
  242.         turtle.turnRight()
  243.         for Z = 1, Length do
  244.             turtle.forward()
  245.         end
  246.         turtle.turnRight()
  247.         for Z = 1, Width - 1 do
  248.             turtle.forward()
  249.         end
  250.         turtle.turnLeft()
  251.     else
  252.         turtle.forward()
  253.         turtle.turnRight()
  254.         for Z = 1, Width - 1 do
  255.             turtle.forward()
  256.         end
  257.         turtle.turnLeft()
  258.     end
  259. end
  260. ---------------------------------------
  261. function DepositeItems()
  262.     II = 1
  263.     while II ~= 17 do
  264.         if turtle.getItemCount(II) > 0 then
  265.             II_name = turtle.getItemDetail(II).name
  266.             if II_name ~= PLANT_SEED and II_name ~= Fuel_Types[1] and II_name ~= Fuel_Types[2] and II_name ~= Fuel_Types[3] then
  267.                 turtle.select(II)
  268.                 turtle.drop()
  269.             elseif II > 4 and II < 13 then
  270.                 turtle.select(II)
  271.                 turtle.drop()
  272.             end
  273.         end
  274.         II = II + 1
  275.     end
  276. end
  277. ---------------------------------------
  278. function Reset()
  279.     turtle.turnRight()
  280.     turtle.turnRight()
  281.     term.clear()
  282.     term.setCursorPos(1,1)
  283.     print("Sleeping for 30 mins...\nFuel Level:",turtle.getFuelLevel(),"\n\nI've gone out",RUNS,"times!")
  284.     sleep(1800)
  285. end
  286. ---------------------------------------
  287. Fuel_Types = {'minecraft:coal','railcraft:fuel_coke','ic2:coke'}
  288. RUNS = 1
  289. GO()
Add Comment
Please, Sign In to add comment