Advertisement
Guest User

treetest

a guest
Jan 18th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.40 KB | None | 0 0
  1.  
  2. local dir = 0
  3.  
  4. local f = 0
  5. local x = 0
  6. local y = 0
  7. local z = 0
  8.  
  9. function digForward(count)
  10.   for i = 1, count do
  11.     while not turtle.forward() do
  12.       turtle.dig()
  13.     end
  14.     while turtle.digUp() do
  15.       os.sleep(0.5)
  16.     end
  17.     turtle.digDown()
  18.   end
  19.  
  20.   if f == 0 then
  21.     z = z + count
  22.   end
  23.   if f == 1 then
  24.     x = x - count
  25.   end
  26.   if f == 2 then
  27.     z = z - count
  28.   end
  29.   if f == 3 then
  30.     x = x + count
  31.   end
  32. end
  33.  
  34. function forward(count)
  35.   for i = 1, count do
  36.     while not turtle.forward() do
  37.       turtle.dig()
  38.     end
  39.   end
  40.   if f == 0 then
  41.     z = z + count
  42.   end
  43.   if f == 1 then
  44.     x = x - count
  45.   end
  46.   if f == 2 then
  47.     z = z - count
  48.   end
  49.   if f == 3 then
  50.     x = x + count
  51.   end
  52. end
  53.  
  54. function up(count)
  55.   for i = 1, count do
  56.     while not turtle.up() do
  57.       turtle.digUp()
  58.       os.sleep(0.5)
  59.     end
  60.     y = y + 1
  61.   end
  62. end
  63.  
  64. function down(count)
  65.   for i = 1, count do
  66.     while not turtle.down() do
  67.       turtle.digDown()
  68.       os.sleep(0.5)
  69.     end
  70.     y = y - 1
  71.   end
  72. end
  73.  
  74. function left()
  75.   turtle.turnLeft()
  76.   f = f - 1
  77.   if f < 0 then
  78.     f = 3
  79.   end
  80. end
  81.  
  82. function right()
  83.   turtle.turnRight()
  84.   f = f + 1
  85.   if f > 3 then
  86.     f = 0
  87.   end
  88. end
  89.  
  90. function faceF(goF)
  91.   if f == goF then
  92.     return
  93.   end
  94.   if f == (goF - 1) then
  95.     right()
  96.     return
  97.   end
  98.   if f == (goF + 1) then
  99.     left()
  100.     return
  101.   end
  102.   if (f == 3) and (goF == 0) then
  103.     right()
  104.     return
  105.   end
  106.   if(f == 0) and (goF == 3) then
  107.     left()
  108.     return
  109.   end
  110.     right()
  111.     right()
  112. end
  113.  
  114. function goToX(goX)
  115.   if x == goX then
  116.     return
  117.   end
  118.   if x > goX then
  119.     faceF(1)
  120.     forward(x - goX)
  121.   else
  122.     faceF(3)
  123.     forward(goX - x)
  124.   end
  125. end
  126.  
  127. function goToZ(goZ)
  128.   if z == goZ then
  129.     return
  130.   end
  131.   if z > goZ then
  132.     faceF(2)
  133.     forward(z - goZ)
  134.   else
  135.     faceF(0)
  136.     forward(goZ - z)
  137.   end
  138. end
  139.  
  140. function goToY(goY)
  141.   if y == goY then
  142.     return
  143.   end
  144.   if y > goY then
  145.     down(y - goY)
  146.   else
  147.     up(goY - y)
  148.   end
  149. end
  150.  
  151. function goTo(goX, goY, goZ, goF)
  152.   goToX(goX)
  153.   goToZ(goZ)
  154.   goToY(goY)
  155.   faceF(goF)
  156. end
  157.  
  158.  
  159. function panic()
  160.   if turtle.getItemCount(16) > 0 then
  161.     local holdX = x
  162.     local holdY = y
  163.     local holdZ = z
  164.     local holdF = f
  165.     goTo(0,y,0,0)
  166.     goToY(0)
  167.     turtle.back()
  168.     turtle.turnLeft()
  169.     for i = 1, 16 do
  170.       turtle.select(i)
  171.       data = turtle.getItemDetail(i)
  172.       if data.name == "minecraft:cobblestone" then
  173.         turtle.drop()
  174.       elseif data.name == "minecraft:dirt" then
  175.         while not turtle.dropUp() do
  176.           os.sleep(5)
  177.         end
  178.       elseif data.name == "minecraft:gravel" then
  179.         turtle.turnLeft()
  180.         turtle.turnLeft()
  181.         while not turtle.drop() do
  182.           os.sleep()
  183.         end
  184.         turtle.turnLeft()
  185.         turtle.turnLeft()
  186.       else
  187.         while not turtle.dropDown() do
  188.           os.sleep(0.5)
  189.         end
  190.       end
  191.     end
  192.     turtle.select(1)
  193.     turtle.turnRight()
  194.     turtle.forward()
  195.     goToY(holdY)
  196.     goTo(holdX, y, holdZ, holdF)
  197.   end
  198. end
  199.  
  200. local lastTree
  201.  
  202. function checkLog()
  203.   local success, data = turtle.inspect()
  204.   if success then
  205.     if data.name == "minecraft:log" then
  206.       return true
  207.     else
  208.       return false
  209.     end
  210.   else
  211.     return false
  212.   end
  213. end
  214.  
  215. function checkTree()
  216.   if checkLog() then
  217.      local holdX = x
  218.      local holdY = y
  219.      local holdZ = z
  220.      local holdF = f
  221.      killTree()
  222.      forward(1)
  223.      findSaplings()
  224.      goTo(holdX, holdY, holdZ, holdF)
  225.   end
  226. end
  227.  
  228. function killTree()
  229.   local leftRight
  230.   local treeHeight = 0
  231.   forward(1)
  232.   left()
  233.   leftRight = checkLog()
  234.   lastTree = leftRight
  235.   right()
  236.   turtle.dig()
  237.   while turtle.detectUp() do
  238.     up(1)
  239.     turtle.dig()
  240.     treeHeight = treeHeight + 1
  241.   end
  242.   if leftRight then
  243.     left()
  244.     forward(1)
  245.     right()
  246.   else
  247.     right()
  248.     forward(1)
  249.     left()
  250.   end
  251.   for i = 1, treeHeight do
  252.     down(1)
  253.     turtle.dig()
  254.   end
  255.   if leftRight then
  256.     turtle.digDown()
  257.     forward(1)
  258.     turtle.digDown()
  259.     right()
  260.     forward(1)
  261.     turtle.digDown()
  262.     right()
  263.     forward(1)
  264.     turtle.digDown()
  265.     forward(1)
  266.     left()
  267.     left()
  268.   else
  269.     turtle.digDown()
  270.     forward(1)
  271.     turtle.digDown()
  272.     left()
  273.     forward(1)
  274.     turtle.digDown()
  275.     left()
  276.     forward(1)
  277.     turtle.digDown()
  278.     forward(1)
  279.     right()
  280.     right()
  281.   end
  282. end
  283.  
  284. function findSaplings()
  285.   if lastTree then
  286.     for m = 1, 5 do
  287.       local distance = (m * 2) - 1
  288.       for n = 1, 4 do
  289.         for i = 1, distance do
  290.           checkTree()
  291.           forward(1)
  292.           turtle.suckDown()
  293.         end
  294.         left()
  295.       end
  296.       left()
  297.       left()
  298.       checkTree()
  299.       forward(1)
  300.       turtle.suckDown()
  301.       left()
  302.       left()
  303.       right()
  304.       checkTree()
  305.       forward(1)
  306.       turtle.suckDown()
  307.       left()
  308.     end
  309.   else
  310.     for m = 1, 5 do
  311.       local distance = (m * 2) - 1
  312.       for n = 1, 4 do
  313.         for i = 1, distance do
  314.           checkTree()
  315.           forward(1)
  316.           turtle.suckDown()
  317.         end
  318.         right()
  319.       end
  320.       left()
  321.       left()
  322.       checkTree()
  323.       forward(1)
  324.       turtle.suckDown()
  325.       left()
  326.       left()
  327.       left()
  328.       checkTree()
  329.       forward(1)
  330.       turtle.suckDown()
  331.       right()
  332.     end
  333.   end
  334. end
  335.  
  336. killTree()
  337. forward(1)
  338. findSaplings()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement