Advertisement
JMANN2400

Synchronized Branch Miner

Aug 7th, 2017
506
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.55 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. bedrockBack = 0
  15.  
  16. mined = 0
  17.  
  18. message = nil
  19.  
  20. function getCount()
  21.     count = 0
  22.     for i = 3,15,1 do
  23.         count = count + turtle.getItemCount(i)
  24.     end
  25.     return count
  26. end
  27.  
  28. function deposit()
  29.     turtle.turnLeft()
  30.     turtle.select(1)
  31.     turtle.dig()
  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.         success, data = turtle.inspect()
  95.         while data.name ~= "computercraft:turtle_expanded" or data.name ~= "minecraft:chest" or data.name ~= "computercraft:turtle" or data.name ~= "minecraft:air" do
  96.             turtle.dig()
  97.         end
  98.         turtle.forward()
  99.         checks = checks + 1
  100.         check()
  101.         turtle.back()
  102.         checks = checks - 1
  103.     end
  104.     if checkLavaCheck() then
  105.         print("I found some in front of me!")
  106.         turtle.select(16)
  107.         turtle.place()
  108.         turtle.refuel()
  109.         print("My fuel level is at ", turtle.getFuelLevel(), ".")
  110.     end
  111.     print("Checking to my left!")
  112.     turtle.turnLeft()
  113.     if checkWanted() then
  114.         success, data = turtle.inspect()
  115.         while data.name ~= "computercraft:turtle_expanded" or data.name ~= "minecraft:chest" or data.name ~= "computercraft:turtle" or data.name ~= "minecraft:air" do
  116.             success, data = turtle.inspect()
  117.             turtle.dig()
  118.         end
  119.         turtle.forward()
  120.         checks = checks + 1
  121.         check()
  122.         turtle.back()
  123.         checks = checks - 1
  124.     end
  125.     if checkLavaCheck() then
  126.         print("I found some to my left!")
  127.         turtle.select(16)
  128.         turtle.place()
  129.         turtle.refuel()
  130.         print("My fuel level is at ", turtle.getFuelLevel(), ".")
  131.         if checks == 0 then
  132.             turtle.select(2)
  133.             turtle.place()
  134.         end
  135.     end
  136.     print("Checking to my right!")
  137.     turtle.turnRight()
  138.     turtle.turnRight()
  139.     if checkWanted() then
  140.         success, data = turtle.inspect()
  141.         while data.name ~= "computercraft:turtle_expanded" or data.name ~= "minecraft:chest" or data.name ~= "computercraft:turtle" or data.name ~= "minecraft:air" do
  142.             success, data = turtle.inspect()
  143.             turtle.dig()
  144.         end
  145.         turtle.forward()
  146.         checks = checks + 1
  147.         check()
  148.         turtle.back()
  149.         checks = checks - 1
  150.     end
  151.     if checkLavaCheck() then
  152.         print("I found some to my right!")
  153.         turtle.select(16)
  154.         turtle.place()
  155.         turtle.refuel()
  156.         print("My fuel level is at ", turtle.getFuelLevel(), ".")
  157.         if checks == 0 then
  158.             turtle.select(2)
  159.             turtle.place()
  160.         end
  161.     end
  162.     turtle.turnLeft()
  163.     print("Checking above me!")
  164.     if checkWantedUp() then
  165.         turtle.digUp()
  166.         turtle.turnLeft()
  167.         turtle.turnLeft()
  168.         turtle.turnLeft()
  169.         turtle.turnLeft()
  170.         turtle.up()
  171.         checks = checks + 1
  172.         check()
  173.         turtle.down()
  174.         checks = checks - 1
  175.     end
  176.     if checkLavaCheckUp() then
  177.         print("I found some above me!")
  178.         turtle.select(16)
  179.         turtle.placeUp()
  180.         turtle.refuel()
  181.         print("My fuel level is at ", turtle.getFuelLevel(), ".")
  182.     end
  183.     print("Checking below me!")
  184.     if checkWantedDown() then
  185.         turtle.digDown()
  186.         turtle.down()
  187.         checks = checks + 1
  188.         check()
  189.         turtle.up()
  190.         checks = checks - 1
  191.     end
  192.     if checkLavaCheckDown() then
  193.         print("I found some below me!")
  194.         turtle.select(16)
  195.         turtle.placeDown()
  196.         turtle.refuel()
  197.         print("My fuel level is at ", turtle.getFuelLevel(), ".")
  198.     end
  199. end
  200.  
  201. function mine()
  202.     turtle.select(15)
  203.     turtle.refuel()
  204.     turtle.select(1)
  205.     print("My fuel level is at ", turtle.getFuelLevel(), ".")
  206.     print("I have ", getCount(), " items.")
  207.     success, data = turtle.inspect()
  208.     if data.name ~= "computercraft:turtle_expanded" or data.name ~= "minecraft:chest" or data.name ~= "computercraft:turtle" or data.name ~= "minecraft:air" then
  209.         success, data = turtle.inspect()
  210.         turtle.dig()
  211.     end
  212.     for a = 1,h-1,1 do
  213.         turtle.up()
  214.         y = y + 1
  215.         success, data = turtle.inspect()
  216.         if data.name ~= "computercraft:turtle_expanded" or data.name ~= "minecraft:chest" or data.name ~= "computercraft:turtle" or data.name ~= "minecraft:air" then
  217.             success, data = turtle.inspect()
  218.             turtle.dig()
  219.         end
  220.     end
  221.     check()
  222.     while y > 0 do
  223.         turtle.down()
  224.         y = y - 1
  225.         check()
  226.     end
  227.     if turtle.detectDown() == false and pos == "bot" then
  228.         turtle.select(2)
  229.         turtle.placeDown()
  230.     end
  231.     success, data = turtle.inspect()
  232.     while data.name ~= "computercraft:turtle_expanded" or data.name ~= "minecraft:chest" or data.name ~= "computercraft:turtle" or data.name ~= "minecraft:air" do
  233.         success, data = turtle.inspect()
  234.         turtle.dig()
  235.     end
  236.     turtle.forward()
  237.     if getCount() > 320 then
  238.         deposit()
  239.     end
  240.     z = z + 1
  241.     if z + h * 4 > turtle.getFuelLevel() then
  242.         while z > 0 do
  243.             turtle.back()
  244.             z = z - 1
  245.             print("Low on fuel!")
  246.             print("Fuel level = ", turtle.getFuelLevel())
  247.         end
  248.         print("Please insert more fuel in slot 15!")
  249.         read()
  250.         turtle.select(15)
  251.         turtle.refuel()
  252.         turtle.select(1)
  253.     end
  254.     if z > 0 then
  255.         print("I'm ", z,"/", l, " of the way done.")
  256.     end
  257. end
  258.  
  259. function sideMine()
  260.     turtle.select(15)
  261.     turtle.refuel()
  262.     turtle.select(1)
  263.     print("My fuel level is at ", turtle.getFuelLevel(), ".")
  264.     print("I have ", getCount(), " items.")
  265.    
  266.     success, data = turtle.inspect()
  267.     if data.name ~= "computercraft:turtle_expanded" or data.name ~= "minecraft:chest" or data.name ~= "computercraft:turtle" or data.name ~= "minecraft:air" then
  268.         success, data = turtle.inspect()
  269.         turtle.dig()
  270.     end
  271.     for a = 1,h-1,1 do
  272.         turtle.up()
  273.         y = y + 1
  274.         success, data = turtle.inspect()
  275.         if data.name ~= "computercraft:turtle_expanded" or data.name ~= "minecraft:chest" or data.name ~= "computercraft:turtle" or data.name ~= "minecraft:air" then
  276.             success, data = turtle.inspect()
  277.             turtle.dig()
  278.         end
  279.     end
  280.     check()
  281.     while y > 0 do
  282.         turtle.down()
  283.         y = y - 1
  284.         check()
  285.     end
  286.     success, data = turtle.inspect()
  287.     while data.name ~= "computercraft:turtle_expanded" or data.name ~= "minecraft:chest" or data.name ~= "computercraft:turtle" or data.name ~= "minecraft:air" do
  288.         success, data = turtle.inspect()
  289.         turtle.dig()
  290.     end
  291.     if getCount() > 320 then
  292.         deposit()
  293.     end
  294.     turtle.forward()
  295.     x = x + 1
  296. end
  297.  
  298.  
  299.  
  300. print("+-------------------------------------+")
  301. print("| Synced Branch Mine                  |")
  302. print("+-------------------------------------+")
  303. print("| Slot 15: Fuel                       |")
  304. print("| Slot 16: Empty Bucket               |")
  305. print("| Slot 1: Chests                      |")
  306. print("| Slot 2: Blocks                      |")
  307. print("+-------------------------------------+")
  308. print("| Place turtle at start of mine.      |")
  309. print("| Insert fuel. Specify height and     |")
  310. print("| length. Press enter to start.       |")
  311. print("+-------------------------------------+")
  312. read()
  313. print("+-------------------------------------+")
  314. print("| Position = ? (top, mid, bot)        |")
  315. print("+-------------------------------------+")
  316. pos = tostring(read())
  317. print("+-------------------------------------+")
  318. print("| Modem Position = ? (left, right)    |")
  319. print("+-------------------------------------+")
  320. modempos = tostring(read())
  321. rednet.open(modempos)
  322.  
  323. print("...Waiting...")
  324.  
  325. print("+-------------------------------------+")
  326. print("| Mine length = ?                     |")
  327. print("+-------------------------------------+")
  328. id, message = rednet.receive()
  329. l = message
  330. print("+-------------------------------------+")
  331. print("| Mine height = ? (>=2)               |")
  332. print("+-------------------------------------+")
  333. id, message = rednet.receive()
  334. h = message
  335. print("+-------------------------------------+")
  336. print("| Amount of shafts = ?                |")
  337. print("+-------------------------------------+")
  338. id, message = rednet.receive()
  339. m = message
  340.  
  341. while z < l do
  342.     mine()
  343. end
  344. turtle.turnLeft()
  345. turtle.turnLeft()
  346. while z > 0 do
  347.     success, data = turtle.inspect()
  348.     while data.name ~= "computercraft:turtle_expanded" or data.name ~= "minecraft:chest" or data.name ~= "computercraft:turtle" or data.name ~= "minecraft:air" do
  349.         success, data = turtle.inspect()
  350.         turtle.dig()
  351.     end
  352.     turtle.forward()
  353.     z = z - 1
  354.     end
  355. mined = mined + 1
  356.  
  357. while mined < m do
  358.     turtle.turnLeft()
  359.     sideMine()
  360.     sideMine()
  361.     sideMine()
  362.     turtle.turnLeft()
  363.     while z < l do
  364.         mine()
  365.     end
  366.     turtle.turnLeft()
  367.     turtle.turnLeft()
  368.     while z > 0 do
  369.         success, data = turtle.inspect()
  370.         while data.name ~= "computercraft:turtle_expanded" or data.name ~= "minecraft:chest" or data.name ~= "computercraft:turtle" or data.name ~= "minecraft:air" do
  371.             success, data = turtle.inspect()
  372.             turtle.dig()
  373.         end
  374.         turtle.forward()
  375.         z = z - 1
  376.     end
  377.     mined = mined + 1
  378. end
  379. turtle.turnRight()
  380. while x > 0 do
  381.     success, data = turtle.inspect()
  382.     while data.name ~= "computercraft:turtle_expanded" or data.name ~= "minecraft:chest" or data.name ~= "computercraft:turtle" or data.name ~= "minecraft:air" do
  383.         success, data = turtle.inspect()
  384.         turtle.dig()
  385.     end
  386.     if turtle.forward() then
  387.         x = x - 1
  388.     end
  389. end
  390. turtle.turnRight()
  391.  
  392. print("I put down ", chestsDropped, " chests for you.")
  393. print("My fuel level is at ", turtle.getFuelLevel(), ".")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement