nupanick

Treekill 1.1

Dec 28th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.36 KB | None | 0 0
  1. -- TreeKilla v1.1
  2. -- Usage: treekill
  3. -- TreeKilla will pull and store the first block
  4. -- it finds. It then moves into the tree and
  5. -- begins to chop its way up, harvesting logs
  6. -- and leaves on the way.
  7. -- Once TreeKilla no longer finds logs above
  8. -- itself, it will move back down.
  9. -- If TreeKilla is set to tear down a 2x2 tree,
  10. -- it will move to the other corner of the trunk
  11. -- before coming down.
  12.  
  13. local function spindig()
  14.   for i=1,4 do
  15.     turtle.dig()
  16.     turtle.turnLeft()
  17.   end
  18. end
  19.  
  20. local y = 0
  21. local s = 0
  22. local f = 0
  23. local isBig = false
  24. local treeDir = 0 -- 0 for other log is left, 1 for other log is right
  25. local fuel
  26.  
  27. while turtle.getFuelLevel() <= 400 do
  28.   turtle.select(1) -- Refuel from slot 1
  29.   turtle.refuel(1)
  30. end
  31. fuel = turtle.getFuelLevel() -- We'll tell how much fuel we used
  32.  
  33. turtle.select(2)
  34. turtle.dig()
  35. turtle.forward() -- The turtle is now inside the tree.
  36. f = f + 1 -- We moved forward one block.
  37.  
  38. -- Detect "big" tree - is there a block ahead?
  39. if turtle.detect() then
  40.   isBig = true
  41.   turtle.turnLeft()
  42.   if turtle.detect() then
  43.     treeDir = 0
  44.   else
  45.     treeDir = 1
  46.   end
  47.   turtle.turnRight()
  48.   spindig()
  49. else
  50.   spindig() -- We'll always spindig.
  51. end
  52.  
  53. -- Until we encounter air above our tree, go up.
  54. while turtle.detectUp() ~= false do
  55.   turtle.digUp()
  56.   turtle.up()
  57.   spindig()
  58.   y = y + 1
  59. end
  60.  
  61. if isBig then
  62.   if treeDir == 0 then
  63.     turtle.turnLeft()
  64.     turtle.forward()
  65.     turtle.dig()
  66.     turtle.forward()
  67.     turtle.turnRight()
  68.   else
  69.     turtle.turnRight()
  70.     turtle.forward()
  71.     turtle.dig()
  72.     turtle.forward()
  73.     turtle.turnLeft()
  74.   end
  75.   spindig()
  76.   turtle.forward()
  77.   spindig()
  78.  
  79.   -- Descend.
  80.   while y ~= 0 do
  81.     turtle.digDown()
  82.     turtle.down()
  83.     spindig()
  84.     y = y - 1
  85.   end
  86. else
  87.   while y ~= 0 do
  88.     turtle.down()
  89.     y = y - 1
  90.   end
  91. end
  92.  
  93. if isBig then
  94.   if treeDir == 0 then
  95.     turtle.turnRight()
  96.     turtle.forward()
  97.     turtle.forward()
  98.     turtle.turnRight()
  99.     turtle.forward()
  100.     turtle.forward()
  101.     turtle.turnLeft()
  102.     turtle.turnLeft()
  103.   else
  104.     turtle.turnLeft()
  105.     turtle.forward()
  106.     turtle.forward()
  107.     turtle.turnLeft()
  108.     turtle.forward()
  109.     turtle.forward()
  110.     turtle.turnRight()
  111.     turtle.turnRight()
  112.   end
  113. else
  114.   turtle.back()
  115. end
  116.  
  117. print("We used " .. fuel - turtle.getFuelLevel() .. " units of fuel")
Advertisement
Add Comment
Please, Sign In to add comment