Advertisement
Guest User

mine.lua

a guest
Dec 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.93 KB | None | 0 0
  1. local rednetWorks = false
  2. for a,b in pairs(rs.getSides()) do
  3.     if peripheral.getType(b) == "modem" then
  4.         rednet.open(b)
  5.         rednetWorks = true
  6.     end
  7. end
  8.  
  9. local depth = 0
  10.  
  11. function isJunk()
  12.     local matched = false
  13.    
  14.     if turtle.detect(stone) or turtle.detect(dirt) or turtle.detect(grass) or turtle.detect(bedrock) or turtle.detect(air) then
  15.         matched = true
  16.     end
  17.     if matched == false then
  18.         return false
  19.     else
  20.         return true
  21.     end
  22. end
  23.  
  24. function compare()
  25.     for j=1,4 do
  26.         if isJunk() == false then
  27.             turtle.dig()
  28.             rednet.send(3,"Found Ore At "..depth)
  29.         end
  30.         turtle.turnLeft()
  31.     end
  32. end
  33.  
  34. function fuel()
  35.     if turtle.getFuelLevel() <= 20 then
  36.         turtle.select(16)
  37.         turtle.refuel(1)
  38.     end
  39. end
  40. function start()
  41.     term.clear()
  42.     term.setCursorPos(1,1)
  43.     print("-------Mining Operation Beta-------")
  44.     term.write("Commence Mining Operation? (y/n):")
  45.  
  46.     local input = read()
  47.  
  48.     if input == "n" then
  49.         print("Cancelling Mining Operation")
  50.         if rednetWorks then
  51.             rednet.send(3,"Cancelling Mining Operation")
  52.             rednet.close(b)
  53.         end
  54.         sleep(1)
  55.         exit()
  56.     elseif input == "y" then
  57.         print("Commencing Mining Operation Beta")
  58.         if rednetWorks then
  59.              rednet.send(3, "Commencing Mining Operation")
  60.         end
  61.         sleep(0.5)
  62.     end
  63. end
  64.  
  65. function goDown()
  66.     fuel()
  67.     if turtle.down() then
  68.         return true
  69.     else
  70.         return false
  71.     end
  72.     depth = depth + 1
  73. end
  74.  
  75. function goUp()
  76.     fuel()
  77.     if turtle.up() then
  78.         return true
  79.     else
  80.         return false
  81.     end
  82.     depth = depth - 1
  83. end
  84.  
  85. while true do
  86.  
  87. start()
  88.  
  89. turtle.digDown()
  90. goDown()
  91. turtle.digDown()
  92. goDown()
  93. turtle.select(1)
  94. turtle.placeUp()
  95. turtle.digDown()
  96. function down()
  97. while turtle.detectDown() == false do
  98.     goDown()
  99.     compare()
  100.     turtle.digDown()
  101.     if depth % 10 == 0 then
  102.         if rednetWorks then
  103.             rednet.send(3,"At Depth "..depth)
  104.         end
  105.     end
  106. end
  107. goUp()
  108. turtle.select(15)
  109. turtle.placeDown()
  110. end
  111.  
  112. down()
  113.  
  114. if rednetWorks then
  115.     rednet.send(3, "Positioning For Next Mine")
  116.  
  117. for l = 1,5 do
  118.     goUp()
  119. end
  120. turtle.dig()
  121. fuel()
  122. turtle.forward()
  123. turtle.dig()
  124. fuel()
  125. turtle.forward()
  126. turtle.turnRight()
  127. turtle.dig()
  128. fuel()
  129. turtle.forward()
  130. turtle.turnLeft()
  131. turtle.digDown()
  132.  
  133. down()
  134.  
  135. if rednetWorks then
  136.     rednet.send(3, "Coming Up")
  137. end
  138.  
  139. while depth > 0 do
  140.     compare()
  141.     fuel()
  142.     if goUp() == false then
  143.         turtle.digUp()
  144.         goUp()
  145.     end
  146.     if depth % 10 == 0 then
  147.         if rednetWorks then
  148.             rednet.send(3, "At depth "..depth)
  149.         end
  150.     end
  151. end
  152. turtle.select(1)
  153. turtle.placeDown()
  154.  
  155. fuel()
  156. turtle.forward()
  157. turtle.forward()
  158. turtle.turnRight()
  159. turtle.forward()
  160. turtle.turnLeft()
  161. fuel()
  162.  
  163. end
  164. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement