Advertisement
Greygraphics

TurtleRemote

Oct 21st, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 KB | None | 0 0
  1. --This is the code for the Turtle. It works in CC 1.74 and requieres a wireless mining turtle.
  2.  
  3. local moves = {}
  4.  
  5. local function connect()
  6.     rednet.open("right")
  7.     print(">> Connecting")
  8.     TrgtID,msg1,prt = rednet.receive("Ask")
  9.     rednet.send(TrgtID,"Ping","Ans")
  10.     print(">> Connected to "..TrgtID.."\n")
  11. end
  12.  
  13. local function save(move)
  14.     moves[table.getn(moves) + 1] = move
  15.     local nMove = table.getn(moves)
  16.     print(">> "..moves[nMove])
  17. end
  18.  
  19. local function recall()
  20.     local length = table.getn(moves)
  21.     for i=length,1,-1 do
  22.         local recall = moves[i]
  23.         if recall =="forward" then
  24.             turtle.back()
  25.         elseif recall =="back" then
  26.             turtle.forward()
  27.         elseif recall =="left" then
  28.             turtle.turnRight()
  29.         elseif recall =="right" then
  30.             turtle.turnLeft()
  31.         elseif recall =="up" then
  32.             turtle.down()
  33.         elseif recall =="down" then
  34.             turtle.up()
  35.         else
  36.             print("Program Failed!")
  37.         end
  38.     end
  39. end
  40.  
  41. local function send(sInput)
  42.     rednet.send(TrgtID,sInput,"Ans")
  43. end
  44.  
  45. local function update()
  46.     local bln,top = turtle.inspectUp()
  47.     if bln then
  48.         rednet.send(TrgtID,"Top: [X]| "..top.name,"BLS")
  49.     else
  50.         rednet.send(TrgtID,"Top: [ ]| minecraft:air","BLS")
  51.     end
  52.    
  53.     local bln,top = turtle.inspect()
  54.     if bln then
  55.         rednet.send(TrgtID,"Mid: [X]| "..top.name,"BLS")
  56.     else
  57.         rednet.send(TrgtID,"Mid: [ ]| minecraft:air","BLS")
  58.     end
  59.    
  60.     local bln,top = turtle.inspectDown()
  61.     if bln then
  62.         rednet.send(TrgtID,"Dow: [X]| "..top.name,"BLS")
  63.     else
  64.         rednet.send(TrgtID,"Dow: [ ]| minecraft:air","BLS")
  65.     end
  66.     rednet.send(TrgtID,turtle.getFuelLevel(),"FL")
  67.     rednet.send(TrgtID,turtle.getItemCount(1),"FL")
  68.    
  69. end
  70.     local function get()
  71.     sID,msg,prt = rednet.receive("CMD")
  72.     rednet.send(TrgtID,"RCV","Ans")
  73. end
  74.  
  75. connect()
  76. print("Please put fuel into first slot")
  77. while true do
  78. get()
  79. if msg =="forward" then
  80.         if turtle.forward() then
  81.             update()
  82.             save("forward")
  83.         else
  84.             update()
  85.         end
  86.     elseif msg =="back" then
  87.         if turtle.back() then
  88.             update()
  89.             save("back")
  90.         else
  91.             update()
  92.         end
  93.     elseif msg =="turnLeft" then
  94.         turtle.turnLeft()
  95.         update()
  96.         save("left")
  97.     elseif msg =="turnRight" then
  98.         turtle.turnRight()
  99.         update()
  100.         save("right")
  101.     elseif msg =="up" then
  102.         if turtle.up() then
  103.             update()
  104.             save("up")
  105.         else
  106.             update()
  107.         end
  108.     elseif msg =="down" then
  109.         if turtle.down() then
  110.             update()
  111.             save("down")
  112.         else
  113.             update()
  114.         end
  115.     elseif msg =="inspect" then
  116.         update()
  117.     elseif msg =="end" then
  118.         print("\n>> Connection terminated")
  119.         print(">> Moving back to starting point...")
  120.         recall()
  121.         break
  122.     elseif msg =="dig" then
  123.         turtle.dig()
  124.         update()
  125.     elseif msg =="digD" then
  126.         turtle.digDown()
  127.         update()
  128.     elseif msg =="digU" then
  129.         turtle.digUp()
  130.         update()
  131.     elseif msg =="refuel" then
  132.         turtle.refuel(1)
  133.         update()
  134.     elseif msg =="Nope" then
  135.         print("Not implemented")
  136.         update()
  137.     end
  138. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement