Advertisement
promitheus_sal

Lumberjack

Mar 29th, 2024 (edited)
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.77 KB | Source Code | 0 0
  1.  
  2. FARMX = 5
  3. FARMY = 3
  4. TREE_DISTANCE_X = 3
  5. TREE_DISTANCE_Y = 3
  6. ITER_DELAY = 60
  7.  
  8. m=peripheral.find('magnet')
  9.  
  10. function checkblock(r,d)
  11.     t = d.tags
  12.     if type(t)~='table' then return false end
  13.     if t["minecraft:logs"] then return true else return false end
  14. end
  15.  
  16. function check_front()
  17.     return checkblock(turtle.inspect())
  18. end
  19.  
  20. function check_up()
  21.     return checkblock(turtle.inspectUp())
  22. end
  23.  
  24. function check_down()
  25.     return checkblock(turtle.inspectDown())
  26. end
  27.  
  28.  
  29.  
  30. function dfs_mine()
  31.     for i=1,4 do
  32.         if check_front() then
  33.             turtle.dig()
  34.             turtle.forward()
  35.             dfs_mine()
  36.             turtle.back()
  37.         end
  38.         turtle.turnRight()
  39.         if check_up() then
  40.             turtle.digUp()
  41.             turtle.up()
  42.             dfs_mine()
  43.             turtle.down()
  44.         end
  45.         if check_down() then
  46.             turtle.digDown()
  47.             turtle.down()
  48.             dfs_mine()
  49.             turtle.up()
  50.         end
  51.     end
  52. end
  53.  
  54. function straight_mine()
  55.     i=0
  56.     while check_up() do
  57.         turtle.digUp()
  58.         turtle.up()
  59.         i=i+1
  60.     end
  61.     while i>0 do
  62.         turtle.down()
  63.         i=i-1
  64.     end
  65. end
  66.  
  67. function check_refuel()
  68.     turtle.select(1)
  69.     while turtle.getFuelLevel()<160 do
  70.         turtle.refuel(1)
  71.     end
  72. end
  73.  
  74. mine_tree_func = straight_mine --or dfs_mine
  75.  
  76. function handle_farm(x,y)
  77.     turtle.forward()
  78.     for a=1,x do
  79.         for b=1,y do
  80.             for i=1,TREE_DISTANCE_X do
  81.                 turtle.forward()
  82.             end
  83.             turtle.turnLeft()
  84.             if check_front() then
  85.                 check_refuel()
  86.                 turtle.dig()
  87.                 turtle.forward()
  88.                 mine_tree_func()
  89.                 turtle.back()
  90.                 check_refuel()
  91.                 os.sleep(5)
  92.                 m.magnetize(4)
  93.             end
  94.             turtle.select(2)
  95.             turtle.place()
  96.             turtle.select(1)
  97.             turtle.turnRight()
  98.             check_refuel()
  99.         end
  100.         for b=1,y*TREE_DISTANCE_X do turtle.back() end
  101.         turtle.turnRight()
  102.         for i=1,TREE_DISTANCE_Y do
  103.             turtle.forward()
  104.         end
  105.         turtle.turnLeft()
  106.         check_refuel()
  107.     end
  108.     turtle.turnLeft()
  109.     for a=1,TREE_DISTANCE_Y*x do
  110.         turtle.forward()
  111.         check_refuel()
  112.     end
  113.     turtle.turnRight()
  114.     turtle.back()
  115.     turtle.turnLeft()
  116.     turtle.turnLeft()
  117.     check_refuel()
  118.     for i=3,16 do
  119.         turtle.select(i)
  120.         turtle.drop()
  121.     end
  122.     turtle.select(1)
  123.     turtle.turnLeft()
  124.     turtle.turnLeft()
  125. end
  126.  
  127. it=1
  128. while true do
  129.     print("Iteration #"..tostring(it))
  130.     handle_farm(FARMX,FARMY)
  131.     print("Done!")
  132.     os.sleep(ITER_DELAY)
  133.     it=it+1
  134. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement