Advertisement
NekoLogi

Roofer.lua

Jan 30th, 2022 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  1. function Prepare(height)
  2.     print("Positioning for Roofing...")
  3.     for i=1,height do
  4.         while not turtle.up() do
  5.             turtle.digUp()
  6.         end
  7.     end
  8. end
  9.  
  10. function Done()
  11.     print("Finished roofing!")
  12.     print("Fuel remaining:")
  13.     print(turtle.getFuelLevel())
  14. end
  15.  
  16. function ResetPosition(width,height)
  17.     print("Moving back to starting position...")
  18.     turtle.turnRight()
  19.     for i=1,width do
  20.         while not turtle.forward() do
  21.             turtle.dig()
  22.         end
  23.     end
  24.     for i=1,height do
  25.         while not turtle.down() do
  26.             turtle.digDown()
  27.         end
  28.     end
  29.     turtle.turnLeft()
  30. end
  31.  
  32. function NextLine()
  33.     print("Preparing for next line...")
  34.     turtle.turnRight()
  35.     while not turtle.forward() do
  36.         turtle.dig()
  37.     end
  38.     turtle.turnRight()
  39. end
  40.  
  41. function TurnBack(length)
  42.     print("Returning...")
  43.     turtle.turnLeft()
  44.     turtle.turnLeft()  
  45.     for i=1,length do
  46.         while not turtle.forward() do
  47.             turtle.dig()
  48.         end
  49.     end
  50. end
  51.  
  52. function Roofing(length,width)
  53.     print("building roof...")
  54.     local stack = 0
  55.     local itemIndex = 2
  56.  
  57.     turtle.select(itemIndex)
  58.     for i=1,width do
  59.         for e=1,length do
  60.             if stack == 64 then
  61.                 itemIndex = itemIndex + 1
  62.                 turtle.select(itemIndex)
  63.                 stack = 0
  64.             end
  65.             if turtle.placeUp() then
  66.                 stack = stack + 1
  67.             end
  68.             while not turtle.forward() do
  69.                 turtle.dig()
  70.             end
  71.         end
  72.         TurnBack(length)
  73.         NextLine()
  74.     end
  75. end
  76.  
  77. function Start()
  78.     local roof = RequestInput()
  79.  
  80.     if (CheckBuildLimit(roof)) then
  81.         print("Area is too big!")
  82.         return
  83.     end
  84.     Prepare(roof[3])
  85.     Roofing(roof[1],roof[2])
  86.     ResetPosition(roof[2],roof[3])
  87.     Done()
  88. end
  89.  
  90. function CheckBuildLimit(roof)
  91.     if (roof[1] * roof[2]) + roof[3] > 64*15 then
  92.         return true
  93.     end
  94.     return false
  95. end
  96.  
  97. function RequestInput()
  98.     io.write("Enter length of roof:")
  99.     local length = io.read()
  100.     io.write("Enter width of roof:")
  101.     local width = io.read()
  102.     io.write("Enter height of roof (Excluding turtle position):")
  103.     local height = io.read()
  104.  
  105.     local roof = {tonumber(length),tonumber(width),tonumber(height)}
  106.  
  107.     return roof
  108. end
  109.  
  110. Start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement