Advertisement
carlosjuero

Minecraft Turtle Lumberjack v1

Jul 12th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.11 KB | None | 0 0
  1. tArgs = {...}
  2.  
  3. local fuelSlot, chestSlot = 16, 15
  4. local height = 0
  5.  
  6. function goUp(distance)
  7.   if distance == nil then distance = 1 end
  8.   shell.run("go", "up", distance)
  9. end
  10.  
  11. function goDown(distance)
  12.   if distance == nil then distance = 1 end
  13.   shell.run("go", "up", distance)
  14. end
  15.  
  16. function goForward(distance)
  17.   if distance == nil then distance = 1 end
  18.   shell.run("go", "forward", distance)
  19. end
  20.  
  21. function goBack(distance)
  22.   if distance == nil then distance = 1 end
  23.   shell.run("go", "back", distance)
  24. end
  25.  
  26. function digUp(distance)
  27.   if distance == nil then distance = 1 end
  28.   for i = 1, distance do
  29.     while turtle.detectUp() == true do
  30.       turtle.digUp()
  31.       sleep(0.5)
  32.     end
  33.     if distance > 1 then
  34.       goUp()
  35.     end
  36.   end
  37. end
  38.  
  39. function dig(distance)
  40.   if distance == nil then distance = 1 end
  41.   for i = 1, distance do
  42.     while turtle.detect() == true do
  43.       turtle.dig()
  44.       sleep(0.5)
  45.     end
  46.   end
  47. end
  48.  
  49. function digDown(distance)
  50.   if distance == nil then distance = 1 end
  51.   for i = 1, distance do
  52.     turtle.digDown()
  53.     sleep(0.5)
  54.     if distance > 1 then
  55.       goDown()
  56.     end
  57.   end
  58. end
  59.  
  60. function getFuel()
  61.   return turtle.getFuelLevel()
  62. end
  63.  
  64. function returnToStart()
  65.   goDown(height)
  66.   height = 0
  67. end
  68.  
  69. function dropLoad()
  70.   shell.run("turn", "around")
  71.   for i = 1, 14 do
  72.     turtle.select(i)
  73.     turtle.drop()
  74.   end
  75.   turtle.select(1)
  76. end
  77.  
  78. if tArgs[1] == "-h" then
  79.   print("Usage: lumberjack <redwood>")
  80. elseif tArgs[1] == nil then
  81.   if turtle.getItemCount(chestSlot) == 0 or turtle.getItemCount(fuelSlot) == 0 then
  82.     print("Please insert a chest into slot "..chestSlot.." and fuel into slot "..fuelSlot..", then run lumberjack again")
  83.   else  
  84.     shell.run("turn", "around")
  85.     turtle.select(chestSlot)
  86.     turtle.place()
  87.     turtle.select(1)
  88.     shell.run("turn", "around")
  89.     dig()
  90.     goForward()
  91.     while turtle.detectUp() == true do
  92.       digUp()
  93.       goUp()
  94.       height = height + 1
  95.       if getFuel() == 0 then
  96.         turtle.select(fuelSlot)
  97.         turtle.refuel(5)
  98.         turtle.select(1)
  99.       end
  100.     end
  101.     returnToStart()
  102.     dropLoad()
  103.   end
  104. elseif tArgs[1] == "redwood" then
  105.   if turtle.getItemCount(chestSlot) == 0 or turtle.getItemCount(fuelSlot) == 0 then
  106.     print("Please insert a chest into slot "..chestSlot.." and fuel into slot "..fuelSlot..", then run lumberjack again")
  107.   else
  108.     shell.run("turn", "around")
  109.     turtle.select(chestSlot)
  110.     turtle.place()
  111.     turtle.select(1)
  112.     shell.run("turn", "around")
  113.     dig()
  114.     goForward()
  115.     while turtle.detectUp() == true do
  116.       shell.run("turn", "right")
  117.       dig()
  118.       shell.run("turn", "left")
  119.       dig()
  120.       goForward()
  121.       shell.run("turn", "right")
  122.       dig()
  123.       shell.run("turn", "left")
  124.       goBack()
  125.       digUp()
  126.       goUp()
  127.       height = height + 1
  128.       if getFuel() == 0 then
  129.         turtle.select(fuelSlot)
  130.         turtle.refuel(5)
  131.         turtle.select(1)
  132.       end
  133.     end
  134.     if turtle.detect() == true then
  135.       dig()
  136.       shell.run("turn", "right")
  137.       dig()
  138.       shell.run("turn", "left")
  139.       goForward()
  140.       shell.run("turn", "right")
  141.       dig()
  142.       shell.run("turn", "left")
  143.       goBack()
  144.     end
  145.     returnToStart()
  146.     dropLoad()
  147.   end
  148. else
  149.   print("Usage: lumberjack <redwood>")
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement