Advertisement
tman10

Tmod1

Jul 23rd, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.38 KB | None | 0 0
  1.    
  2.     --Variable Declarations
  3.     local mainShaftDim = "3x2"
  4.     local sideShaftDim = "2x1"
  5.     local shaftFreq = "3"
  6.     local totalCost = 0
  7.     local input = ""
  8.     local length = 0
  9.     local currentPos = 1
  10.     local chestDist = 0
  11.     local doFuel = false
  12.      
  13.     --Function Declarations
  14.     function oreDetect()
  15.             --[[ This function is a WIP system for the turtle to detect ores when it
  16.             is mining and dig out the entire vein.  It will do so by comparing items
  17.             around it to specific slots in its inventory which will contain common
  18.             blocks such as smooth stone, gravel, dirt, etc.
  19.             If one of these ores is identified, then the turtle will dig out the block
  20.             and then move into the space that the block occupied and 'sense' the blocks
  21.             around it again to try and find the continuation of the vein.
  22.             Once the turtle has finished identifying the vein, it will return to it's
  23.             initial position.  This last task may either be completed by recording
  24.             movement as the turtle moves or by using a GPS wireless system and a
  25.             basic 'goto' function for the initial coordinates.
  26.             ]]
  27.     end
  28.      
  29.     function refuel()
  30.             for i=1,15,1 do
  31.                     turtle.select(i)
  32.                     turtle.refuel(turtle.getItemCount(i))
  33.             end
  34.             turtle.select(1)
  35.     end
  36.      
  37.     function mainShaft()
  38.             turtle.select(1)
  39.             for i=1,4,1 do
  40.                     while turtle.detect() == true do
  41.                             turtle.dig()
  42.                     end
  43.                     turtle.forward()
  44.                     if not turtle.detectDown() then
  45.                             turtle.placeDown()
  46.                     end
  47.                     while turtle.detectUp() do
  48.                             turtle.digUp()
  49.                     end
  50.                     turtle.turnRight()
  51.                     while turtle.detect() == true do
  52.                             turtle.dig()
  53.                     end
  54.                     turtle.forward()
  55.                     if not turtle.detectDown() then
  56.                             turtle.placeDown()
  57.                     end
  58.                     while turtle.detectUp() do
  59.                             turtle.digUp()
  60.                     end
  61.                     turtle.turnRight()
  62.                     turtle.turnRight()
  63.                     while turtle.detect() do
  64.                             turtle.dig()
  65.                     end
  66.                     turtle.forward()
  67.                     if not turtle.detectDown() then
  68.                             turtle.placeDown()
  69.                     end
  70.                     turtle.turnRight()
  71.             end
  72.             turtle.turnRight()
  73.             turtle.turnRight()
  74.             turtle.select(16)
  75.             turtle.forward()
  76.             turtle.placeUp()
  77.             turtle.turnLeft()
  78.             turtle.forward()
  79.             turtle.placeUp()
  80.             turtle.turnLeft()
  81.             turtle.forward()
  82.             turtle.turnLeft()
  83.             turtle.forward()
  84.             turtle.turnRight()
  85.     end
  86.      
  87.     function sideShaft()
  88.             turtle.select(1)
  89.             for i=0,20,1 do
  90.                     while turtle.detect() == true do
  91.                             turtle.dig()
  92.                     end
  93.                     turtle.forward()
  94.                     if turtle.detectDown() == false then
  95.                             turtle.placeDown()
  96.                     end
  97.                     while turtle.detectUp() == true do
  98.                             turtle.digUp()
  99.                     end
  100.             end
  101.             turtle.select(16)
  102.             turtle.turnRight()
  103.             turtle.turnRight()
  104.             turtle.place()
  105.             turtle.turnRight()
  106.             turtle.turnRight()
  107.             turtle.select(1)
  108.             for i=0,20,1 do
  109.                     while turtle.detect() == true do
  110.                             turtle.dig()
  111.                     end
  112.                     turtle.forward()
  113.                     if turtle.detectDown() == false then
  114.                             turtle.placeDown()
  115.                     end
  116.                     while turtle.detectUp() == true do
  117.                             turtle.digUp()
  118.                     end
  119.             end
  120.             turtle.turnRight()
  121.             turtle.turnRight()
  122.             turtle.select(16)
  123.             turtle.place()
  124.             turtle.up()
  125.             for i=1,23,1 do
  126.                     while turtle.detect() do
  127.                             turtle.dig()
  128.                     end
  129.                     turtle.forward()
  130.             end
  131.             turtle.down()
  132.     end
  133.      
  134.     function deposit()
  135.             for i=1, (chestDist), 1 do
  136.                     turtle.forward()
  137.             end
  138.             for i=1, 15, 1 do
  139.                     turtle.select(i)
  140.                     turtle.drop()
  141.             end
  142.             refuel()
  143.             if turtle.getItemCount(16) < 6 then
  144.                     stopMining()
  145.             end
  146.             if turtle.getFuelLevel() < (108 + 2 * chestDist) then
  147.                     stopMining()
  148.             end
  149.             turtle.turnRight()
  150.             turtle.turnRight()
  151.             for i=1, (chestDist), 1 do
  152.                     turtle.forward()
  153.             end
  154.      
  155.     end
  156.      
  157.     function stopMining()
  158.             if turtle.getFuelLevel() < (108 + 2 * chestDist) then
  159.                     print("I am low on fuel.")
  160.                     local remainFuel = 0
  161.                     for i=currentPos, length, 1 do
  162.                             remainFuel = (108 + 2 * (4 * i + 1))
  163.                     end
  164.                     print("I need "..remainFuel.." to finish.")
  165.                     print("That's "..(remainFuel/80).." coal or "..(remainFuel/1000).." lava.")
  166.                     print("Type (cont) to refuel & continue mining.")
  167.                     doFuel = true
  168.             end
  169.             if turtle.getItemCount(16) < 6 then
  170.                     print("I am low on torches.")
  171.                     print("Place more in slot 16...")
  172.                     while turtle.getItemCount(16) < 6 do
  173.                             sleep(1)
  174.                     end
  175.                     print("Type (cont) to continue mining.")
  176.                     doFuel = false
  177.             end
  178.             local cont = false
  179.             while cont == false do
  180.                     --[[if rs.getInput("right") == true then --Flickers RS torch on right of chest
  181.                             rs.setOutput("right", false)
  182.                     else
  183.                             rs.setOutput("right", true)
  184.                     end]]
  185.                     local input = io.read()
  186.                     if input == "cont" then
  187.                             if doFuel then
  188.                                     refuel()
  189.                             end
  190.                             turtle.turnRight()
  191.                             turtle.turnRight()
  192.                             for i=1, chestDist, 1 do
  193.                                     turtle.forward()
  194.                             end
  195.                             currentPos = currentPos + 1
  196.                             run()
  197.                     else
  198.                             print("Incorrect input.")
  199.                     end
  200.             end
  201.     end
  202.      
  203.     function run()
  204.             while currentPos < length do
  205.                     chestDist = (currentPos * 4 + 4)
  206.                     mainShaft()
  207.                     turtle.turnLeft()
  208.                     sideShaft()
  209.                     sideShaft()
  210.                     turtle.turnLeft()
  211.                     deposit()
  212.                     currentPos = currentPos + 1
  213.             end
  214.     end
  215.      
  216.     function idle()
  217.             print("Mining Complete")
  218.             print("Type (end) to terminate program")
  219.             local input = "null"
  220.             rs.setOutput("right", true)
  221.             while input ~= "end" do
  222.                     input = io.read()
  223.             end
  224.             rs.setOutput("right", false)
  225.     end
  226.      
  227.     --Execution
  228.     print("----------------------------------")
  229.     print("Branch Mine Turtle Activated")
  230.     print("----------------------------------")
  231.     sleep(2)
  232.     print("Beginning Mine w. Following Specs:")
  233.     print("Main Shaft: "..mainShaftDim)
  234.     print("Side Shafts: "..sideShaftDim)
  235.     print("Branch Frequency: "..shaftFreq)
  236.     print("----------------------------------")
  237.      
  238.     print("Number of Shafts:")
  239.     length = tonumber(read())
  240.     currentPos = 0
  241.     print("----------------------------------")
  242.     for x = length, 0, -1 do
  243.             totalCost = totalCost + (108 + 2 * (4 * x + 1))
  244.     end
  245.     print("Current Fuel: "..turtle.getFuelLevel())
  246.     print("Fuel cost: "..totalCost)
  247.     print("Coal cost: "..(totalCost/80))
  248.     print("Lava cost: "..(totalCost/1000))
  249.     sleep(2)
  250.     print("----------------------------------")
  251.     print("Would you like to refuel now (y/n)?")
  252.     input = io.read()
  253.     if input == "y" then
  254.             refuel()
  255.             print("Refueled.")
  256.     else
  257.             print("Did not refuel.")
  258.     end
  259.     print("Turtle now has "..turtle.getFuelLevel().." fuel.")
  260.     print("----------------------------------")
  261.     print("Now beginning mining!")
  262.      
  263.     run()
  264.     turtle.turnRight()
  265.     turtle.turnRight()
  266.     for i=1, chestDist, 1 do
  267.             turtle.forward()
  268.     end
  269.     idle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement