Advertisement
theDeanoRama

Lumberjack

Feb 25th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.98 KB | None | 0 0
  1. do
  2.   local reserve = turtle.getItemCount(16)
  3.   local fuel = turtle.getFuelLevel()
  4.   write("Checking Resources...\nIf available, place bone meals at slot 14.\n IMPORTANT\nDon't get the item slots mixed up, it's 1 - 16:top-left-right-bottom.\n At least 1 wood of the tree to farm at slot 1.\n Saplings go in slot 15 and source of fuel at slot 16.\n\n\n\n")
  5.  
  6.   function lackResource()
  7.     write("Lacking Resources\n")
  8.     write("[[Resource Placement]]\nItem\t\t\t\t\t\t\t\t:\tSlot Number\n")
  9.     write("Wood\t\t\t\t\t\t\t\t:\tSlot 1\nBone Meal\t\t\t:\tSlot 14\nSapling\t\t\t\t\t:\tSlot 15\nFuel Source\t:\tSlot 16\n")
  10.     write("Placing other items in these slots will cause unusual turtle behaviour.\n")
  11.     do
  12.       error()
  13.     end
  14.   end
  15.  
  16.   local sapling = turtle.getItemCount(15)
  17.   local wood = turtle.getItemCount(1)
  18.   if sapling >= 1 and wood >= 1 then
  19.  
  20.   local function down()
  21.     while not turtle.down() do
  22.       if turtle.detectDown() then
  23.           --#there's a block
  24.           --#we should mine it
  25.       turtle.digDown()
  26.       else
  27.          --#we can assume it's an entity
  28.          --#we should attack it
  29.       turtle.attackDown()
  30.       end
  31.     end
  32.   end
  33.    
  34.     function reposition()
  35.       turtle.turnRight()
  36.       turtle.turnRight()
  37.       turtle.forward()
  38.       turtle.forward()
  39.       turtle.forward()
  40.       turtle.turnRight()
  41.       turtle.turnRight()
  42.       turtle.select(1)
  43.     end
  44.  
  45.     function repositionbone()
  46.       turtle.turnRight()
  47.       turtle.turnRight()
  48.       turtle.forward()
  49.       turtle.forward()
  50.       turtle.turnRight()
  51.       turtle.turnRight()
  52.       turtle.select(1)
  53.     end
  54.  
  55.     function surplus()
  56.      surp = turtle.getItemCount(2)
  57.      if surp >= 2 then
  58.        turtle.turnLeft()
  59.        turtle.select(2)
  60.        turtle.drop()
  61.        turtle.turnRight()
  62.      end
  63.     end  
  64.      
  65.     function plantSap()
  66.       if not turtle.detect() then
  67.         turtle.forward()
  68.       end
  69.       if not turtle.detect() then
  70.         turtle.forward()
  71.       end
  72.       if turtle.detect() then
  73.         turtle.select(1)
  74.         fellOrwait()
  75.       end
  76.       if not turtle.detect() then
  77.         sapling = turtle.getItemCount(15)
  78.         if sapling >= 1 then
  79.           turtle.select(15)
  80.           turtle.place()
  81.           turtle.select(1)
  82.           checkBone()
  83.         end
  84.         reposition()
  85.         lackResource()
  86.       end
  87.     end
  88.  
  89.     function checkBone()
  90.       bone = turtle.getItemCount(14)
  91.       if bone >= 1 then
  92.         turtle.select(1)
  93.         if not turtle.compare() then
  94.           bone = turtle.getItemCount(14)
  95.           if bone >= 1 then
  96.             turtle.select(14)
  97.             turtle.place()
  98.             turtle.select(1)
  99.           end
  100.           fellOrwait()
  101.         end
  102.         if turtle.compare() then
  103.           fellOrwait()
  104.         end
  105.       end
  106.       turtle.select(1)
  107.       fellOrwait()
  108.     end
  109.  
  110.     function fellOrwait()
  111.       fuel = turtle.getFuelLevel()
  112.       if fuel <= 78 then
  113.         reserve = turtle.getItemCount(16)
  114.         if reserve == 0 then
  115.           write("Out of fuel reserve\n")
  116.           repositionbone()
  117.           lackResource()
  118.         end
  119.         turtle.select(16)
  120.         turtle.refuel(1)
  121.         turtle.select(1)
  122.       end
  123.       if turtle.compare() then
  124.         turtle.dig()
  125.         turtle.forward()
  126.         while turtle.compareUp() do
  127.           turtle.digUp()
  128.           turtle.up()
  129.         end
  130.         while not turtle.detectDown() do
  131.           down()
  132.         end
  133.         sapling = turtle.getItemCount(15)
  134.         if sapling >= 1 then
  135.           turtle.turnLeft()
  136.           turtle.suck()
  137.           turtle.turnRight()
  138.           turtle.turnRight()
  139.           turtle.suck()
  140.           surplus()
  141.           turtle.turnRight()
  142.           turtle.forward()
  143.           turtle.turnRight()
  144.           turtle.turnRight()
  145.           turtle.select(15)
  146.           turtle.place()
  147.           turtle.select(1)
  148.           bone = turtle.getItemCount(14)
  149.           if bone >= 1 then
  150.             checkBone()
  151.           end
  152.           repositionbone()
  153.           sleep(180)
  154.           plantSap()
  155.         end
  156.         reposition()
  157.         lackResource()
  158.       end
  159.       if not turtle.compare() then
  160.         bone = turtle.getItemCount(14)
  161.         if bone >= 1 then
  162.             checkBone()
  163.         end
  164.         repositionbone()
  165.         sleep(180)
  166.         print("Waiting for growth!")
  167.         plantSap()
  168.       end
  169.     end    
  170.    
  171.    
  172.     print("Number of Saplings: " ..sapling.. "\nWood reference checked! OK!\n")
  173.     fuel = turtle.getFuelLevel()
  174.     reserve = turtle.getItemCount(16)
  175.     if fuel <= 79 then
  176.       if reserve == 0 then
  177.         write("NOT ENOUGH FUEL FOR OPERATION\nPLACE FUEL ITEM IN SLOT 16\n")
  178.         lackResource()
  179.       end
  180.       do
  181.         turtle.select(16)
  182.         turtle.refuel(1)
  183.         turtle.select(1)
  184.         fuel = turtle.getFuelLevel()
  185.         print("Fuel Level:" ..fuel.."~\nAll Clear!\nCommencing Automated Logging\n")
  186.       end
  187.     end
  188.   plantSap()
  189.   end
  190. lackResource()
  191. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement