posicat

/digtunnel

Sep 21st, 2024 (edited)
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --File: /digtunnel
  2.  
  3. local moves = dofile("/cattech/moves.lua")
  4. local lists = dofile("/cattech/lists.lua")
  5.  
  6. dofile("/cattech/common.lua")
  7. dofile("/cattech/file.lua")
  8. dofile("/cattech/comms.lua")
  9.  
  10. local torchCounter = 7;
  11. local redstoneTorchCounter = 1;
  12.  
  13. function checkTorch()
  14. torchCounter = torchCounter +1
  15.  
  16. if (torchCounter > 7) then
  17. log("info","placing Torch!")
  18. moves.placeLight(2)
  19. torchCounter = 0
  20. end
  21. end
  22.  
  23. function checkRedstoneTorch()
  24. redstoneTorchCounter = redstoneTorchCounter +1
  25.  
  26. if (redstoneTorchCounter > 4) then
  27. log("info","placing Redstone Torch!")
  28. moves.up()
  29. moves.turnLeft()
  30. moves.forward()
  31. local placeItem = selectTurtleItemByList(lists.redstoneMarker)
  32. if placeItem ~= nil then
  33. turtle.placeDown(placeItem)
  34. end
  35. moves.turnRight()
  36. moves.turnRight()
  37. moves.forward()
  38. moves.forward()
  39. local placeItem = selectTurtleItemByList(lists.redstoneMarker)
  40. if placeItem ~= nil then
  41. turtle.placeDown(placeItem)
  42. end
  43. moves.turnLeft()
  44. moves.turnLeft()
  45. moves.forward()
  46. moves.turnRight()
  47. moves.down()
  48.  
  49. redstoneTorchCounter = 0
  50. end
  51. end
  52.  
  53. config = loadConfigAndDefaults()
  54.  
  55. if #arg >= 1 then
  56. config["maxSteps"] = tonumber(arg[1])
  57. if #arg >= 2 then
  58. config["pathDirection"] = arg[2]
  59. end
  60. else
  61. local continue = getContinue("digtunnel")
  62. if continue ~= nil then
  63. log("info","Continuing remaining: ",continue)
  64. config["maxSteps"] = continue
  65. end
  66. end
  67.  
  68. displayHash(config)
  69. local haveRednet = initializeRednetModem()
  70.  
  71. log("info","Going " .. config["pathDirection"] .. " " .. config["maxSteps"] .. " blocks")
  72.  
  73. if (config["pathDirection"] == "mineshaft") then
  74. config["pathDirection"] = "level"
  75. end
  76.  
  77. local spaces = 0
  78. while spaces < config["maxSteps"] do
  79. refuelIfNeeded(30)
  80. if haveRednet then
  81. chunkload()
  82. end
  83.  
  84. if (config["pathDirection"] == "down") then
  85. -- Starts 1 above first step
  86. moves.down()
  87.  
  88. moves.digTunnelSlice(tonumber(config["stairHeight"]))
  89. if config["safeTunnel"] == "yes" then
  90. sleep(1)
  91. moves.secureTunnelSlice(tonumber(config["stairHeight"]))
  92. end
  93. checkTorch()
  94.  
  95. moves.forward()
  96. end
  97.  
  98. if (config["pathDirection"] == "up") then
  99. -- Starts on first step.
  100. moves.digTunnelSlice(tonumber(config["stairHeight"]))
  101. if config["safeTunnel"] == "yes" then
  102. sleep(1)
  103. moves.secureTunnelSlice(tonumber(config["stairHeight"]))
  104. end
  105. checkTorch()
  106.  
  107. moves.up()
  108. moves.forward()
  109. end
  110.  
  111. if (config["pathDirection"] == "level") then
  112. -- Starts the ground
  113. moves.digTunnelSlice(tonumber(config["tunnelHeight"]))
  114.  
  115. if config["safeTunnel"] == "yes" then
  116. sleep(1)
  117. moves.secureTunnelSlice(tonumber(config["tunnelHeight"]))
  118. end
  119.  
  120. checkTorch()
  121. -- Mineshaft mode, place redstone torches every 4 spots to indicate branch locations.
  122. checkRedstoneTorch()
  123.  
  124. moves.forward()
  125. end
  126.  
  127. local remaining = config["maxSteps"] - spaces
  128. updateLine(remaining.."/"..config["maxSteps"])
  129.  
  130. local inv = scanInventory()
  131.  
  132. if (inv.empty == 0) then
  133. dropCommonItems(inv)
  134. end
  135.  
  136. spaces = spaces + 1
  137. updateContinue("digtunnel",remaining)
  138. end
  139.  
  140. updateContinue("digtunnel",nil)
  141.  
Advertisement
Add Comment
Please, Sign In to add comment