Advertisement
gridcaster

Tunnel

Jun 3rd, 2021
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. --[[
  2. Version
  3. 0.06 - 5/24/2021
  4. Changelog
  5. 0.01 - 1/21/2017
  6. 0.02 - 1/26/2017 Bug Fixing
  7. 0.03 - Function Renaming and Fix fuelcode
  8. 0.04 - Worng Variables Fix
  9. 0.05 - English is understandable
  10. 0.06 5/24/2021 - Code Formatting
  11. ]]
  12.  
  13. -- Locals Variables
  14. local noFuelNeeded = 0 -- Check if turtle is using no fuel config
  15. local fuelSlot1 = 0 -- Fuel Slot 1
  16. local fuelSlot2 = 0 -- Fuel Slot 2
  17. local chest = 0 -- Chest Slot 3
  18. local distance = 0 -- Distance will dig
  19. local distanceCount = 0 -- Count the distance
  20. local errorItems = 0
  21.  
  22. -- itemCheck
  23. local function itemCount()
  24. fuelSlot1 = turtle.getItemCount(1)
  25. fuelSlot2 = turtle.getItemCount(2)
  26. chest = turtle.getItemCount(3)
  27. errorItems = 0
  28. end
  29.  
  30. -- Checking
  31. local function check()
  32. if noFuelNeed == 0 then
  33. if fuelSlot1 == 0 then
  34. print("Turtle has no fuel")
  35. print("Put fuel in First and Second slot")
  36. errorItems = 1
  37. else
  38. itemData = turtle.getItemDetail(1)
  39. if itemData.name == "minecraft:chest" then
  40. print("Worng Slot Please Move to 3rd slot")
  41. errorItems = 1
  42. else
  43. print("Turtle has Fuel in Slot 1")
  44. end
  45. end
  46. if fuelSlot2 == 0 then
  47. print("Turtle has no extra fuel if this is a short job its ok")
  48. else
  49. itemData = turtle.getItemDetail(2)
  50. if itemData.name == "minecraft:chest" then
  51. print("Worng Slot Please Move to 3rd slot")
  52. errorItems = 1
  53. else
  54. print("Turtle has Fuel Slot 2")
  55. end
  56. end
  57. end
  58. if chest == 0 then
  59. print("No chest in Turtle")
  60. print("Put chest in Thrid slot")
  61. errorItems = 1
  62. end
  63. if errorItems == 1 then
  64. print("Items are missing please try again")
  65. print("Turtle will recheck in 5 sec")
  66. end
  67. end
  68.  
  69. -- Refuel
  70. local function refuel()
  71. if noFuelNeeded == 0 then
  72. repeat
  73. if turtle.getFuelLevel() < 120 then
  74. if fuelSlot1 > 0 then
  75. turtle.select(1)
  76. turtle.refuel(1)
  77. fuelSlot1 = fuelSlot1 - 1
  78. elseif fuelSlot2 > 0 then
  79. turtle.select(2)
  80. turtle.refuel(1)
  81. fuelSlot2 = fuelSlot2 - 1
  82. else
  83. print("Out Of Fuel")
  84. os.shutdown()
  85. end
  86. end
  87. until turtle.getFuelLevel() >= 120
  88. end
  89. end
  90.  
  91. local function dig()
  92. turtle.dig()
  93. turtle.forward()
  94. turtle.turnLeft()
  95. turtle.dig()
  96. turtle.digUp()
  97. turtle.up()
  98. turtle.dig()
  99. turtle.digUp()
  100. turtle.up()
  101. turtle.dig()
  102. turtle.turnRight()
  103. turtle.turnRight()
  104. turtle.dig()
  105. turtle.down()
  106. turtle.dig()
  107. turtle.down()
  108. turtle.dig()
  109. turtle.turnLeft()
  110. end
  111.  
  112. local function chestDump()
  113. if turtle.getItemCount(16) > 0 then -- If slot 16 in turtle has item slot 4 to 16 will go to chest
  114. if Chest ~= 0 then
  115. turtle.select(3)
  116. turtle.digDown()
  117. turtle.placeDown()
  118. for slot = 4, 16 do
  119. turtle.select(slot)
  120. sleep(0.6) -- Small fix for slow pc because i had people problem with this
  121. turtle.dropDown()
  122. end
  123. turtle.select(4)
  124. else
  125. print("Out Of Chest")
  126. os.shutdown()
  127. end
  128. end
  129. end
  130.  
  131. local function tunnel()
  132. repeat
  133. refuel()
  134. dig()
  135. chestDump()
  136. distanceCount = distanceCount + 1
  137. until distance == distanceCount
  138. end
  139.  
  140. local function start()
  141. print("Welcome To John's Tunnel Program")
  142. print("This program creats a 3x3 tunnel")
  143. print("Please Input Your Fuel In Slot 1 and Slot 2(Optional) and Chest in Slot 3")
  144. print("Please Input The Lenght Of The Tunnel")
  145. distance = tonumber(read())
  146. print("Turtle Will Dig " .. distance .. " Long")
  147. if turtle.getFuelLevel() == "unlimited" then -- just check if config of fuel is to unlimited
  148. noFuelNeeded = 1
  149. end
  150. repeat
  151. itemCount()
  152. check()
  153. sleep(5)
  154. until errorItems == 0
  155. tunnel()
  156. end
  157.  
  158. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement