Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Configs
- --What
- local MODEM_CHANNEL = 127
- --Amount of attempts to break block (if none set to nil or false)
- local MAX_ATTEMPTS = 25
- --Slot with enderchest (if none set to nil or false)
- local ENDER_CHEST_SLOT = 16
- --[[ Legal stuff:
- Literally do whatever you want, modify, redistribute, claim it as yours and sell it for dogecoins.
- Modification is encouraged.
- You can use any of my code for your own projects (Not recommended, my code is pretty sloppy)
- ]]
- --Not configs
- --Dont change this stuff unless you know what you are doing, basically.
- --Program Object
- local program = {
- name = shell.getRunningProgram();
- args = {...};
- version = "1.0.0";
- pastebinCode = "5bUfs7P0";
- cmdHistory = {}
- }
- --JyNet Object
- local JyNet = {
- channel = MODEM_CHANNEL;
- --If is wireless turtle or not
- active = false;
- }
- --Bot Object
- local bot = {
- ID = os.getComputerID();
- --Direction turtle is facing
- --X,Y,Z coordinates relative to where it started
- dir = 0;
- xPos;
- yPos;
- zPos;
- }
- --Mining Quarry
- local quarry = {
- --Number of blocks that have been mined this cycle
- blocksMined = 1;
- --Will dump items into enderchest
- enderChest = false;
- x = tonumber(program.args[1]);
- y = tonumber(program.args[2]);
- z = tonumber(program.args[3]);
- }
- local eventData = {}
- local help = [[
- Ill add stuff later
- ]]
- --Clears screen then exits program
- function program.exit()
- --Clear screen
- term.clear()
- --Set cursor pos to top left
- term.setCursorPos(1,1)
- --Exits program
- error()
- end
- function program.uninstall()
- --Clear screen
- term.clear()
- --Set cursor pos to top left
- term.setCursorPos(1,1)
- print("Are you sure you would like to uninstall?")
- program.input = read()
- --If player answer is yes, then uninstall program
- if program.input == "yes"
- or program.input == "YES"
- or program.input == "y"
- or program.input == "Y"
- or program.input == "true"
- or program.input == "TRUE" then
- --Deletes current program file
- fs.delete(program.name)
- print("Program uninstalled")
- --Waits for key press
- os.pullEvent("key")
- --Exits program
- program.exit()
- end
- end
- --Reinstalls/updates the currently running program
- function program.reinstall()
- if http then
- --Deletes current program file
- fs.delete(program.name)
- --Runs built it pastebin program (too lazy to write my own function)
- shell.run("pastebin get "..program.pastebinCode.." "..program.name)
- print("Program reinstalled, press any key to continue")
- --Waits for key press
- os.pullEvent("key")
- --Exits program
- program.exit()
- else
- print("Http not enabled")
- --Waits for key press
- os.pullEvent("key")
- end
- end
- function program.edit()
- --Opens file to be edited
- shell.run("edit "..program.name)
- --Exits program
- program.exit()
- end
- function program.printHelp()
- --Clears screen
- term.clear()
- --Sets cursor pos to top left
- term.setCursorPos(1,1)
- print(help)
- --Waits for key press
- os.pullEvent("key")
- end
- function program.cmd()
- term.clear()
- term.setCursorPos(1,1)
- while true do
- term.write("> ")
- program.input = read(nil,program.cmdHistory)
- program.cmdHistory[#program.cmdHistory+1] = program.input
- if program.input == "left" then
- bot.turn("left")
- elseif program.input == "right" then
- bot.turn("right")
- elseif program.input == "forward" then
- bot.forward()
- elseif program.input == "down" then
- bot.down()
- elseif program.input == "up" then
- bot.up()
- elseif program.input == "refuel" then
- bot.refuel()
- elseif program.input == "back" then
- bot.turn("back")
- elseif program.input == "exit" then
- program.cmdHistory = {}
- return
- elseif program.input == "help" then
- print("Commands = \"left\",\"right\",\"down\",\"up\", and\"forward\"")
- else
- print("Not valid command")
- end
- end
- end
- function program.errorCheck()
- --Beefy error checking code (if any)
- end
- --This runs on startup and gets everything set up
- function program.startup()
- turtle.select(1)
- program.errorCheck()
- if tonumber(program.args[1])
- and tonumber(program.args[2])
- and tonumber(program.args[3]) then
- quarry.run()
- end
- end
- function bot.refuel(sNum)
- if sNum == nil then
- sNum = 0
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Refueling")
- for i = 1,16 do
- --Selects slot
- turtle.select(i)
- --Refuels from slot
- turtle.refuel()
- end
- turtle.select(1)
- return turtle.getFuelLevel()
- end
- --Moves forward and breaks blocks in front of it
- function bot.forward(sNum)
- bot.attemptCounter = 0
- if sNum == nil then
- sNum = 1
- end
- --Breaks blocks until it can move forward
- for i = 1,sNum do
- while not turtle.forward() do
- if turtle.dig() then
- quarry.blocksMined = quarry.blocksMined + 1
- end
- bot.attemptCounter = bot.attemptCounter + 1
- if bot.attemptCounter > 1
- and bot.attemptCounter <= MAX_ATTEMPTS then
- --Attacks entities
- turtle.attack()
- elseif bot.attemptCounter > MAX_ATTEMPTS then
- return false
- end
- end
- end
- return true
- end
- function bot.up(sNum)
- attemptCounter = 0
- if sNum == nil then
- sNum = 1
- end
- --Breaks blocks until it can move forward
- for i = 1,sNum do
- while not turtle.up() do
- if turtle.digUp() then
- quarry.blocksMined = quarry.blocksMined + 1
- end
- attemptCounter = attemptCounter + 1
- if attemptCounter > 1
- and attemptCounter <= MAX_ATTEMPTS then
- --Attacks entities
- turtle.attackUp()
- elseif attemptCounter > MAX_ATTEMPTS then
- return false
- end
- end
- end
- return true
- end
- function bot.down(sNum)
- attemptCounter = 0
- if sNum == nil then
- sNum = 1
- end
- --Breaks blocks until it can move forward
- for i = 1,sNum do
- while not turtle.down() do
- if turtle.digDown() then
- quarry.blocksMined = quarry.blocksMined + 1
- end
- attemptCounter = attemptCounter + 1
- if attemptCounter > 1
- and attemptCounter <= MAX_ATTEMPTS then
- --Attacks entities
- turtle.attackDown()
- elseif attemptCounter > MAX_ATTEMPTS then
- return false
- end
- end
- end
- return true
- end
- --Changes turtle orientation
- function bot.turn(sDir)
- if sDir == "left" then
- turtle.turnLeft()
- elseif sDir == "right" then
- turtle.turnRight()
- elseif sDir == "back" then
- turtle.turnRight()
- turtle.turnRight()
- end
- end
- function quarry.checkFuel()
- quarry.reqFuel = ((quarry.x*quarry.y)*quarry.z)
- bot.fuelLevel = turtle.getFuelLevel()
- while bot.fuelLevel < quarry.reqFuel do
- print("Fuel = "..bot.fuelLevel.." of "..quarry.reqFuel)
- quarry.event = os.pullEvent()
- if quarry.event == "key" or quarry.event == "turtle_inventory" then
- bot.fuelLevel = turtle.refuel()
- end
- end
- end
- function quarry.startCycle()
- bot.forward()
- bot.turn("right")
- end
- function quarry.digX()
- bot.forward(quarry.x-1)
- end
- function quarry.digY()
- for i = 1,quarry.y do
- quarry.digX()
- if i ~= quarry.y then
- bot.down()
- bot.turn("back")
- end
- end
- end
- function quarry.endCycle()
- if quarry.y%2 == 1 then
- bot.turn("left")
- quarry.digX()
- end
- bot.turn("right")
- bot.up(quarry.y-1)
- end
- function quarry.digZ()
- for i = 1,quarry.z do
- quarry.startCycle()
- quarry.digY()
- quarry.endCycle()
- end
- end
- function quarry.shutDown()
- quarry.x,quarry.y,quarry.z = nil
- end
- function quarry.startup()
- --clear screen
- term.clear()
- --set cursor pos to top left
- term.setCursorPos(1,1)
- --Checks if running on a turtle
- if term.getSize() > 39 then
- --Exits with error message
- error("This program must run on a turtle")
- end
- if tonumber(ENDER_CHEST_SLOT)
- and turtle.getItemCount(ENDER_CHEST_SLOT) > 0 then
- quarry.enderChest = true
- end
- --Get X,Y,and Z num from player
- if not quarry.x
- or not quarry.y
- or not quarry.y then
- term.write("x: ")
- program.input = read()
- quarry.x = math.abs(math.floor(tonumber(program.input)))
- term.write("y: ")
- program.input = read()
- quarry.y = math.abs(math.floor(tonumber(program.input)))
- term.write("z: ")
- program.input = read()
- quarry.z = math.abs(math.floor(tonumber(program.input)))
- end
- end
- --Run the quarry
- function quarry.run()
- quarry.startup()
- quarry.digZ()
- quarry.shutDown()
- end
- --Wraps modem as peripheral
- function JyNet.wrapModem()
- --Checks for modem
- if peripheral.getType("right") == "modem" then
- --Creates modem object
- JyNet.modem = peripheral.wrap("right")
- JyNet.active = true
- return true
- else
- return false
- end
- end
- --Send Messages through modems
- function JyNet.send(sMessage)
- --Checks if modem is connected
- if JyNet.active then
- --Sends message
- JyNet.modem.transmit(JyNet.channel,bot.ID,sMessage)
- return true
- else
- return false
- end
- end
- -- //Menu code
- local menu = {}
- menu.pos = 3
- menu.backColor = colors.black
- menu.programName = program.name
- menu.programVersion = program.version
- menu.programDeveloper = "Jyzarc27"
- menu.eventData = {}
- menu.mainTextColor = colors.red
- menu.items = {
- [1] = { text = "help", handler = program.printHelp, color = 1, bounds = {} };
- [2] = { text = "refuel", handler = bot.refuel, color = 1, bounds = {} };
- [3] = { text = "run", handler = quarry.run, color = 1, bounds = {} };
- [4] = { text = "edit", handler = program.edit, color = 1, bounds = {} };
- [5] = { text = "exit", handler = program.exit, color = 1, bounds = {} };
- [6] = { text = "cmd", handler = program.cmd, color = 1, bounds = {} };
- [7] = { text = "reinstall", handler = program.reinstall, color = 1, bounds = {} };
- [8] = { text = "uninstall", handler = program.uninstall, color = 1, bounds = {} };
- }
- function menu.print()
- if term.isColor() then
- term.setBackgroundColor(menu.backColor)
- else
- term.setBackgroundColor(colors.black)
- end
- term.clear()
- term.setCursorPos(1,1)
- if term.isColor() then
- term.setTextColor(menu.mainTextColor)
- else
- term.setTextColor(colors.white)
- end
- print(menu.programName.." "..menu.programVersion.." by "..menu.programDeveloper)
- menu.x,menu.y = term.getSize()
- menu.x = (menu.x/2)
- menu.y = (menu.y/2) - (#menu.items/2)
- for i = 1,#menu.items do
- if term.isColor() then
- term.setTextColor(menu.items[i].color)
- else
- term.setTextColor(colors.white)
- end
- term.setCursorPos(menu.x-(string.len(menu.items[i].text)/2),menu.y+(i))
- menu.items[i].bounds.x1,menu.items[i].bounds.y = term.getCursorPos()
- if menu.pos == i then
- print("<"..menu.items[i].text..">")
- else
- print(" "..menu.items[i].text)
- end
- menu.items[i].bounds.x2 = menu.items[i].bounds.x1 + string.len(menu.items[i].text)
- end
- end
- function menu.run()
- menu.items[menu.pos].handler()
- end
- function menu.checkClick(x,y)
- for i = 1,#menu.items do
- if x >= menu.items[i].bounds.x1
- and x <= menu.items[i].bounds.x2
- and y == menu.items[i].bounds.y then
- return i
- end
- end
- end
- program.startup()
- --Main Loop
- while true do
- menu.print(menu.pos)
- menu.eventData[1],menu.eventData[2],menu.eventData[3],menu.eventData[4] = os.pullEvent()
- if menu.eventData[1] == "key" then
- if menu.eventData[2] == 208
- or menu.eventData[2] == 205 then
- menu.pos = menu.pos + 1
- elseif menu.eventData[2] == 200
- or menu.eventData[2] == 203 then
- menu.pos = menu.pos - 1
- elseif menu.eventData[2] == 28 then
- menu.run()
- end
- elseif menu.eventData[1] == "mouse_scroll" then
- menu.pos = menu.pos + menu.eventData[2]
- elseif menu.eventData[1] == "mouse_click" then
- if menu.eventData[2] == 1 then
- menu.temp = menu.checkClick(menu.eventData[3],menu.eventData[4])
- if menu.temp ~= nil then
- menu.pos = menu.temp
- menu.run()
- end
- end
- end
- if menu.pos > #menu.items then
- menu.pos = 1
- elseif menu.pos < 1 then
- menu.pos = #menu.items
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment