Advertisement
ravneravn

Return to surface

Aug 3rd, 2021 (edited)
731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.18 KB | None | 0 0
  1.  
  2.  
  3. local bot = {}
  4.  
  5. local function savePos()
  6.   local handle = fs.open("enderMine/savedFile", "w")
  7.   handle.write(textutils.serialize(bot))
  8.   handle.close()
  9. end
  10.  
  11. local function loadPos()
  12.   local files = fs.list("/rom/enderMine")
  13.   for i = 1, #files do
  14.     print(files[i])
  15.   end
  16.  
  17.   if fs.exists(filename) == true then
  18.     local handle = fs.open("enderMine/savedFile", "r")
  19.     readFile = handle.readLine()
  20.     if readFile ~= nil then
  21.       bot = textutils.unserialize(readFile)
  22.     end
  23.     handle.close()
  24.   else
  25.     print("file does not exist, check path..")
  26.   end
  27. end
  28.  
  29.  
  30. local function printPos()
  31.   term.clear()
  32.   term.setCursorPos(1,1)
  33.   print("------------")
  34.   print("x"..bot.currX)
  35.   print("z"..bot.currZ)
  36.   print("y"..bot.currY)
  37.   print("direction "..bot.direction)
  38.   print("layer "..bot.currLayer)
  39.   print("------------")
  40. end
  41.  
  42.  
  43. local function moveForward()
  44.   while not turtle.forward() do
  45.     turtle.dig()
  46.   end
  47.   savePos()
  48.   printPos()
  49. end
  50.  
  51. local function moveUp()
  52.   while not turtle.up() do
  53.     turtle.digUp()
  54.   end
  55.   bot.currY = bot.currY+1
  56.   savePos()
  57.   printPos()
  58. end
  59.  
  60. local function moveDown()
  61.   while not turtle.down() do
  62.     turtle.digDown()
  63.   end
  64.   bot.currY = bot.currY-1
  65.   savePos()
  66.   printPos()
  67. end
  68.  
  69. local function turnRight()
  70.   turtle.turnRight()
  71.   bot.direction = bot.direction +1
  72.   if bot.direction > 4 then
  73.     bot.direction = 1
  74.   end
  75.   savePos()
  76.   printPos()
  77. end
  78.  
  79. local function turnLeft()
  80.   turtle.turnLeft()
  81.   bot.direction = bot.direction -1
  82.   if bot.direction < 1 then
  83.     bot.direction = 4
  84.   end
  85.   savePos()
  86.   printPos()
  87. end
  88.  
  89.  
  90. local function gotoShaft() -- finder punktet hvor den gik ned "skakten"
  91.   while bot.direction ~= 3 do
  92.    turnRight()
  93.   end
  94.  
  95.   while bot.currX > 1 do
  96.    moveForward()
  97.    bot.currX = bot.currX -1
  98.    savePos()
  99.   end
  100.  
  101.   while bot.direction ~= 4 do
  102.    turnRight()
  103.   end
  104.  
  105.   while bot.currZ > 1 do
  106.    moveForward()
  107.    bot.currZ = bot.currZ -1
  108.    savePos()
  109.   end
  110.  
  111.   while bot.direction ~= 1 do
  112.    turnRight()
  113.   end
  114. end
  115.  
  116. local function toSurface()
  117.   while tonumber(bot.currY) < tonumber(bot.yStart) do
  118.           moveUp()
  119.   end
  120. end
  121.  
  122. loadPos()
  123. gotoShaft()
  124. toSurface()
  125.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement