Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- branchMiner a Computercraft Turtle Program by SavageCore
- -- Version 1.0
- -- Get the install/update script with "pastebin get nxzTTDAK branchMinerInit"
- -- Section: Variables -----------------------------------------------------------------------------
- -- these are defaults loaded when the turtle runs for the first time
- local trunkLength = 18
- local branchLength = 50
- local branchSpacing = 3
- local coalSlot = 1
- local stoneSlot = 2
- local torchSlot = 3
- local chestSlot = 4
- local defaultLabel = "branchMiner"
- if not os.getComputerLabel() then
- os.setComputerLabel(defaultLabel)
- end
- -- variables for saving the turtle's cordinates, saved in branchMinerCords.dat
- local cordsx = 0
- local cordsy = 0
- local cordsz = 0
- local facing = 1
- -- SECTION: Cordinate Handling
- -- cords notes: x is forward and backward, z is left and right
- -- faceing is as follows: 1 is x+, 2 is z+, 3 is x-, 4 is z- or
- -- Forward, Right, Backward, Left from inital placement
- -- all cords and facings are relative to turtles initial placement, not minecraft cords
- function saveCords() -- write cordinates to branchMinerCords.dat
- local file = fs.open("branchMinerCords.dat", "w")
- file.writeLine(cordsx)
- file.writeLine(cordsy)
- file.writeLine(cordsz)
- file.writeLine(facing)
- file.close()
- end
- function loadCords() -- read cordinates from branchMinerCords.dat
- local file = fs.open("branchMinerCords.dat", "r")
- cordsx = tonumber(file.readLine())
- cordsy = tonumber(file.readLine())
- cordsz = tonumber(file.readLine())
- facing = tonumber(file.readLine())
- file.close()
- end
- -- SECTION: Settings Saving and Loading -----------------------------------------------------------
- function saveSettings() -- write the settings to branch.cfg
- shell.run('clear')
- print("0------- branchMiner | NOTICE --------0")
- print("| |")
- print("| |")
- print("| |")
- print("| |")
- print("| Committing settings to |")
- print("| branchMiner.cfg |")
- print("| |")
- print("| |")
- print("| |")
- print("| |")
- print("0-------------------------------------0")
- local file = fs.open("branchMiner.cfg", "w")
- file.writeLine(trunkLength)
- file.writeLine(branchLength)
- file.writeLine(branchSpacing)
- file.writeLine(coalSlot)
- file.writeLine(stoneSlot)
- file.writeLine(torchSlot)
- file.writeLine(chestSlot)
- file.close()
- --sleep(0.3)
- end
- function loadSettings() -- load values from logger.cfg
- shell.run('clear')
- print("0------- branchMiner | NOTICE --------0")
- print("| |")
- print("| |")
- print("| |")
- print("| |")
- print("| Loading settings from |")
- print("| branchMiner.cfg |")
- print("| |")
- print("| |")
- print("| |")
- print("| |")
- print("0-------------------------------------0")
- local file = fs.open("branchMiner.cfg", "r")
- trunkLength = tonumber(file.readLine())
- branchLength = tonumber(file.readLine())
- branchSpacing = tonumber(file.readLine())
- coalSlot = tonumber(file.readLine())
- stoneSlot = tonumber(file.readLine())
- torchSlot = tonumber(file.readLine())
- chestSlot = tonumber(file.readLine())
- file.close()
- end
- function aboutScreen()
- shell.run('clear')
- print("0------- branchMiner | ABOUT ---------0")
- print("| |")
- print("| branchMiner written by @SavageCore |")
- print("| Version: 1.0 |")
- print("| \"pastebin get nxzTTDAK\" to update |")
- print("| |")
- print("| Thanks to: Andrakon (AndyLogger) |")
- print("| proimage (branch_mine) plus lots of |")
- print("| other people for inspiration! |")
- print("| |")
- print("0-------------------------------------0")
- print(" Press ENTER to return ")
- io.read()
- mainMenu()
- end
- function helpScreen()
- shell.run('clear')
- print("0------- branchMiner | HELP ----------0")
- print("| |")
- print("| Place turtle down facing direction |")
- print("| in which the first branch will be |")
- print("| dug out. |")
- print("| |")
- print("| Optionally you may want slots 5-16 |")
- print("| filled with ONE of each ore you |")
- print("| wish to collect most. |")
- print("| |")
- print("0-------------------------------------0")
- print(" Press ENTER to return ")
- io.read()
- mainMenu()
- end
- function viewSettings()
- shell.run('clear')
- print("0------- branchMiner | SETTINGS ------0")
- print("| |")
- print("| Trunk length: " .. trunkLength .. " |")
- print("| Branch length: " .. branchLength .. " |")
- print("| Branch spacing: " .. branchSpacing .. " |")
- print("| Coal slot: " .. coalSlot .. " |")
- print("| Cobblestone slot: " .. stoneSlot .. " |")
- print("| Torch slot: " .. torchSlot .. " |")
- print("| Chest slot: " .. chestSlot .. " |")
- print("| |")
- print("0-------------------------------------0")
- print(" Press ENTER to return ")
- io.read()
- mainMenu()
- end
- function nameSettings()
- shell.run('clear')
- print("0------- branchMiner | SETTINGS ------0")
- print("| |")
- print("| What would you like to |")
- print("| name this turtle? |")
- print("| |")
- print("| |")
- print("| |")
- print("| A turtle with no name is sad |")
- print("| |")
- print("| |")
- print("0-------------------------------------0")
- print(" Type a name and press ENTER ")
- local input = io.read()
- os.setComputerLabel(input)
- saveSettings()
- mainMenu()
- end
- function chestSettings()
- shell.run('clear')
- print("0------- branchMiner | SETTINGS ------0")
- print("| |")
- print("| Which slot are your CHESTS in? |")
- print("| |")
- print("| 1 2 3 4 |")
- print("| 5 6 7 8 |")
- print("| 9 10 11 12 |")
- print("| 13 14 15 16 |")
- print("| |")
- print("| |")
- print("0-------------------------------------0")
- print(" Type a number and press ENTER ")
- local input = io.read()
- input = tonumber(input)
- if type(input) == "number" then
- chestSlot = input
- saveSettings()
- nameSettings()
- else
- print("Invalid input - numbers only please")
- textutils.slowPrint(".......................................")
- chestSettings()
- end
- end
- function torchSettings()
- shell.run('clear')
- print("0------- branchMiner | SETTINGS ------0")
- print("| |")
- print("| Which slot are your TORCHES in? |")
- print("| |")
- print("| 1 2 3 4 |")
- print("| 5 6 7 8 |")
- print("| 9 10 11 12 |")
- print("| 13 14 15 16 |")
- print("| |")
- print("| |")
- print("0-------------------------------------0")
- print(" Type a number and press ENTER ")
- local input = io.read()
- input = tonumber(input)
- if type(input) == "number" then
- torchSlot = input
- saveSettings()
- chestSettings()
- else
- print("Invalid input - numbers only please")
- textutils.slowPrint(".......................................")
- torchSettings()
- end
- end
- function cobblestoneSettings()
- shell.run('clear')
- print("0------- branchMiner | SETTINGS ------0")
- print("| |")
- print("| Which slot is your COBBLESTONE in? |")
- print("| |")
- print("| 1 2 3 4 |")
- print("| 5 6 7 8 |")
- print("| 9 10 11 12 |")
- print("| 13 14 15 16 |")
- print("| |")
- print("| |")
- print("0-------------------------------------0")
- print(" Type a number and press ENTER ")
- local input = io.read()
- input = tonumber(input)
- if type(input) == "number" then
- stoneSlot = input
- saveSettings()
- torchSettings()
- else
- print("Invalid input - numbers only please")
- textutils.slowPrint(".......................................")
- cobblestoneSettings()
- end
- end
- function coalSettings()
- shell.run('clear')
- print("0------- branchMiner | SETTINGS ------0")
- print("| |")
- print("| Which slot is your COAL in? |")
- print("| |")
- print("| 1 2 3 4 |")
- print("| 5 6 7 8 |")
- print("| 9 10 11 12 |")
- print("| 13 14 15 16 |")
- print("| |")
- print("| |")
- print("0-------------------------------------0")
- print(" Type a number and press ENTER ")
- local input = io.read()
- input = tonumber(input)
- if type(input) == "number" then
- coalSlot = input
- saveSettings()
- cobblestoneSettings()
- else
- print("Invalid input - numbers only please")
- textutils.slowPrint(".......................................")
- coalSettings()
- end
- end
- function branchSpacingSettings()
- shell.run('clear')
- print("0------- branchMiner | SETTINGS ------0")
- print("| |")
- print("| SPACING between each BRANCH? |")
- print("| (= trunk | branch - spacing) |")
- print("| |")
- print("| |---|---|---|---|---|---|---|---|-- |")
- print("| =================================== |")
- print("| |---|---|---|---|---|---|---|---|-- |")
- print("| |")
- print("| |")
- print("0-------------------------------------0")
- print(" Type a number and press ENTER ")
- local input = io.read()
- input = tonumber(input)
- if type(input) == "number" then
- branchSpacing = input
- saveSettings()
- coalSettings()
- else
- print("Invalid input - numbers only please")
- textutils.slowPrint(".......................................")
- branchSpacingSettings()
- end
- end
- function branchLengthSettings()
- shell.run('clear')
- print("0------- branchMiner | SETTINGS ------0")
- print("| |")
- print("| How LONG should each BRANCH be? |")
- print("| (= trunk | branch - spacing) |")
- print("| |")
- print("| |---|---|---|---|---|---|---|---|-- |")
- print("| =================================== |")
- print("| |---|---|---|---|---|---|---|---|-- |")
- print("| |")
- print("| |")
- print("0-------------------------------------0")
- print(" Type a number and press ENTER ")
- local input = io.read()
- input = tonumber(input)
- if type(input) == "number" then
- branchLength = input
- saveSettings()
- branchSpacingSettings()
- else
- print("Invalid input - numbers only please")
- textutils.slowPrint(".......................................")
- branchLengthSettings()
- end
- end
- function trunkSettings()
- shell.run('clear')
- print("0------- branchMiner | SETTINGS ------0")
- print("| |")
- print("| How long should the TRUNK be? |")
- print("| (= trunk | branch - spacing) |")
- print("| |")
- print("| |---|---|---|---|---|---|---|---|-- |")
- print("| =================================== |")
- print("| |---|---|---|---|---|---|---|---|-- |")
- print("| |")
- print("| |")
- print("0-------------------------------------0")
- print(" Type a number and press ENTER ")
- local input = io.read()
- input = tonumber(input)
- if type(input) == "number" then
- trunkLength = input
- saveSettings()
- branchLengthSettings()
- else
- print("Invalid input - numbers only please")
- textutils.slowPrint(".......................................")
- trunkSettings()
- end
- end
- function mainMenu()
- shell.run('clear')
- print("0------- branchMiner | MAIN MENU -----0")
- print("| |")
- print("| 1. View settings |")
- print("| 2. Configuration |")
- print("| 3. Help and tips |")
- print("| 4. About this program |")
- print("| 5. Reboot |")
- print("| 6. Update |")
- print("| 7. Begin mining! |")
- print("| |")
- print("0-------------------------------------0")
- print(" Type a number 1-7 and press ENTER ")
- local input = io.read()
- if input == "1" then
- viewSettings()
- elseif input == "2" then
- trunkSettings()
- elseif input == "3" then
- helpScreen()
- elseif input == "4" then
- aboutScreen()
- elseif input == "5" then
- os.reboot()
- elseif input == "6" then
- if not fs.exists("branchMinerInit") then
- shell.run("pastebin","get","nxzTTDAK","branchMinerInit")
- shell.run("branchMinerInit")
- else
- shell.run("branchMinerInit")
- end
- elseif input == "7" then
- doMining()
- else
- print("Invalid input - enter a number 1-6")
- textutils.slowPrint(".......................................")
- mainMenu()
- end
- end
- -- Make sure files exist
- while not fs.exists("branchMiner.cfg") do
- saveSettings()
- saveCords()
- end
- mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement