Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("GUIElements")
- local args = {...}
- --Name, Text, BlinkText, FirstColor, SecondColor, FirstTextColor, SecondTextColor, PosX, PosY, Blink
- local StatusPoint = GUIElements.CreateBlinkPoint("SP", "Undefined", nil, colors.green, colors.white, nil, nil, 2, 1)
- local InfoPoint = GUIElements.CreateBlinkPoint("IP", "Press 'p' to pause/continue; Press 's' to stop.", ">", colors.green, colors.white, nil, nil, 2, 3)
- local FuelPoint = GUIElements.CreateBlinkPoint("FP", "Fuel: " .. turtle.getFuelLevel(), ">", colors.green, colors.white, nil, nil, 2, 6)
- local ConnectPoint = GUIElements.CreateBlinkPoint("CP", "No modem", ">", colors.red, colors.white, nil, nil, 2, 8)
- --Define variable
- local isColor = term.isColor()
- local serveraddress = nil
- local running = true
- local FUELSLOT = 16
- local status = "paused"
- local isConnect = 0 -- '-1' - no modem; '0' - no connect; '1' - connect; '2' - connected.
- local statcolor = {}
- statcolor["mining"] = colors.green
- statcolor["paused"] = colors.yellow
- statcolor["no_fuel"] = colors.red
- statcolor["undefined"] = colors.gray
- --Utils
- local function CheckFuel()
- if turtle.getFuelLevel() > 0 or turtle.getFuelLevel() == "unlimited" then
- return true
- end
- turtle.select(FUELSLOT)
- if turtle.refuel() then
- turtle.select(1)
- os.queueEvent("status", "paused")
- return true
- end
- turtle.drop(FUELSLOT)
- return false
- end
- local function Exit()
- running = false
- GUIElements.DestroyBlinkPoint(StatusPoint.name)
- GUIElements.DestroyBlinkPoint(InfoPoint.name)
- GUIElements.DestroyBlinkPoint(FuelPoint.name)
- GUIElements.DestroyBlinkPoint(ConnectPoint.name)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(1, 1)
- term.clear()
- end
- --Program
- local function Mine(len, retback, core, list)
- turtle.select(1)
- while running do
- if not CheckFuel() and status ~= "undefined" then
- os.queueEvent("status", "no_fuel")
- end
- if (status == "mining") then
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- turtle.digUp()
- else os.sleep(2) end
- end
- end
- local function GUI()
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.gray)
- term.clear()
- while running do
- StatusPoint.text = status
- StatusPoint.fcolor = statcolor[status]
- FuelPoint.text = "Fuel: " .. turtle.getFuelLevel()
- GUIElements.DrawPoints()
- os.sleep(1)
- end
- end
- local function ncGUI()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- StatusPoint.fcolor = colors.white
- InfoPoint.fcolor = colors.white
- FuelPoint.fcolor = colors.white
- ConnectPoint.fcolor = colors.white
- StatusPoint.scolor = colors.black
- InfoPoint.scolor = colors.black
- FuelPoint.scolor = colors.black
- ConnectPoint.scolor = colors.black
- StatusPoint.ftcolor = colors.white
- InfoPoint.ftcolor = colors.white
- FuelPoint.ftcolor = colors.white
- ConnectPoint.ftcolor = colors.white
- StatusPoint.stcolor = colors.black
- InfoPoint.stcolor = colors.black
- FuelPoint.stcolor = colors.black
- ConnectPoint.stcolor = colors.black
- while running do
- StatusPoint.text = status
- FuelPoint.text = "Fuel: " .. turtle.getFuelLevel()
- GUIElements.DrawPoints()
- os.sleep(1)
- end
- end
- local function UserControl()
- while running do
- local event, par1 = os.pullEvent()
- if (event == "char") then
- if par1 == "p" and (status == "mining" or status == "paused") then
- if status == "paused" then os.queueEvent("status", "mining") else os.queueEvent("status", "paused") end
- elseif par1 == "s" then
- rednet.send(address, "packet stop end", "TurtleControl1")
- Exit()
- end
- elseif (event == "status") then
- status = par1
- end
- end
- end
- local function MessageHandler()
- if not address then return end
- while running do
- rednet.send(address, "packet " .. status .. " " .. turtle.getFuelLevel() .. " end", "TurtleControl1")
- local id, msg = rednet.receive("TurtleControl1", 1)
- if id == address then
- if msg == "paused" then
- if status == "paused" then os.queueEvent("status", "mining") else os.queueEvent("status", "paused") end
- elseif msg == "stop" then
- Exit()
- end
- end
- end
- end
- local sModemSide = nil
- for n, sSide in ipairs(rs.getSides()) do
- if peripheral.getType(sSide) == "modem" and peripheral.call(sSide, "isWireless") then
- sModemSide = sSide
- break
- end
- end
- if not sModemSide then isConnect = -1 end
- if args[1] and type(args[1] + 0) == "number" then
- address = args[1] + 0
- end
- if sModemSide and address then
- rednet.open(sModemSide)
- isConnect = 1
- end
- if term.isColor() then
- parallel.waitForAll(GUI, UserControl, Mine, MessageHandler)
- else
- parallel.waitForAll(ncGUI, UserControl, Mine, MessageHandler)
- end
- rednet.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement