Advertisement
YannMarcotte

Advanced Branch Mining Turtle (second/over)

Mar 26th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.08 KB | None | 0 0
  1. --Variable Declarations
  2. local mainShaftDim = "2x2"
  3. local sideShaftDim = "2x1"
  4. local shaftFreq = "3"
  5. local totalCost = 0
  6. local input = ""
  7. local length = 0
  8. local currentPos = 1
  9. local chestDist = 0
  10. local doFuel = false
  11.  
  12.  
  13.  
  14. --Function Declarations
  15. -- Refuels the turtle with slots 1-15
  16. function refuel()
  17.     for i=1,15,1 do
  18.         turtle.select(i)
  19.         turtle.refuel(turtle.getItemCount(i))
  20.     end
  21.     turtle.select(1)
  22. end
  23.  
  24. function dig()
  25.     turtle.dig()
  26. end
  27.  
  28. -- Mines the main 2x2 shaft of the system
  29. function mainShaft()
  30.     turtle.select(1)
  31.     for i=1,4,1 do
  32.         while turtle.detect() == true do
  33.             dig()
  34.         end
  35.         turtle.forward()
  36.         while turtle.detectUp() do
  37.             turtle.digUp()
  38.         end
  39.         turtle.turnRight()
  40.         while turtle.detect() == true do
  41.             dig()
  42.         end
  43.         turtle.forward()
  44.         while turtle.detectUp() do
  45.             turtle.digUp()
  46.         end
  47.         turtle.turnRight()
  48.         turtle.turnRight()
  49.         while turtle.detect() do
  50.             dig()
  51.         end
  52.         turtle.forward()
  53.         turtle.turnRight()
  54.     end
  55.     turtle.turnRight()
  56.     turtle.turnRight()
  57.     turtle.forward()
  58.     turtle.turnLeft()
  59.     turtle.forward()
  60.     turtle.turnLeft()
  61.     turtle.forward()
  62.     turtle.turnLeft()
  63.     turtle.forward()
  64.     turtle.turnRight()
  65. end
  66.  
  67. -- Mines a 2x1 side shaft off of the main shaft of the system
  68. function sideShaft()
  69.     turtle.select(1)
  70.     for i=0,10,1 do
  71.         while turtle.detect() == true do
  72.             dig()
  73.         end
  74.         turtle.forward()
  75.         while turtle.detectUp() == true do
  76.             turtle.digUp()
  77.         end
  78.     end
  79.     turtle.turnRight()
  80.     turtle.turnRight()
  81.     turtle.turnRight()
  82.     turtle.turnRight()
  83.     turtle.select(1)
  84.     for i=0,10,1 do
  85.         while turtle.detect() == true do
  86.             dig()
  87.         end
  88.         turtle.forward()
  89.         while turtle.detectUp() == true do
  90.             turtle.digUp()
  91.         end
  92.     end
  93.     turtle.turnRight()
  94.     turtle.turnRight()
  95.     turtle.up()
  96.     for i=1,23,1 do
  97.         while turtle.detect() do
  98.             dig()
  99.         end
  100.         turtle.forward()
  101.     end
  102.     turtle.down()
  103. end
  104.  
  105.  
  106. -- Places all the goodies in the designated chest
  107. function deposit()
  108.     for i=1, (chestDist), 1 do
  109.         turtle.forward()
  110.     end
  111.     for i=1, 11, 1 do
  112.         turtle.select(i)
  113.         turtle.drop()
  114.     end
  115.     refuel()
  116.     if turtle.getFuelLevel() < (108 + 2 * chestDist) then
  117.         stopMining()
  118.     end
  119.     turtle.turnRight()
  120.     turtle.turnRight()
  121.     for i=1, (chestDist), 1 do
  122.         turtle.forward()
  123.     end
  124.  
  125. end
  126.  
  127. -- Stops mining for some reason or another
  128. function stopMining()
  129.     if turtle.getFuelLevel() < (108 + 2 * chestDist) then
  130.         print("I am low on fuel.")
  131.         local remainFuel = 0
  132.         for i=currentPos, length, 1 do
  133.             remainFuel = (108 + 2 * (4 * i + 1))
  134.         end
  135.         print("I need "..remainFuel.." to finish.")
  136.         print("That's "..(remainFuel/80).." coal or "..(remainFuel/1000).." lava.")
  137.         print("Type (cont) to refuel & continue mining.")
  138.         doFuel = true
  139.     end
  140.     if turtle.getItemCount(16) < 6 then
  141.         print("I am low on torches.")
  142.         print("Place more in slot 9...")
  143.         while turtle.getItemCount(16) < 6 do
  144.             sleep(1)
  145.         end
  146.         print("Type (cont) to continue mining.")
  147.         doFuel = false
  148.     end
  149.     local cont = false
  150.     while cont == false do
  151.         --[[
  152.         if rs.getInput("right") == true then --Flickers RS torch on right of chest
  153.             rs.setOutput("right", false)
  154.         else
  155.             rs.setOutput("right", true)
  156.         end
  157.         ]]
  158.         local input = io.read()
  159.         if input == "cont" then
  160.  
  161.             if doFuel then
  162.                 refuel()
  163.             end
  164.  
  165.             turtle.turnRight()
  166.             turtle.turnRight()
  167.             for i=1, chestDist, 1 do
  168.                 turtle.forward()
  169.             end
  170.             currentPos = currentPos + 1
  171.             run()
  172.         else
  173.             print("Incorrect input.")
  174.         end
  175.     end
  176. end
  177.  
  178. -- Run the mining loop
  179. function run()
  180.     while currentPos < length do
  181.         chestDist = (currentPos * 4 + 4)
  182.         mainShaft()
  183.         turtle.turnLeft()
  184.         sideShaft()
  185.         sideShaft()
  186.         turtle.turnLeft()
  187.         deposit()
  188.         currentPos = currentPos + 1
  189.     end
  190. end
  191.  
  192. -- Alert system for user, using the redstone torch
  193. function idle()
  194.     print("Mining Complete")
  195.     print("Type (end) to terminate program")
  196.     local input = "null"
  197.     rs.setOutput("right", true)
  198.     while input ~= "end" do
  199.         input = io.read()
  200.     end
  201.     rs.setOutput("right", false)
  202. end
  203.  
  204. --Execution
  205. print("----------------------------------")
  206. print("Branch Mine Turtle Activated")
  207. print("----------------------------------")
  208. sleep(2)
  209. print("Beginning Mine w. Following Specs:")
  210. print("Main Shaft: "..mainShaftDim)
  211. print("Side Shafts: "..sideShaftDim)
  212. print("Branch Frequency: "..shaftFreq)
  213. print("----------------------------------")
  214.  
  215. print("Number of Shafts:")
  216. length = tonumber(read())
  217. currentPos = 0
  218. print("----------------------------------")
  219.  
  220. for x = length, 0, -1 do
  221.     totalCost = totalCost + (108 + 2 * (4 * x + 1))
  222. end
  223.  
  224.  
  225. print("Current Fuel: "..turtle.getFuelLevel())
  226. print("Fuel cost: "..totalCost)
  227. print("Coal cost: "..(totalCost/80))
  228. print("Lava cost: "..(totalCost/1000))
  229. sleep(2)
  230. print("----------------------------------")
  231. print("Would you like to refuel now (y/n)?")
  232. input = io.read()
  233. if input == "y" then
  234.     refuel()
  235.     print("Refueled.")
  236. else
  237.     print("Did not refuel.")
  238. end
  239. print("Turtle now has "..turtle.getFuelLevel().." fuel.")
  240. print("----------------------------------")
  241.  
  242. print("Now beginning mining!")
  243.  
  244. run()
  245. turtle.turnRight()
  246. turtle.turnRight()
  247. for i=1, chestDist, 1 do
  248.     turtle.forward()
  249. end
  250. idle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement