Advertisement
JMANN2400

Branch Miner

Jul 31st, 2017
512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.08 KB | None | 0 0
  1.  
  2.  
  3.  
  4. x = 0
  5.  
  6. y = 0
  7.  
  8. z = 0
  9.  
  10. checks = 0
  11.  
  12. chestsDropped = 0
  13.  
  14. mined = 0
  15.  
  16. function getCount()
  17.     count = 0
  18.     for i = 3,15,1 do
  19.         count = count + turtle.getItemCount(i)
  20.     end
  21.     return count
  22. end
  23.  
  24. function deposit()
  25.     turtle.select(1)
  26.     turtle.turnLeft()
  27.     turtle.dig()
  28.     turtle.digUp()
  29.     turtle.up()
  30.     turtle.dig()
  31.     turtle.down()
  32.     turtle.place()
  33.     chestsDropped = chestsDropped + 1
  34.     for i = 3,15,1 do
  35.         turtle.select(i)
  36.         turtle.drop()
  37.     end
  38.     turtle.turnRight()
  39. end
  40.  
  41. function checkWanted()
  42.     success, data = turtle.inspect()
  43.     if data.name == "minecraft:diamond_ore" or data.name == "minecraft:redstone_ore" or data.name == "minecraft:iron_ore" or data.name == "minecraft:coal_ore" or data.name == "minecraft:gold_ore" or data.name == "minecraft:lapis_ore" then
  44.         print("I found ", data.name, "!")
  45.         return true
  46.     end
  47. end
  48.  
  49. function checkWantedUp()
  50.     success, data = turtle.inspectUp()
  51.     if data.name == "minecraft:diamond_ore" or data.name == "minecraft:redstone_ore" or data.name == "minecraft:iron_ore" or data.name == "minecraft:coal_ore" or data.name == "minecraft:gold_ore" or data.name == "minecraft:lapis_ore" then
  52.         print("I found ", data.name, "!")
  53.         return true
  54.     end
  55. end
  56.  
  57. function checkWantedDown()
  58.     success, data = turtle.inspectDown()
  59.     if data.name == "minecraft:diamond_ore" or data.name == "minecraft:redstone_ore" or data.name == "minecraft:iron_ore" or data.name == "minecraft:coal_ore" or data.name == "minecraft:gold_ore" or data.name == "minecraft:lapis_ore" then
  60.         print("I found ", data.name, "!")
  61.         return true
  62.     end
  63. end
  64.  
  65. function checkLavaCheck()
  66.     success, data = turtle.inspect()
  67.     if data.name == "minecraft:lava" or data.name == "minecraft:flowing_lava" then
  68.         return true
  69.     end
  70. end
  71.  
  72. function checkLavaCheckUp()
  73.     success, data = turtle.inspectUp()
  74.     if data.name == "minecraft:lava" or data.name == "minecraft:flowing_lava" then
  75.         if y == h - 1 then
  76.             return true
  77.         end
  78.     end
  79. end
  80.  
  81. function checkLavaCheckDown()
  82.     success, data = turtle.inspectDown()
  83.     if data.name == "minecraft:lava" or data.name == "minecraft:flowing_lava" then
  84.         if y == 0 then
  85.             return true
  86.         end
  87.     end
  88. end
  89.  
  90. function check()
  91.     print("I'm gonna check for some ore and lava!")
  92.     print("Checking in front of me!")
  93.     if checkWanted() then
  94.         while turtle.detect() do
  95.             turtle.dig()
  96.         end
  97.         turtle.forward()
  98.         checks = checks + 1
  99.         check()
  100.         turtle.back()
  101.         checks = checks - 1
  102.     end
  103.     if checkLavaCheck() then
  104.         print("I found some in front of me!")
  105.         turtle.select(16)
  106.         turtle.place()
  107.         turtle.refuel()
  108.         print("My fuel level is at ", turtle.getFuelLevel(), ".")
  109.     end
  110.     print("Checking to my left!")
  111.     turtle.turnLeft()
  112.     if checkWanted() then
  113.         while turtle.detect() do
  114.             turtle.dig()
  115.         end
  116.         turtle.forward()
  117.         checks = checks + 1
  118.         check()
  119.         turtle.back()
  120.         checks = checks - 1
  121.     end
  122.     if checkLavaCheck() then
  123.         print("I found some to my left!")
  124.         turtle.select(16)
  125.         turtle.place()
  126.         turtle.refuel()
  127.         print("My fuel level is at ", turtle.getFuelLevel(), ".")
  128.         if checks == 0 then
  129.             turtle.select(2)
  130.             turtle.place()
  131.         end
  132.     end
  133.     print("Checking to my right!")
  134.     turtle.turnRight()
  135.     turtle.turnRight()
  136.     if checkWanted() then
  137.         while turtle.detect() do
  138.             turtle.dig()
  139.         end
  140.         turtle.forward()
  141.         checks = checks + 1
  142.         check()
  143.         turtle.back()
  144.         checks = checks - 1
  145.     end
  146.     if checkLavaCheck() then
  147.         print("I found some to my right!")
  148.         turtle.select(16)
  149.         turtle.place()
  150.         turtle.refuel()
  151.         print("My fuel level is at ", turtle.getFuelLevel(), ".")
  152.         if checks == 0 then
  153.             turtle.select(2)
  154.             turtle.place()
  155.         end
  156.     end
  157.     turtle.turnLeft()
  158.     print("Checking above me!")
  159.     if checkWantedUp() then
  160.         turtle.digUp()
  161.         turtle.turnLeft()
  162.         turtle.turnLeft()
  163.         turtle.turnLeft()
  164.         turtle.turnLeft()
  165.         turtle.up()
  166.         checks = checks + 1
  167.         check()
  168.         turtle.down()
  169.         checks = checks - 1
  170.     end
  171.     if checkLavaCheckUp() then
  172.         print("I found some above me!")
  173.         turtle.select(16)
  174.         turtle.placeUp()
  175.         turtle.refuel()
  176.         print("My fuel level is at ", turtle.getFuelLevel(), ".")
  177.         if checks == 0 then
  178.             turtle.select(2)
  179.             turtle.placeUp()
  180.         end
  181.     end
  182.     print("Checking below me!")
  183.     if checkWantedDown() then
  184.         turtle.digDown()
  185.         turtle.down()
  186.         checks = checks + 1
  187.         check()
  188.         turtle.up()
  189.         checks = checks - 1
  190.     end
  191.     if checkLavaCheckDown() then
  192.         print("I found some below me!")
  193.         turtle.select(16)
  194.         turtle.placeDown()
  195.         turtle.refuel()
  196.         print("My fuel level is at ", turtle.getFuelLevel(), ".")
  197.         if checks == 0 then
  198.             turtle.select(2)
  199.             turtle.placeDown()
  200.         end
  201.     end
  202. end
  203.  
  204. function mine()
  205.     turtle.select(15)
  206.     turtle.refuel()
  207.     turtle.select(1)
  208.     print("My fuel level is at ", turtle.getFuelLevel(), ".")
  209.     print("I have ", getCount(), " items.")
  210.    
  211.     if turtle.detect() == true then
  212.         turtle.dig()
  213.     end
  214.     for a = 1, h-1, 1 do
  215.         if turtle.detectUp() then
  216.             turtle.digUp()
  217.         end
  218.         if turtle.up() then
  219.             y = y + 1
  220.         end
  221.         if turtle.detect() == true then
  222.             turtle.dig()
  223.         end
  224.     end
  225.     check()
  226.     while y > 0 do
  227.         if turtle.down() then
  228.             y = y - 1
  229.         end
  230.         check()
  231.     end
  232.     if turtle.detectDown() == false then
  233.         turtle.select(2)
  234.         turtle.placeDown()
  235.     end
  236.     while turtle.detect() do
  237.         turtle.dig()
  238.     end
  239.     turtle.forward()
  240.     z = z + 1
  241.     if getCount() > 320 then
  242.         deposit()
  243.     end
  244.     if z + h * 4 > turtle.getFuelLevel() then
  245.         while z > 0 do
  246.             turtle.back()
  247.             z = z - 1
  248.             print("Low on fuel!")
  249.             print("Fuel level = ", turtle.getFuelLevel())
  250.         end
  251.         print("Please insert more fuel in slot 15!")
  252.         read()
  253.         turtle.select(15)
  254.         turtle.refuel()
  255.         turtle.select(1)
  256.     end
  257.     if z > 0 then
  258.         print("I'm ", z,"/", l, " of the way done.")
  259.     end
  260. end
  261.  
  262. function sideMine()
  263.     turtle.select(15)
  264.     turtle.refuel()
  265.     turtle.select(1)
  266.     print("My fuel level is at ", turtle.getFuelLevel(), ".")
  267.     print("I have ", getCount(), " items.")
  268.    
  269.     if turtle.detect() == true then
  270.         turtle.dig()
  271.     end
  272.     for a = 1, h-1, 1 do
  273.         if turtle.detectUp() then
  274.             turtle.digUp()
  275.         end
  276.         if turtle.up() then
  277.             y = y + 1
  278.         end
  279.         if turtle.detect() == true then
  280.             turtle.dig()
  281.         end
  282.     end
  283.     check()
  284.     while y > 0 do
  285.         if turtle.down() then
  286.             y = y - 1
  287.         end
  288.         check()
  289.     end
  290.     if turtle.detectDown() == false then
  291.         turtle.select(2)
  292.         turtle.placeDown()
  293.     end
  294.     while turtle.detect() do
  295.         turtle.dig()
  296.     end
  297.     turtle.forward()
  298.     x = x + 1
  299.     if getCount() > 320 then
  300.         deposit()
  301.     end
  302. end
  303.  
  304.  
  305.  
  306. print("+-------------------------------------+")
  307. print("| Branch Mine                         |")
  308. print("+-------------------------------------+")
  309. print("| Slot 15: Fuel                       |")
  310. print("| Slot 16: Empty Bucket               |")
  311. print("| Slot 1: Chests                      |")
  312. print("| Slot 2: Blocks                      |")
  313. print("+-------------------------------------+")
  314. print("| Place turtle at start of mine.      |")
  315. print("| Insert fuel. Specify height and     |")
  316. print("| length. Press enter to start.       |")
  317. print("+-------------------------------------+")
  318. read()
  319. print("+-------------------------------------+")
  320. print("| Mine length = ?                     |")
  321. print("+-------------------------------------+")
  322. l = tonumber(read())
  323. print("+-------------------------------------+")
  324. print("| Mine height = ? (>=2)               |")
  325. print("+-------------------------------------+")
  326. h = tonumber(read())
  327. print("+-------------------------------------+")
  328. print("| Amount of shafts = ?                |")
  329. print("+-------------------------------------+")
  330. m = tonumber(read())
  331.  
  332. while z < l do
  333.     mine()
  334. end
  335. turtle.turnLeft()
  336. turtle.turnLeft()
  337. while z > 0 do
  338.     turtle.dig()
  339.     turtle.forward()
  340.     z = z - 1
  341. end
  342. turtle.turnLeft()
  343. mined = mined + 1
  344.  
  345. while mined < m do
  346.     sideMine()
  347.     sideMine()
  348.     sideMine()
  349.     turtle.turnLeft()
  350.     while z < l do
  351.         mine()
  352.     end
  353.     turtle.turnLeft()
  354.     turtle.turnLeft()
  355.     while z > 0 do
  356.         turtle.dig()
  357.         turtle.forward()
  358.         z = z - 1
  359.     end
  360.     turtle.turnLeft()
  361.     mined = mined + 1
  362. end
  363. turtle.turnLeft()
  364. turtle.turnLeft()
  365. while x > 0 do
  366.     turtle.dig()
  367.     turtle.forward()
  368.     x = x - 1
  369. end
  370. turtle.turnRight()
  371.  
  372. print("I put down ", chestsDropped, " chests for you.")
  373. print("My fuel level is at ", turtle.getFuelLevel(), ".")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement