Advertisement
Shaka01

2x2 spruce farm

Nov 18th, 2016 (edited)
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.49 KB | None | 0 0
  1. ----- https://drive.google.com/drive/folders/1kjauE0XBuLGPOfnKRHc-a4aVUoU9wZYT
  2. ----crafty turtle! chest in slot 16, saplings in slot 1
  3.  
  4. moves = 0
  5. treemined = false
  6. local chestName = "minecraft:barrel"
  7. craftTable = peripheral.wrap("right")
  8.  
  9. function movesUp()
  10.     repeat
  11.         turtle.digUp()
  12.     until turtle.up()
  13.     moves = moves + 1
  14. end
  15.  
  16. function movesDown()
  17.     if turtle.down() then
  18.         moves = moves - 1
  19.     else
  20.         turtle.digDown()
  21.     end
  22. end
  23.  
  24. function inspect()
  25.     local success, data = turtle.inspect()
  26.         if data.name == "minecraft:spruce_log" then
  27.             holz = true
  28.         else
  29.             holz = false
  30.         end
  31.         if data.name == "minecraft:spruce_sapling" then
  32.             sapling = true
  33.         else
  34.             sapling = false
  35.         end
  36.     --print(data.name)
  37. end
  38.  
  39. function inspectDown()
  40.     local success, data = turtle.inspectDown()
  41.         if data.name == "minecraft:spruce_sapling" then
  42.             sapling = true
  43.         else
  44.             sapling = false
  45.         end
  46.         if data.name == "minecraft:dirt" or data.name == "minecraft:podzol" then
  47.             bottom = true
  48.         else
  49.             bottom = false
  50.         end
  51.     --print(data.name)
  52. end
  53.  
  54. function goUp()
  55.     repeat
  56.     inspect()
  57.     turtle.dig()
  58.     if moves == 0 then
  59.         turtle.select(1)
  60.         turtle.place()
  61.     end
  62.     if moves == 1 then
  63.         turtle.select(1)
  64.         turtle.placeDown()
  65.     end
  66.     movesUp()
  67.     until holz == false
  68. end
  69.  
  70. function goDown()
  71.     repeat
  72.     turtle.dig()
  73.     turtle.digDown()
  74.     movesDown()
  75.     inspectDown()
  76.     until moves == 1 or bottom == true
  77.     if bottom == true then
  78.         turtle.up()
  79.         moves = 1
  80.     end
  81. end
  82.  
  83. function changepos()
  84.     turtle.digDown()
  85.     if moves == 1 then
  86.         turtle.select(1)
  87.         turtle.placeDown()
  88.     end
  89.     repeat turtle.dig() until turtle.forward()
  90.     turtle.digUp()
  91.     if dir == "l" then
  92.         turtle.turnLeft()
  93.     elseif dir == "r" then
  94.         turtle.turnRight()
  95.     end
  96.     turtle.digDown()
  97.     if moves == 1 then
  98.         turtle.select(1)
  99.         turtle.placeDown()
  100.     end
  101.     repeat turtle.dig() until turtle.forward()
  102.     if dir == "l" then
  103.         turtle.turnLeft()
  104.     elseif dir == "r" then
  105.         turtle.turnRight()
  106.     end
  107.     turtle.digUp()
  108.     if moves == 1 then
  109.         turtle.turnLeft()
  110.         turtle.turnLeft()
  111.         repeat turtle.dig() until turtle.forward()
  112.         repeat turtle.digDown() until turtle.down()
  113.         turtle.turnRight()
  114.         turtle.turnRight()
  115.     end
  116. end
  117.  
  118. function checksaplings()
  119. if turtle.getItemCount(1) > 0 then
  120.     data = turtle.getItemDetail(1)
  121.     if data.name ~= "minecraft:spruce_sapling" then
  122.         repeat
  123.             print("No Saplings, something went wrong.")
  124.             sleep(5)
  125.             data = turtle.getItemDetail(1)
  126.         until data.name == "minecraft:spruce_sapling"
  127.     end
  128. else
  129.     repeat
  130.         print("No Saplings, something went wrong.")
  131.         sleep(5)
  132.     until turtle.getItemCount(1) > 0
  133. end
  134. end
  135.    
  136. function minetree()
  137. checksaplings()
  138. getinPos()
  139. goUp()
  140. changepos()
  141. goDown()
  142. changepos()
  143. moves = 0
  144. treemined = true
  145. end
  146.  
  147. function getinPos()
  148.     repeat turtle.dig() until turtle.forward()
  149. end
  150.  
  151.  
  152. function checktrees()
  153.     repeat turtle.dig() until turtle.forward()
  154.         ---vor links
  155.         dir = "r"
  156.         turtle.turnLeft()
  157.         inspect()
  158.         if holz == true then
  159.             minetree()
  160.         end
  161.         --vor rechts
  162.         dir = "l"
  163.         turtle.turnRight()
  164.         turtle.turnRight()
  165.         inspect()
  166.         if holz == true then
  167.             minetree()
  168.         end
  169.         --transition
  170.         turtle.turnRight()
  171.         repeat turtle.dig() until turtle.forward()
  172.         repeat turtle.dig() until turtle.forward()
  173.         ----
  174.         ---back links
  175.         dir = "r"
  176.         turtle.turnLeft()
  177.         inspect()
  178.         if holz == true then
  179.             minetree()
  180.         end
  181.         --back rechts
  182.         dir = "l"
  183.         turtle.turnRight()
  184.         turtle.turnRight()
  185.         inspect()
  186.         if holz == true then
  187.             minetree()
  188.         end
  189.         --
  190.         turtle.turnRight()
  191.         turtle.select(1)
  192.         saplings = turtle.getItemSpace(1)
  193.         turtle.suckDown(saplings)
  194.         repeat turtle.dig() until turtle.forward()
  195. end
  196.  
  197. function turtleFind(itemName)
  198.     for i=1, 16 do
  199.         local itemz = turtle.getItemDetail(i)
  200.         if itemz then
  201.             if itemz.name == itemName then
  202.                 turtle.select(i)
  203.                 return i
  204.             end
  205.         end
  206.     end
  207. end
  208.        
  209.  
  210. function dropitems()
  211.     for i=2,15 do
  212.         if turtle.getItemCount(i) > 0 then
  213.             data = turtle.getItemDetail(i)
  214.             turtle.select(i)
  215.             if data.name == "minecraft:spruce_log" then
  216.                 if turtle.dropDown() == false then
  217.                     repeat
  218.                     sleep(2)
  219.                     print("Nowhere to put item")
  220.                     until turtle.dropDown()
  221.                 end
  222.             else
  223.                 turtle.dropUp()
  224.             end
  225.         end
  226.     end
  227. end
  228.  
  229. function placechest()
  230.     turtleFind(chestName)
  231.     repeat
  232.     turtle.dig()
  233.     until turtle.place()
  234. end
  235.  
  236. function retrievechest()
  237.     turtle.select(1)
  238.     repeat until turtle.suck() == false
  239.     turtle.select(16)
  240.     turtle.dig()
  241.     turtle.select(1)
  242. end
  243.  
  244. function checkname()
  245.     if turtle.getItemCount(slot) > 0 then
  246.         if data.name == "minecraft:spruce_log" then
  247.             return true
  248.         end
  249.     end
  250. end
  251.  
  252. function craft()
  253.     turtle.select(16)
  254.     while craftTable.craft() do
  255.     stacksize = turtle.getItemCount(16)
  256.     turtle.refuel(stacksize)
  257.     end
  258. end
  259.  
  260. function findwood()
  261. slot = 0
  262. repeat
  263.     slot = slot + 1
  264.     data = turtle.getItemDetail(slot)
  265.     if turtle.getItemCount(slot) > 0 then
  266.         if data.name ~= "minecraft:spruce_log" then
  267.             turtle.select(slot)
  268.             turtle.drop()
  269.         end
  270.     end
  271. until slot == 15 or checkname() == true
  272.  
  273. if slot ~= 15 then
  274.     slot = slot + 1
  275.     for i =slot, 15 do
  276.         if turtle.getItemCount(i) > 0 then
  277.             turtle.select(i)
  278.             turtle.drop()
  279.         end
  280.     end
  281. end
  282. shell.run("refuel".." ".."all")
  283. end
  284.  
  285. function refuel()
  286. placechest()
  287. findwood()
  288. retrievechest()
  289. end
  290.        
  291. ---do all the things
  292.  
  293. function allthethings()
  294.     while true do
  295.     checktrees()
  296.     if turtle.getFuelLevel() < 6000 then
  297.         if treemined == true then
  298.             refuel()
  299.         end
  300.     end
  301.     dropitems()
  302.     sleep(15)
  303.     treemined = false
  304.     end
  305. end
  306.  
  307. allthethings()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement