Advertisement
augustclear

ChopTree

May 6th, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.38 KB | None | 0 0
  1. local success = false
  2. local data = nil
  3.  
  4. local facing = 1;
  5.  
  6. local height = 0;
  7.  
  8. ---------------------------------------
  9. -- BASIC FUNCTIONS FOR TURTLE CONTROL -
  10. ---------------------------------------
  11.  
  12. local function gf(n)
  13.   if n==nil then
  14.     n=1
  15.   end
  16.   for i=1,n,1 do
  17.     turtle.forward()
  18.   end
  19. end
  20. local function gb(n)
  21.   if n==nil then
  22.     n=1
  23.   end
  24.   for i=1,n,1 do
  25.     turtle.back()
  26.   end
  27. end
  28. local function gu(n)
  29.   if n==nil then
  30.     n=1
  31.   end
  32.   for i=1,n,1 do
  33.     turtle.up()
  34.   end
  35. end
  36. local function gd(n)
  37.   if n==nil then
  38.     n=1
  39.   end
  40.   for i=1,n,1 do
  41.     turtle.down()
  42.   end
  43. end
  44. local function tl()
  45.   turtle.turnLeft()
  46.   if facing == 1 then
  47.     facing = 4
  48.   else
  49.     facing = facing - 1
  50.   end
  51. end
  52. local function tr()
  53.   turtle.turnRight()
  54.   if facing == 4 then
  55.     facing = 1
  56.   else
  57.     facing = facing + 1
  58.   end
  59. end
  60. local function pf()  turtle.place()       end
  61. local function pu()  turtle.placeUp()     end
  62. local function pd()  turtle.placeDown()   end
  63. local function df()  return turtle.dig()  end
  64. local function du()  turtle.digUp()       end
  65. local function dd()  turtle.digDown()     end
  66. local function sf()  turtle.suck()        end
  67. local function su(n)
  68.   if n==nil then
  69.     while turtle.suckUp() do end
  70.   else
  71.     for i=1,n do
  72.       turtle.suckUp()
  73.     end
  74.   end
  75. end
  76. local function sd(n)
  77.   if n==nil then
  78.     while turtle.suckDown() do end
  79.   else
  80.     for i=1,n do
  81.       turtle.suckDown()
  82.     end
  83.   end
  84. end
  85. local function Df()  turtle.drop()       end
  86. local function Du()  turtle.dropUp()     end
  87. local function Dd(n)
  88.   if n==nil then n=64 end
  89.   turtle.dropDown(n)
  90. end
  91. local function ss(s) turtle.select(s)    end
  92. local function cf() turtle.compare()     end
  93. local function cu() turtle.compareUp()   end
  94.  
  95. ---------------------------------------
  96. --          Building Blocks          --
  97. ---------------------------------------
  98.  
  99. local function lightUp()
  100.     redstone.setOutput("back", true)
  101.     redstone.setOutput("right", true)
  102.     redstone.setOutput("left", true)
  103.     redstone.setOutput("top", true)
  104.     redstone.setOutput("bottom", true)
  105. end
  106.  
  107. local function findLog()
  108.     repeat
  109.         tl()
  110.         success, data = turtle.inspect()
  111.     until data.name == "minecraft:log"
  112. end
  113.  
  114. local function chop2x2()
  115.     data = nil
  116.     repeat
  117.         height = height - 1
  118.         dd()
  119.         gd()
  120.         findLog()
  121.         df()
  122.         findLog()
  123.         df()
  124.     until height == 0
  125.     gu()
  126. end
  127.  
  128. local function chopTree()
  129.     success, data = turtle.inspect()
  130.     if data.name == "minecraft:log" then
  131.         df()
  132.         gf()
  133.         while success do
  134.             success, data = turtle.inspectUp()
  135.             if data.name == "minecraft:log" then
  136.                 du()
  137.                 gu()
  138.                 height = height + 1
  139.             else
  140.                 break
  141.             end
  142.         end
  143.         success, data = turtle.inspect()
  144.         if data.name == "minecraft:log" then
  145.             df()
  146.             gf()
  147.             du()
  148.             findLog()
  149.             df()
  150.             gf()
  151.             du()
  152.             findLog()
  153.             df()
  154.             gf()
  155.             du()
  156.             gb()
  157.         else
  158.             gd()
  159.             height = height - 1
  160.             success, data = turtle.inspect()
  161.             if data.name == "minecraft:log" then
  162.                 df()
  163.                 gf()
  164.                 findLog()
  165.                 df()
  166.                 gf()
  167.                 findLog()
  168.                 df()
  169.             end
  170.         end
  171.         if data.name == "minecraft:log" then
  172.             chop2x2()
  173.         else
  174.             repeat
  175.                 gd()
  176.                 height = height - 1
  177.             until height == 0
  178.         end
  179.     else
  180.         print("No tree found")
  181.     end
  182. end
  183.  
  184. ---------------------------------------
  185. ---------         MAIN        ---------
  186. ---------------------------------------
  187.  
  188. chopTree()
  189.  
  190. lightUp()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement