Advertisement
Guest User

Lumberjack

a guest
Aug 2nd, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.94 KB | None | 0 0
  1. print("Thanks for using Lumberjack v3, feel free to copy, distribute or edit this program. - Melodicolt")
  2. direction = 0
  3. function mainLoop()
  4.     refuelTurtle()
  5.     checkInventory()
  6.     if turtle.detect() then
  7.         process()
  8.     end
  9.     turtle.forward()
  10. end
  11. function refuelTurtle()
  12.     if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 50 then
  13.         local fuelCounter = 0
  14.         for i = 1, 16 do
  15.             if turtle.getItemCount(i) > 0 then
  16.                 local data = turtle.getItemDetail(i)
  17.                 if data.name == "minecraft:coal" then
  18.                     turtle.select(i)
  19.                     turtle.refuel()
  20.                 else
  21.                     fuelCounter = fuelCounter + 1
  22.                 end
  23.             end
  24.         end
  25.         if fuelCounter == 16 then
  26.             print("I'm out of fuel.")
  27.             fuelCounter = 0
  28.         end
  29.     end
  30. end
  31. function checkInventory()
  32.     local emptyInvSlots = 0
  33.     for i = 1, 16 do
  34.         if turtle.getItemCount(i) == 0 then
  35.             emptyInvSlots = emptyInvSlots + 1
  36.         end
  37.     end
  38.     if emptyInvSlots == 0 then
  39.         print("Inventory full.")
  40.     else
  41.         emptyInvSlots = 0
  42.     end
  43. end
  44. function process()
  45.     local success, data = turtle.inspect()
  46.     if data.name == "minecraft:log" then
  47.         local movesUp = 0
  48.         turtle.dig()
  49.         turtle.forward()
  50.         turtle.digDown()
  51.         while turtle.detectUp() do
  52.             local success, data = turtle.inspectUp()
  53.             if data.name == "minecraft:log" then
  54.                 turtle.digUp()
  55.                 turtle.up()
  56.                 movesUp = movesUp + 1
  57.             else
  58.                 turtle.digUp()
  59.             end
  60.         end
  61.         while movesUp ~= 0 do
  62.             turtle.down()
  63.             movesUp = movesUp - 1
  64.         end
  65.         local saplings = 0
  66.         for i = 1, 16 do
  67.             if turtle.getItemCount(i) > 0 then
  68.                 local data = turtle.getItemDetail(i)
  69.                 if data.name == "minecraft:sapling" then
  70.                     turtle.select(i)
  71.                     turtle.placeDown()
  72.                     saplings = saplings + 1
  73.                 end
  74.             end
  75.         end
  76.         if saplings == 0 then
  77.             print("Out of saplings.")
  78.         end
  79.     elseif data.name == "minecraft:fence" then
  80.         local success, data = turtle.inspectDown()
  81.         if data.name == "IronChest:BlockIronChest" then
  82.             for i = 1, 16 do
  83.                 if turtle.getItemCount(i) > 0 then
  84.                     local data = turtle.getItemDetail(i)
  85.                     if data.name == "minecraft:log" then
  86.                         turtle.select(i)
  87.                         turtle.dropDown()
  88.                     end
  89.                 end
  90.             end
  91.         end
  92.         if direction == 0 then
  93.             turtle.turnRight()
  94.             local success, data = turtle.inspect()
  95.             if data.name == "minecraft:leaves" then
  96.                 turtle.dig()
  97.             end
  98.             if turtle.forward() then
  99.                 turtle.turnRight()
  100.                 direction = 1
  101.             else
  102.                 turtle.turnLeft()
  103.                 turtle.turnLeft()
  104.                 if turtle.forward() then
  105.                     turtle.turnLeft()
  106.                 end
  107.             end
  108.         elseif direction == 1 then
  109.             turtle.turnLeft()
  110.             local success, data = turtle.inspect()
  111.             if data.name == "minecraft:leaves" then
  112.                 turtle.dig()
  113.             end
  114.             if turtle.forward() then
  115.                 turtle.turnLeft()
  116.                 direction = 0
  117.             else
  118.                 turtle.turnRight()
  119.                 turtle.turnRight()
  120.                 if turtle.forward() then
  121.                     turtle.turnRight()
  122.                 end
  123.             end
  124.         else
  125.             print("Direction is messed up.")
  126.         end
  127.     else
  128.         turtle.dig()
  129.     end
  130. end
  131. while true do
  132.     mainLoop()
  133. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement