Advertisement
kreezxil

spire

May 3rd, 2023 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. -- spire.lua
  2. -- A program to build a spire using a turtle
  3. -- Requires a chest with fuel and building materials next to the turtle
  4.  
  5. local height = 100 -- the height of the spire
  6. local floor = 10 -- the interval of floors
  7. local iron = 1 -- the slot for iron blocks
  8. local copper = 2 -- the slot for copper blocks
  9. local diamond = 3 -- the slot for diamond blocks
  10.  
  11. -- Refuel from the chest if needed
  12. function refuel()
  13. if turtle.getFuelLevel() < 10 then
  14. turtle.turnLeft()
  15. turtle.suck()
  16. turtle.refuel()
  17. turtle.turnRight()
  18. end
  19. end
  20.  
  21. -- Select a slot and place a block
  22. function place(slot)
  23. turtle.select(slot)
  24. turtle.placeDown()
  25. end
  26.  
  27. -- Build one layer of the spire
  28. function layer()
  29. place(iron)
  30. turtle.forward()
  31. place(copper)
  32. turtle.forward()
  33. place(iron)
  34. turtle.turnRight()
  35. turtle.forward()
  36. place(copper)
  37. turtle.forward()
  38. place(iron)
  39. turtle.turnRight()
  40. end
  41.  
  42. -- Build one floor of the spire
  43. function floor()
  44. for i = 1, 4 do
  45. layer()
  46. end
  47. end
  48.  
  49. -- Build a staircase to the next floor
  50. function stairs()
  51. turtle.up()
  52. place(iron)
  53. turtle.forward()
  54. place(copper)
  55. turtle.up()
  56. end
  57.  
  58. -- Build the spire
  59. function spire()
  60. for i = 1, height do
  61. refuel()
  62. if math.mod(i,floor) == 0 then
  63. floor()
  64. stairs()
  65. else
  66. place(iron)
  67. turtle.up()
  68. end
  69. end
  70. place(diamond) -- top off with a diamond block
  71. end
  72.  
  73. spire() -- start the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement