Advertisement
princejoogie

mine.lua

Dec 9th, 2022 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. rednet.open("right")
  2. print("mine.lua running")
  3. print("#ID: " .. os.getComputerID())
  4.  
  5. local path = {}
  6.  
  7. -- FUNCTIONS
  8.  
  9. function fwd()
  10.     while not turtle.forward() do
  11.         turtle.dig()
  12.     end
  13. end
  14.  
  15. function back()
  16.     turtle.turnRight()
  17.     turtle.turnRight()
  18.     fwd()
  19.     turtle.turnRight()
  20.     turtle.turnRight()
  21. end
  22.  
  23. function right()
  24.     turtle.turnRight()
  25.     fwd()
  26.     turtle.turnLeft()
  27. end
  28.  
  29. function left()
  30.     turtle.turnLeft()
  31.     fwd()
  32.     turtle.turnRight()
  33. end
  34.  
  35. function up()
  36.     while not turtle.up() do
  37.         turtle.digUp()
  38.     end
  39. end
  40.  
  41. function down()
  42.     while not turtle.down() do
  43.         turtle.digDown()
  44.     end
  45. end
  46.  
  47.  
  48. function addPath(m)
  49.     path[#path + 1] = m
  50. end
  51.  
  52. function returnHome()
  53.     for i = #path, 1, -1 do
  54.         if path[i] == "f" then
  55.             back()
  56.         elseif path[i] == "b" then
  57.             fwd()
  58.         elseif path[i] == "r" then
  59.             left()
  60.         elseif path[i] == "l" then
  61.             right()
  62.         elseif path[i] == "u" then
  63.             down()
  64.         elseif path[i] == "d" then
  65.             up()
  66.         end
  67.  
  68.         table.remove(path, i)
  69.     end
  70.  
  71.     path = {}
  72. end
  73.  
  74. function main()
  75.     while true do
  76.         local _, msg = rednet.receive()
  77.  
  78.         if msg == "stop" then
  79.             break
  80.         elseif msg == "return" then
  81.             returnHome()
  82.         elseif msg == "f" then
  83.             fwd()
  84.             addPath("f")
  85.         elseif msg == "b" then
  86.             back()
  87.             addPath("b")
  88.         elseif msg == "r" then
  89.             right()
  90.             addPath("r")
  91.         elseif msg == "l" then
  92.             left()
  93.             addPath("l")
  94.         elseif msg == "u" then
  95.             up()
  96.             addPath("u")
  97.         elseif msg == "d" then
  98.             down()
  99.             addPath("d")
  100.         end
  101.  
  102.         -- print("(x: " .. currPos.x .. " y: " .. currPos.y .. " z: " .. currPos.z .. ")")
  103.     end
  104. end
  105.  
  106. main()
  107. print("mine.lua exited")
  108. rednet.close()
  109.  
Tags: turtle code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement