LDDestroier

Turtle Place Wall Blocks fuck

May 2nd, 2022 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. local tArg = {...}
  2.  
  3. local height = tonumber(tArg[1] or "") or 45
  4. local length = tonumber(tArg[2] or "") or 30
  5.  
  6. turtle.refuel(64)
  7. turtle.select(1)
  8.  
  9. local saveFile = "lastpos.dat"
  10.  
  11. local saveState = function(x, y)
  12.     local file = fs.open(saveFile, "w")
  13.     file:writeLine(x)
  14.     file:writeLine(y)
  15.     file.close()
  16. end
  17.  
  18.  
  19. local loadState = function()
  20.     local file = fs.open(saveFile, "r")
  21.     local x = tonumber(file:readLine())
  22.     local y = tonumber(file:readLine())
  23.     file.close()
  24.     return x, y
  25. end
  26.  
  27. local function place()
  28.     if turtle.getItemCount() == 0 then
  29.         for i = 1, 16 do
  30.             if turtle.getItemCount(i) > 0 then
  31.                 turtle.select(i)
  32.                 turtle.placeDown()
  33.                 return true
  34.             end
  35.         end
  36.     else
  37.         turtle.placeDown()
  38.         return true
  39.     end
  40.     return false
  41. end
  42.  
  43. local function goUp()
  44.     repeat until turtle.up()
  45. end
  46.  
  47. local function goForward()
  48.     repeat until turtle.forward()
  49. end
  50.  
  51. local function goBack()
  52.     repeat until turtle.forward()
  53. end
  54.  
  55. local startX, startY
  56.  
  57. if fs.exists(saveFile) then
  58.     print("Save file found.")
  59.     startX, startY = loadState()
  60. else
  61.     goUp()
  62. end
  63.  
  64. for y = startY or 1, height - 1 do
  65.     for x = startX or 1, length do
  66.         saveState()
  67.         if not place() then
  68.             print("Ran out of shit. Fuck you")
  69.             print("Please insert more shit")
  70.             repeat
  71.                 sleep(0.5)
  72.             until place()
  73.             print("Cheers")
  74.         end
  75.         if x ~= length then
  76.             if y % 2 == 1 then
  77.                 turtle.forward()
  78.             else
  79.                 turtle.back()
  80.             end
  81.         end
  82.     end
  83.     if y ~= height - 1 then
  84.         goUp()
  85.     end
  86.     startX = 1
  87. end
  88.  
  89. print("All done.")
  90. fs.delete(saveFile)
Add Comment
Please, Sign In to add comment