Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("octree")
- local mapTree = octree.new()
- local termX, termY = term.getSize()
- local function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- local function rednetCheck(side)
- local idReceiver, msg = rednet.receive()
- if msg == "<success:"..side..">" then
- return "true"
- else
- return "false"
- end
- end
- local function drawBox(x, y, a, b, colorL)
- paintutils.drawLine(x, y, a, y, colorL) --draw the top line
- paintutils.drawLine(x, y, x, b, colorL) --draw the left line
- paintutils.drawLine(a, y, a, b, colorL) --draw the right line
- paintutils.drawLine(x, b, a, b, colorL) --draw the bottom line
- end
- local function drawGUI()
- local x, y = term.getSize()
- drawBox(41, 1, x, y, colors.blue)
- end
- local function drawTurtle(x, y, orientation)
- if orientation == "right" then
- tW = ">"
- elseif orientation == "left" then
- tW = "<"
- elseif orientation == "up" then
- tW = "^"
- elseif orientation == "down" then
- tW = "v"
- end
- term.setCursorPos(x, y)
- term.setTextColor(colors.red)
- write(tW)
- term.setTextColor(colors.white)
- end
- local function drawMap(xPos, yPos, z, orientation)
- local x = xPos-19
- local y = yPos-termY/2
- for a=1, termY do
- for b=1, 40 do
- local currentBlock = mapTree:get(b+x, y+a, z)
- if currentBlock == nil then
- paintutils.drawPixel(b+x, y+a, colors.grey)
- elseif currentBlock == 1 then
- paintutils.drawPixel(b+x, y+a, colors.green)
- elseif currentBlock == 0 then
- paintutils.drawPixel(b+x, a+y, colors.white)
- end
- end
- end
- drawTurtle(xPos, yPos, orientation)
- end
- local function receiveMap()
- local id, mapS = rednet.receive()
- local mapT = textutils.unserialize(mapS)
- local x, y, z, orientation, block = mapT[1], mapT[2], mapT[3], mapT[4], mapT[5]
- mapTree:set(x, y, z, block)
- end
- local function ping()
- write("ID of the turtle :")
- local idTurtle = tonumber(read())
- clear()
- rednet.send(idTurtle, "#/ping#")
- local id, msg = rednet.receive(5)
- if msg == "<ping>" then
- print("The turtle has respond")
- sleep(1)
- return "true"
- else
- print("Error : the turtle doesn't respond")
- return "false"
- end
- end
- clear()
- ping()
- clear()
- print("Enter command")
- while true do
- local key, keycode = os.pullEvent("key")
- if keycode == 200 then
- rednet.send(idTurtle, "#/forward#")
- if rednetCheck(forward) then
- print("Success")
- else
- print("Fail")
- end
- elseif keycode == 205 then
- rednet.send(idTurtle, "#/right#")
- elseif keycode == 203 then
- rednet.send(idTurtle, "#/left#")
- elseif keycode == 208 then
- rednet.send(idTurtle, "#/back#")
- if rednetCheck(back) then
- print("Success")
- else
- print("Fail")
- end
- elseif keycode == 57 then
- rednet.send(idTurtle, "#/dig#")
- elseif keycode == 42 then
- rednet.send(idTurtle, "#/up#")
- if rednetCheck(up) then
- print("Success")
- else
- print("Fail")
- end
- elseif keycode == 29 then
- rednet.send(idTurtle, "#/down#")
- if rednetCheck(down) then
- print("Success")
- else
- print("Fail")
- end
- elseif keycode == 28 then
- rednet.send(idTurtle, "#/select#")
- write("Enter the number of the slot :")
- numberSlot = read()
- clear()
- rednet.send(idTurtle, numberSlot)
- elseif keycode == 14 then
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement