Advertisement
dapiedude_

CC Mining Turtle - Room Excavation

Apr 27th, 2024 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. local version = 0.3
  2.  
  3. -- Constants for the update process
  4. local pastebinCode = "gQV6Jvhv" -- Replace with your actual Pastebin code
  5. local scriptName = "jakeExcavate"
  6.  
  7. -- Function to download and update from Pastebin
  8. function updateFromPastebin()
  9. local response = http.get("https://pastebin.com/raw/" .. pastebinCode)
  10. if response then
  11. local scriptContent = response.readAll()
  12. response.close()
  13.  
  14. local file = fs.open(scriptName, "w")
  15. file.write(scriptContent)
  16. file.close()
  17.  
  18. print(scriptName.. " - Update downloaded. Restarting script...")
  19. os.sleep(1) -- Short pause before reboot
  20. os.reboot()
  21. else
  22. print("Failed to check for updates.")
  23. end
  24. end
  25.  
  26. -- Function to check for new updates and apply them
  27. function checkForUpdates()
  28. local response = http.get("https://pastebin.com/raw/" .. pastebinCode)
  29. if response then
  30. local scriptContent = response.readAll()
  31. response.close()
  32.  
  33. -- Check if the first line in the updated file contains a new version number
  34. local remoteVersion = tonumber(string.match(scriptContent, "%-%- Version: (%d+%.%d+)"))
  35. if remoteVersion and remoteVersion > version then
  36. print(scriptName.. " - New version found: " .. remoteVersion)
  37. updateFromPastebin()
  38. else
  39. print(scriptName.. " - Running the latest version.")
  40. end
  41. else
  42. print("Failed to connect to Pastebin for update check.")
  43. end
  44. end
  45.  
  46. -- Main script execution
  47. local args = {...} -- Capture command-line arguments
  48.  
  49. if #args > 0 and args[1] == "-update" then
  50. print("Update flag detected. Checking for updates...")
  51. checkForUpdates()
  52. return -- Exit after updating
  53. end
  54.  
  55. -- THE MAIN FUNCTION --
  56.  
  57. -- Prompt for dimensions
  58. print("Enter the length:")
  59. local length = tonumber(read())
  60. print("Enter the width:")
  61. local width = tonumber(read())
  62. print("Enter the depth:")
  63. local depth = tonumber(read())
  64.  
  65. -- Function to check and mine block
  66. function mineBlock()
  67. turtle.dig()
  68. if turtle.detectUp() then
  69. turtle.digUp()
  70. end
  71. if turtle.detectDown() then
  72. turtle.digDown()
  73. end
  74. end
  75.  
  76. -- Function to handle the mining in one layer
  77. function mineLayer()
  78. for w = 1, width do
  79. for l = 1, length - 1 do
  80. mineBlock()
  81. turtle.forward()
  82. end
  83. if w < width then
  84. mineBlock()
  85. if w % 2 == 1 then
  86. turtle.turnLeft() -- Turning left instead of right
  87. turtle.forward()
  88. turtle.turnLeft()
  89. else
  90. turtle.turnRight() -- Adjusting to ensure proper alignment
  91. turtle.forward()
  92. turtle.turnRight()
  93. end
  94. end
  95. end
  96. end
  97.  
  98. -- Main mining function
  99. function mainMining()
  100. for d = 1, depth do
  101. mineLayer()
  102. if d < depth then
  103. if d % 2 == 1 then -- Adjust turn based on odd/even layer
  104. turtle.turnLeft() -- Adjusting for leftward movement
  105. else
  106. turtle.turnRight()
  107. end
  108. turtle.down() -- Move down to next layer
  109. if (d < depth) then
  110. if d % 2 == 1 then
  111. turtle.turnLeft() -- Continue leftward movement on next layer
  112. else
  113. turtle.turnRight()
  114. end
  115. end
  116. end
  117. end
  118. end
  119.  
  120. -- Start the mining operation
  121. mainMining()
  122. print("Mining complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement