Advertisement
Guest User

auto_farm

a guest
Jul 17th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.83 KB | None | 0 0
  1. version = "0.1"
  2.  
  3. --Var section--
  4. fuelLevel = 0
  5. fuelNeeded = 26
  6. other_crops = {
  7.  
  8.     "minecraft:wheat",
  9.     "minecraft:potato",
  10.     "minecraft:carrot",
  11.     "minecraft:beetroot"
  12.  
  13. }
  14.  
  15.  
  16.  
  17.  
  18. ---------------
  19.  
  20. function turn()
  21.  
  22.     if chest_pos == "left" then
  23.         turtle.turnRight()
  24.  
  25.     elseif chest_pos == "right" then
  26.         turtle.turnLeft()
  27.  
  28.     end
  29.  
  30. end
  31.  
  32. function turn2()
  33.  
  34.     if chest_pos == "left" then
  35.         turtle.turnLeft()
  36.  
  37.     elseif chest_pos == "right" then
  38.         turtle.turnRight()
  39.  
  40.     end
  41.  
  42. end
  43.  
  44. function pumpkin_melon()
  45.     turtle.up()
  46.     turtle.forward()
  47.     local bool, crop = turtle.inspectDown()
  48.     for i = 1, 5 do
  49.         if bool == true then
  50.             if crop.name == "minecraft:melon" or "minecraft:pumpkin" then
  51.                 turtle.digDown()
  52.  
  53.             end
  54.  
  55.         end
  56.         turtle.forward()
  57.  
  58.     end
  59.     turn()
  60.     turtle.forward()
  61.     turtle.forward()
  62.     turtle.forward()
  63.     turtle.forward()
  64.     turn()
  65.  
  66.     for i = 1, 6 do
  67.         if bool == true then
  68.             if crop.name == "minecraft:melon" or "minecraft:pumpkin" then
  69.                 turtle.digDown()
  70.  
  71.             end
  72.  
  73.         end
  74.         turtle.forward()
  75.  
  76.  
  77.     end
  78.     turn()
  79.     turtle.forward()
  80.     turtle.forward()
  81.     turtle.forward()
  82.     turtle.forward()
  83.     turn()
  84.     turtle.forward()
  85.     turtle.forward()
  86.     turn2()
  87.  
  88.     --drop off melon or pumpkins--
  89.     for k = 1, 16 do
  90.         local item = turtle.getItemDetail(k)
  91.         if item then
  92.             if item.name == "minecraft:melon" or "minecraft:pumpkin" then
  93.                 turtle.select(k)
  94.                 turtle.drop()
  95.  
  96.             end
  97.  
  98.         end
  99.  
  100.     end
  101.  
  102.     turn2()
  103.     turtle.forward()
  104.     turtle.forward()
  105.     turtle.down()
  106.     turn2()
  107.     turn2()
  108. end
  109.  
  110. function other_crop()
  111.     turtle.up()
  112.     turtle.forward()
  113.     local bool, crop = turtle.inspectDown()
  114.     for i = 1, 5 do
  115.         if bool == true then
  116.             for i = 1, #other_crops do
  117.                 if crop.name == other_crops[i] and crop.metadata == 7 then
  118.                     turtle.digDown()
  119.  
  120.                 end
  121.             end
  122.  
  123.         end
  124.         turtle.forward()
  125.     end
  126.  
  127.     turn()
  128.     turtle.forward()
  129.     turn()
  130.  
  131.     for i = 1, 6 do
  132.         if crop then
  133.             for i = 1, #other_crops do
  134.                 if crop.name == other_crops[i] and crop.metadata == 7 then
  135.                     other_crop()
  136.  
  137.                 end
  138.             end
  139.  
  140.         end
  141.         turtle.forward()
  142.     end
  143.  
  144.     turn2()
  145.     turtle.forward()
  146.     --reached middle of farm
  147.     turtle.forward()
  148.     turn2()
  149.  
  150.     for i = 1, 5 do
  151.         if crop then
  152.             for i = 1, #other_crops do
  153.                 if crop.name == other_crops[i] and crop.metadata == 7 then
  154.                     other_crop()
  155.  
  156.                 end
  157.             end
  158.  
  159.         end
  160.         turtle.forward()
  161.     end
  162.  
  163.     turn()
  164.     turtle.forward()
  165.     turn()
  166.  
  167.     for i = 1, 6 do
  168.         if crop then
  169.             for i = 1, #other_crops do
  170.                 if crop.name == other_crops[i] and crop.metadata == 7 then
  171.                     other_crop()
  172.  
  173.                 end
  174.             end
  175.  
  176.         end
  177.         turtle.forward()
  178.     end
  179.  
  180.     turn()
  181.     turtle.forward()
  182.     turtle.forward()
  183.     turtle.forward()
  184.     turtle.forward()
  185.     turn()
  186.     turtle.forward()
  187.     turtle.forward()
  188.     turn2()
  189.  
  190.     --drop off crop--
  191.  
  192.     for k = 1, 16 do
  193.         local item = turtle.getItemDetail(k)
  194.         if item then
  195.             for i = 1, #other_crops do
  196.                 if item.name == other_crops[i] then
  197.                     turtle.select(k)
  198.                     turtle.drop()
  199.  
  200.                 end
  201.             end
  202.  
  203.         end
  204.     end
  205.  
  206.     turn2()
  207.     turtle.forward()
  208.     turtle.forward()
  209.     turtle.down()
  210.     turn2()
  211.     turn2()
  212.  
  213. end
  214.  
  215.  
  216. --------------------end functions----------------------
  217.  
  218. -------------------CHEST CHECK!!!-----------------------------
  219. turtle.turnLeft()
  220. bool, block = turtle.inspect()
  221.  
  222. if block.name == "minecraft:chest" then
  223.     chest_pos = "left"
  224.  
  225. else
  226.     chest_pos = "right"
  227.     print("Chest is not to the left. Assuming it's to the right.")
  228.  
  229. end
  230.  
  231. turtle.turnRight()
  232. --^^^^^^^^^^^^^^^^^CHEST CHECK!!!^^^^^^^^^^^^^^^^^^^^^^^^^^^^--
  233.  
  234.  
  235. while true do
  236.     local bool, crop = turtle.inspect()
  237.     if bool == true then
  238.         if crop.name == "minecraft:pumpkin" or "minecraft:melon_block" then
  239.             pumpkin_melon()
  240.  
  241.         else
  242.             for i = 1, #other_crops do
  243.                 if crop.name == other_crops[i] and crop.metadata == 7 then
  244.                     other_crop()
  245.  
  246.                 end
  247.  
  248.             end
  249.         end
  250.  
  251.     end
  252. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement