Advertisement
Blackhome

Lumberjack

Jan 6th, 2025
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.80 KB | Gaming | 0 0
  1. --[[
  2.     - side:         2 for right, left otherwise
  3.     - numTun(nel):  number of small mining tunnels on side
  4.     - lenTun(nel):  length of each mining tunnel
  5.     - bLava:        allow the collection of lava
  6.     - bAllLava:     Emptys every lava lake it comes across
  7.  
  8. ]]
  9. side, numTun, lenTun, bLava, bAllLava = ...
  10.  
  11. stringtoboolean = { ["true"] = true, ["false"] = false }
  12.  
  13. --side for the mining tunnels
  14. tunnelSide = "left"
  15. if side then
  16.     if tonumber(side) == 2 then
  17.         tunnelSide = "right"
  18.     end
  19. end
  20.  
  21. --number of tunnels (2 blocks in between)
  22. numTunnels = 1
  23. if numTun then
  24.     numTunnels = tonumber(numTun)
  25. end
  26.  
  27. --length of single tunnel
  28. lenTunnel = 3
  29. if lenTun then
  30.     lenTunnel = tonumber(lenTun)
  31. end
  32.  
  33. --uses or destroys bordering lava
  34. if bLava then
  35.     bLava = stringtoboolean[bLava]
  36. else
  37.     bLava = false
  38. end
  39.  
  40. --uses or destroys all connected lava
  41. if bAllLava then
  42.     bAllLava = stringtoboolean[bAllLava]
  43. else
  44.     bAllLava = false
  45. end
  46.  
  47.  
  48. --Counter for found lava springs
  49. lavaCnt = {0}
  50.  
  51. blocksToMine = {
  52.                 "minecraft:oak_log", "minecraft:oak_leaves",
  53.                 "minecraft:spruce_log", "minecraft:spruce_leaves",
  54.                 "minecraft:birch_log", "minecraft:birch_leaves",
  55.                 "minecraft:jungle_log", "minecraft:jungle_leaves",
  56.                 "minecraft:acacia_log", "minecraft:acacia_leaves",
  57.                 "minecraft:dark_oak_log", "minecraft:dark_oak_leaves",
  58.                 "minecraft:mangrove_log", "minecraft:mangrove_leaves",
  59.                 "minecraft:cherry_log", "minecraft:cherry_leaves",
  60.                 "minecraft:pale_oak_log", "minecraft:pale_oak_leaves",
  61.                 "minecraft:crimson_stem", "minecraft:azalea_leaves",
  62.                 "minecraft:warped_stem", "minecraft:flowering_azalea_leaves",
  63.                 "minecraft:nether_wart_block", "minecraft:warped_wart_block",
  64.                 "minecraft:shroomlight"
  65.             }
  66. notDroppedBlocks = {
  67.                     "minecraft:chest", "minecraft:torch",
  68.                     "minecraft:bucket", "minecraft:lava_bucket"
  69.                     }
  70. lavaArray = {"minecraft:lava"}
  71. bucketList = {"minecraft:bucket", "minecraft:lava_bucket"}
  72.  
  73.  
  74. local move = require("move")
  75. local inspect = require("inspect")
  76. local collectLava = require("collectLava")
  77. local dropAll = require("dropAll")
  78.  
  79.  
  80. -- turns into tunnel or back out in starting direction
  81. function takeTurn()
  82.     if tunnelSide == "left" then
  83.         turtle.turnLeft()
  84.     else
  85.         turtle.turnRight()
  86.     end
  87. end
  88.  
  89. -- collects all valuable blcoks that are connected to start block (+Lava collection/destruction possible)
  90. function collectAllValuables()
  91.     local bLocLava = bLava
  92.     if not collectLava.selectBucket() then
  93.         bLocLava = false
  94.     end
  95.  
  96.     if inspect.Down(blocksToMine) then
  97.         move.Down()
  98.         collectAllValuables()
  99.         move.Up()
  100.     elseif inspect.Down(lavaArray) and bLocLava then
  101.         collectLava.Bottom(lavaCnt)
  102.         if bAllLava then
  103.             move.Down()
  104.             collectAllValuables()
  105.             move.Up()
  106.         end
  107.     end
  108.  
  109.     if inspect.Forward(blocksToMine) then
  110.         move.Forward()
  111.         collectAllValuables()
  112.         move.turnBack()
  113.         move.Forward()
  114.         move.turnBack()
  115.     elseif inspect.Forward(lavaArray) and bLocLava then
  116.         collectLava.Front(lavaCnt)
  117.         if bAllLava then
  118.             move.Forward()
  119.             collectAllValuables()
  120.             move.turnBack()
  121.             move.Forward()
  122.             move.turnBack()
  123.         end
  124.     end
  125.     turtle.turnRight()      -- right
  126.  
  127.     if inspect.Forward(blocksToMine) then
  128.         move.Forward()
  129.         collectAllValuables()
  130.         move.turnBack()
  131.         move.Forward()
  132.         move.turnBack()
  133.     elseif inspect.Forward(lavaArray) and bLocLava then
  134.         collectLava.Front(lavaCnt)
  135.         if bAllLava then
  136.             move.Forward()
  137.             collectAllValuables()
  138.             move.turnBack()
  139.             move.Forward()
  140.             move.turnBack()
  141.         end
  142.     end
  143.     turtle.turnRight()      -- back
  144.  
  145.     if inspect.Forward(blocksToMine) then
  146.         move.Forward()
  147.         collectAllValuables()
  148.         move.turnBack()
  149.         move.Forward()
  150.         move.turnBack()
  151.     elseif inspect.Forward(lavaArray) and bLocLava then
  152.         collectLava.Front(lavaCnt)
  153.         if bAllLava then
  154.             move.Forward()
  155.             collectAllValuables()
  156.             move.turnBack()
  157.             move.Forward()
  158.             move.turnBack()
  159.         end
  160.     end
  161.     turtle.turnRight()      -- left
  162.  
  163.     if inspect.Forward(blocksToMine) then
  164.         move.Forward()
  165.         collectAllValuables()
  166.         move.turnBack()
  167.         move.Forward()
  168.         move.turnBack()
  169.     elseif inspect.Forward(lavaArray) and bLocLava then
  170.         collectLava.Front(lavaCnt)
  171.         if bAllLava then
  172.             move.Forward()
  173.             collectAllValuables()
  174.             move.turnBack()
  175.             move.Forward()
  176.             move.turnBack()
  177.         end
  178.     end
  179.     turtle.turnRight()      -- forward
  180.  
  181.     if inspect.Up(blocksToMine) then
  182.         move.Up()
  183.         collectAllValuables()
  184.         move.Down()
  185.     elseif inspect.Up(lavaArray) and bLocLava then
  186.         collectLava.Top(lavaCnt)
  187.         if bAllLava then
  188.             move.Up()
  189.             collectAllValuables()
  190.             move.Down()
  191.         end
  192.     end
  193.  
  194.     return true
  195. end
  196.  
  197. -- places chest on top of turtle
  198. function placeChest()
  199.     for i = 1, 16, 1 do
  200.         turtle.select(i)
  201.         itemDetail = turtle.getItemDetail()
  202.         if itemDetail then
  203.             if itemDetail.name == "minecraft:chest" then
  204.                 move.Up()
  205.                 move.Up()
  206.                 move.Down()
  207.                 move.Down()
  208.                 turtle.placeUp()
  209.                 return true
  210.             end
  211.         end
  212.     end
  213.     if bLava then
  214.         if not (lavaCnt[1] == 0) then
  215.             print(tostring(lavaCnt[1]).." Lavablocks were collected/destroyed")
  216.             lavaCnt[1] = 0
  217.         end
  218.     end
  219.     return false
  220. end
  221.  
  222. -- mines one tunnel and comes back out
  223. function mineTunnel (remainingLength)
  224.     if not (remainingLength == 0) then
  225.         move.Forward()
  226.         collectAllValuables()
  227.         move.Up()
  228.         collectAllValuables()
  229.         move.Down()
  230.         mineTunnel(remainingLength - 1)
  231.         move.Forward()
  232.     else
  233.         move.turnBack()
  234.     end
  235. end
  236.  
  237. -- Digs and mines all tunnels
  238. function runTunnelMiner()
  239.     for i=1, numTunnels, 1 do
  240.         takeTurn()
  241.         mineTunnel(lenTunnel)
  242.         if placeChest() then
  243.             dropAll.Up(notDroppedBlocks)
  244.         end
  245.         takeTurn()
  246.         if not (i == numTunnels) then
  247.             move.Forward()
  248.             move.Forward()
  249.             move.Forward()
  250.         end
  251.     end
  252. end
  253.  
  254. runTunnelMiner()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement