Advertisement
SavageCore

branchMiner

May 20th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.88 KB | None | 0 0
  1. -- branchMiner a Computercraft Turtle Program by SavageCore
  2. -- Version 1.0
  3. -- Get the install/update script with "pastebin get nxzTTDAK branchMinerInit"
  4.  
  5. -- Section: Variables -----------------------------------------------------------------------------
  6. -- these are defaults loaded when the turtle runs for the first time
  7. local trunkLength = 18
  8. local branchLength = 50                
  9. local branchSpacing = 3
  10. local coalSlot = 1
  11. local stoneSlot = 2
  12. local torchSlot = 3
  13. local chestSlot = 4
  14. local defaultLabel = "branchMiner"
  15. if not os.getComputerLabel() then
  16.  os.setComputerLabel(defaultLabel)
  17. end
  18. -- variables for saving the turtle's cordinates, saved in branchMinerCords.dat
  19. local cordsx = 0
  20. local cordsy = 0
  21. local cordsz = 0
  22. local facing = 1
  23.  
  24. -- SECTION: Cordinate Handling
  25. -- cords notes: x is forward and backward, z is left and right
  26. -- faceing is as follows: 1 is x+, 2 is z+, 3 is x-, 4 is z- or
  27. -- Forward, Right, Backward, Left from inital placement
  28. -- all cords and facings are relative to turtles initial placement, not minecraft cords
  29.  
  30. function saveCords() -- write cordinates to branchMinerCords.dat
  31.     local file = fs.open("branchMinerCords.dat", "w")
  32.     file.writeLine(cordsx)
  33.     file.writeLine(cordsy)
  34.     file.writeLine(cordsz)
  35.     file.writeLine(facing)
  36.     file.close()
  37. end
  38.  
  39. function loadCords() -- read cordinates from branchMinerCords.dat
  40.     local file = fs.open("branchMinerCords.dat", "r")
  41.     cordsx = tonumber(file.readLine())
  42.     cordsy = tonumber(file.readLine())
  43.     cordsz = tonumber(file.readLine())
  44.     facing = tonumber(file.readLine())
  45.     file.close()
  46. end
  47.  
  48. -- SECTION: Settings Saving and Loading -----------------------------------------------------------
  49. function saveSettings() -- write the settings to branch.cfg
  50.   shell.run('clear')
  51.   print("0------- branchMiner | NOTICE --------0")
  52.   print("|                                     |")
  53.   print("|                                     |")
  54.   print("|                                     |")  
  55.   print("|                                     |")
  56.   print("|       Committing settings to        |")
  57.   print("|         branchMiner.cfg             |")
  58.   print("|                                     |")
  59.   print("|                                     |")
  60.   print("|                                     |")
  61.   print("|                                     |")
  62.   print("0-------------------------------------0")
  63.     local file = fs.open("branchMiner.cfg", "w")
  64.     file.writeLine(trunkLength)
  65.     file.writeLine(branchLength)
  66.     file.writeLine(branchSpacing)
  67.     file.writeLine(coalSlot)
  68.     file.writeLine(stoneSlot)
  69.     file.writeLine(torchSlot)
  70.     file.writeLine(chestSlot)
  71.     file.close()
  72.     --sleep(0.3)
  73. end
  74.  
  75. function loadSettings() -- load values from logger.cfg
  76.   shell.run('clear')
  77.   print("0------- branchMiner | NOTICE --------0")
  78.   print("|                                     |")
  79.   print("|                                     |")
  80.   print("|                                     |")  
  81.   print("|                                     |")
  82.   print("|       Loading settings from         |")
  83.   print("|         branchMiner.cfg             |")
  84.   print("|                                     |")
  85.   print("|                                     |")
  86.   print("|                                     |")
  87.   print("|                                     |")
  88.   print("0-------------------------------------0")
  89.     local file = fs.open("branchMiner.cfg", "r")
  90.     trunkLength = tonumber(file.readLine())
  91.     branchLength = tonumber(file.readLine())
  92.     branchSpacing = tonumber(file.readLine())
  93.     coalSlot = tonumber(file.readLine())
  94.     stoneSlot = tonumber(file.readLine())
  95.     torchSlot = tonumber(file.readLine())
  96.     chestSlot = tonumber(file.readLine())
  97.     file.close()
  98. end
  99.  
  100. function aboutScreen()
  101.   shell.run('clear')
  102.   print("0------- branchMiner | ABOUT ---------0")
  103.   print("|                                     |")
  104.   print("| branchMiner written by @SavageCore  |")
  105.   print("| Version: 1.0                        |")
  106.   print("| \"pastebin get nxzTTDAK\" to update   |")
  107.   print("|                                     |")
  108.   print("| Thanks to: Andrakon (AndyLogger)    |")
  109.   print("| proimage (branch_mine) plus lots of |")
  110.   print("| other people for inspiration!       |")
  111.   print("|                                     |")
  112.   print("0-------------------------------------0")
  113.   print("         Press ENTER to return         ")
  114.     io.read()
  115.     mainMenu()
  116. end
  117.  
  118. function helpScreen()
  119.   shell.run('clear')
  120.   print("0------- branchMiner | HELP ----------0")
  121.   print("|                                     |")
  122.   print("| Place turtle down facing direction  |")
  123.   print("| in which the first branch will be   |")
  124.   print("| dug out.                            |")
  125.   print("|                                     |")
  126.   print("| Optionally you may want slots 5-16  |")
  127.   print("| filled with ONE of each ore you     |")
  128.   print("| wish to collect most.               |")
  129.   print("|                                     |")
  130.   print("0-------------------------------------0")
  131.   print("         Press ENTER to return         ")
  132.     io.read()
  133.     mainMenu()
  134. end
  135.  
  136. function viewSettings()
  137.   shell.run('clear')
  138.   print("0------- branchMiner | SETTINGS ------0")
  139.   print("|                                     |")
  140.   print("| Trunk length: " .. trunkLength .. "                    |")
  141.   print("| Branch length: " .. branchLength .. "                   |")
  142.   print("| Branch spacing: " .. branchSpacing .. "                   |")
  143.   print("| Coal slot: " .. coalSlot .. "                        |")
  144.   print("| Cobblestone slot: " .. stoneSlot .. "                 |")
  145.   print("| Torch slot: " .. torchSlot .. "                       |")
  146.   print("| Chest slot: " .. chestSlot .. "                       |")
  147.   print("|                                     |")
  148.   print("0-------------------------------------0")
  149.   print("         Press ENTER to return         ")
  150.     io.read()
  151.     mainMenu()
  152. end
  153.  
  154. function nameSettings()
  155.   shell.run('clear')
  156.   print("0------- branchMiner | SETTINGS ------0")
  157.   print("|                                     |")
  158.   print("| What would you like to              |")
  159.   print("| name this turtle?                   |")  
  160.   print("|                                     |")  
  161.   print("|                                     |")  
  162.   print("|                                     |")
  163.   print("| A turtle with no name is sad        |")  
  164.   print("|                                     |")  
  165.   print("|                                     |")  
  166.   print("0-------------------------------------0")
  167.   print("     Type a name and press ENTER       ")
  168.     local input = io.read()
  169.   os.setComputerLabel(input)
  170.   saveSettings()
  171.   mainMenu()
  172. end
  173.  
  174. function chestSettings()
  175.   shell.run('clear')
  176.   print("0------- branchMiner | SETTINGS ------0")
  177.   print("|                                     |")
  178.   print("| Which slot are your CHESTS in?      |")
  179.   print("|                                     |")  
  180.   print("| 1  2  3  4                          |")  
  181.   print("| 5  6  7  8                          |")  
  182.   print("| 9  10 11 12                         |")  
  183.   print("| 13 14 15 16                         |")  
  184.   print("|                                     |")  
  185.   print("|                                     |")  
  186.   print("0-------------------------------------0")
  187.   print("     Type a number and press ENTER     ")
  188.     local input = io.read()
  189.     input = tonumber(input)
  190.     if type(input) == "number" then
  191.     chestSlot = input
  192.     saveSettings()
  193.     nameSettings()
  194.     else
  195.         print("Invalid input - numbers only please")
  196.         textutils.slowPrint(".......................................")
  197.         chestSettings()
  198.     end  
  199. end
  200.  
  201. function torchSettings()
  202.   shell.run('clear')
  203.   print("0------- branchMiner | SETTINGS ------0")
  204.   print("|                                     |")
  205.   print("| Which slot are your TORCHES in?     |")
  206.   print("|                                     |")  
  207.   print("| 1  2  3  4                          |")  
  208.   print("| 5  6  7  8                          |")  
  209.   print("| 9  10 11 12                         |")  
  210.   print("| 13 14 15 16                         |")  
  211.   print("|                                     |")  
  212.   print("|                                     |")  
  213.   print("0-------------------------------------0")
  214.   print("     Type a number and press ENTER     ")
  215.     local input = io.read()
  216.     input = tonumber(input)
  217.     if type(input) == "number" then
  218.     torchSlot = input
  219.     saveSettings()
  220.     chestSettings()
  221.     else
  222.         print("Invalid input - numbers only please")
  223.         textutils.slowPrint(".......................................")
  224.         torchSettings()
  225.     end  
  226. end  
  227.  
  228. function cobblestoneSettings()
  229.   shell.run('clear')
  230.   print("0------- branchMiner | SETTINGS ------0")
  231.   print("|                                     |")
  232.   print("| Which slot is your COBBLESTONE in?  |")
  233.   print("|                                     |")  
  234.   print("| 1  2  3  4                          |")  
  235.   print("| 5  6  7  8                          |")  
  236.   print("| 9  10 11 12                         |")  
  237.   print("| 13 14 15 16                         |")  
  238.   print("|                                     |")  
  239.   print("|                                     |")  
  240.   print("0-------------------------------------0")
  241.   print("     Type a number and press ENTER     ")
  242.     local input = io.read()
  243.     input = tonumber(input)
  244.     if type(input) == "number" then
  245.     stoneSlot = input
  246.     saveSettings()
  247.     torchSettings()
  248.     else
  249.         print("Invalid input - numbers only please")
  250.         textutils.slowPrint(".......................................")
  251.         cobblestoneSettings()
  252.     end  
  253. end  
  254.  
  255. function coalSettings()
  256.   shell.run('clear')
  257.   print("0------- branchMiner | SETTINGS ------0")
  258.   print("|                                     |")
  259.   print("| Which slot is your COAL in?         |")
  260.   print("|                                     |")  
  261.   print("| 1  2  3  4                          |")  
  262.   print("| 5  6  7  8                          |")  
  263.   print("| 9  10 11 12                         |")  
  264.   print("| 13 14 15 16                         |")  
  265.   print("|                                     |")  
  266.   print("|                                     |")  
  267.   print("0-------------------------------------0")
  268.   print("     Type a number and press ENTER     ")
  269.     local input = io.read()
  270.     input = tonumber(input)
  271.     if type(input) == "number" then
  272.     coalSlot = input
  273.     saveSettings()
  274.     cobblestoneSettings()
  275.     else
  276.         print("Invalid input - numbers only please")
  277.         textutils.slowPrint(".......................................")
  278.         coalSettings()
  279.     end  
  280. end  
  281.  
  282. function branchSpacingSettings()
  283.   shell.run('clear')
  284.   print("0------- branchMiner | SETTINGS ------0")
  285.   print("|                                     |")
  286.   print("| SPACING between each BRANCH?        |")
  287.   print("| (= trunk | branch - spacing)        |")  
  288.   print("|                                     |")  
  289.   print("| |---|---|---|---|---|---|---|---|-- |")  
  290.   print("| =================================== |")  
  291.   print("| |---|---|---|---|---|---|---|---|-- |")
  292.   print("|                                     |")  
  293.   print("|                                     |")  
  294.   print("0-------------------------------------0")
  295.   print("     Type a number and press ENTER     ")
  296.     local input = io.read()
  297.     input = tonumber(input)
  298.     if type(input) == "number" then
  299.     branchSpacing = input
  300.     saveSettings()
  301.     coalSettings()
  302.     else
  303.         print("Invalid input - numbers only please")
  304.         textutils.slowPrint(".......................................")
  305.         branchSpacingSettings()
  306.     end  
  307. end  
  308.  
  309. function branchLengthSettings()
  310.   shell.run('clear')
  311.   print("0------- branchMiner | SETTINGS ------0")
  312.   print("|                                     |")
  313.   print("| How LONG should each BRANCH be?     |")
  314.   print("| (= trunk | branch - spacing)        |")  
  315.   print("|                                     |")  
  316.   print("| |---|---|---|---|---|---|---|---|-- |")  
  317.   print("| =================================== |")  
  318.   print("| |---|---|---|---|---|---|---|---|-- |")
  319.   print("|                                     |")  
  320.   print("|                                     |")  
  321.   print("0-------------------------------------0")
  322.   print("     Type a number and press ENTER     ")
  323.     local input = io.read()
  324.     input = tonumber(input)
  325.     if type(input) == "number" then
  326.     branchLength = input
  327.     saveSettings()
  328.     branchSpacingSettings()
  329.     else
  330.         print("Invalid input - numbers only please")
  331.         textutils.slowPrint(".......................................")
  332.         branchLengthSettings()
  333.     end  
  334. end  
  335.  
  336. function trunkSettings()
  337.   shell.run('clear')
  338.   print("0------- branchMiner | SETTINGS ------0")
  339.   print("|                                     |")
  340.   print("| How long should the TRUNK be?       |")
  341.   print("| (= trunk | branch - spacing)        |")  
  342.   print("|                                     |")  
  343.   print("| |---|---|---|---|---|---|---|---|-- |")  
  344.   print("| =================================== |")  
  345.   print("| |---|---|---|---|---|---|---|---|-- |")
  346.   print("|                                     |")  
  347.   print("|                                     |")  
  348.   print("0-------------------------------------0")
  349.   print("     Type a number and press ENTER     ")
  350.     local input = io.read()
  351.     input = tonumber(input)
  352.     if type(input) == "number" then
  353.     trunkLength = input
  354.     saveSettings()
  355.     branchLengthSettings()
  356.     else
  357.         print("Invalid input - numbers only please")
  358.         textutils.slowPrint(".......................................")
  359.         trunkSettings()
  360.     end  
  361. end  
  362.  
  363. function mainMenu()
  364.   shell.run('clear')
  365.   print("0------- branchMiner | MAIN MENU -----0")
  366.   print("|                                     |")
  367.   print("| 1. View settings                    |")
  368.   print("| 2. Configuration                    |")  
  369.   print("| 3. Help and tips                    |")
  370.   print("| 4. About this program               |")
  371.   print("| 5. Reboot                           |")
  372.   print("| 6. Update                           |")
  373.   print("| 7. Begin mining!                    |")
  374.   print("|                                     |")  
  375.   print("0-------------------------------------0")
  376.   print("  Type a number 1-7 and press ENTER    ")
  377.     local input = io.read()
  378.     if input == "1" then
  379.         viewSettings()
  380.     elseif input == "2" then
  381.         trunkSettings()
  382.     elseif input == "3" then
  383.         helpScreen()
  384.     elseif input == "4" then
  385.         aboutScreen()
  386.     elseif input == "5" then
  387.         os.reboot()
  388.     elseif input == "6" then
  389.     if not fs.exists("branchMinerInit") then
  390.       shell.run("pastebin","get","nxzTTDAK","branchMinerInit")
  391.       shell.run("branchMinerInit")
  392.     else
  393.       shell.run("branchMinerInit")
  394.     end    
  395.   elseif input == "7" then
  396.     doMining()
  397.     else
  398.         print("Invalid input - enter a number 1-6")
  399.         textutils.slowPrint(".......................................")
  400.         mainMenu()
  401.     end  
  402. end
  403.  
  404. -- Make sure files exist
  405. while not fs.exists("branchMiner.cfg") do
  406.     saveSettings()
  407.     saveCords()
  408. end
  409. mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement