CelticCoder

fillBlock

Jan 23rd, 2024 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. os.loadAPI("buildSupport.lua")
  2. os.loadAPI("userInput.lua")
  3.  
  4.  
  5. -- make the turtle go down until it can't
  6. function goDown()
  7.     local blocksDown = 0
  8.     while turtle.down() do
  9.         blocksDown = blocksDown + 1
  10.     end
  11.     turtle.up()
  12.     return blocksDown
  13. end
  14.  
  15. -- make the turtle go up a certain number of blocks
  16. function goUp(blocks)
  17.     slot = 2
  18.     for i = 1, blocks do
  19.         turtle.up()
  20.         while not turtle.placeDown() and slot ~= 17 do
  21.             turtle.select(slot)
  22.             slot = slot + 1
  23.         end
  24.         if slot == 17 then
  25.             return 1
  26.         end
  27.     end
  28.     return 0
  29. end
  30.  
  31. function fillY(height)
  32.     goDown()
  33.     if goUp(height) == 1 then
  34.         return 1
  35.     else
  36.         return 0
  37.     end
  38. end
  39.  
  40. width = tonumber(userInput.getUserInput("Please Enter a Length: "))
  41. length = tonumber(userInput.getUserInput("Please Enter a Width: "))
  42. height = tonumber(userInput.getUserInput("Please Enter a Height: "))
  43.  
  44. print("Fuel And Blocks Cannot be Predicted")
  45. print("Fuel")
  46. print("currently: " .. turtle.getFuelLevel() .. " out of " .. turtle.getFuelLimit())
  47. print("or " .. (turtle.getFuelLevel()/turtle.getFuelLimit()) * 100 .. "%")
  48.  
  49. userInput.getUserInput("Press anything to continue: ")
  50.  
  51. turtle.forward()
  52. turtle.select(1)
  53. for i = 1, length do
  54.     for j = 1, width do
  55.         if fillY(height) == 1 then
  56.             os.exit(1)
  57.         end
  58.         if j < width then
  59.             turtle.forward()
  60.         end
  61.     end
  62.     if i < length then
  63.         if i % 2 == 0 then
  64.             turtle.turnLeft()
  65.             turtle.forward()
  66.             turtle.turnLeft()
  67.         else
  68.             turtle.turnRight()
  69.             turtle.forward()
  70.             turtle.turnRight()
  71.         end
  72.     end
  73. end
Advertisement
Add Comment
Please, Sign In to add comment