kreezxil

buildspiral

Apr 28th, 2023
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.12 KB | None | 0 0
  1. local platformRadius = 10
  2. local height = 50
  3. local gap = 4
  4. local blockCount = 0
  5. local steps = 0
  6. local requiredFuel = 0.5 * (height/3 * (platformRadius + 0.5) ^ 2 - (height-gap)*(platformRadius + 0.5-gap)^2)
  7.  
  8. local chestSide = "front" -- set this to the side where the chest is located, e.g. "left", "right", "front", "back", or "up"
  9.  
  10. function move()
  11. while not turtle.forward() do
  12. turtle.dig()
  13. end
  14. end
  15.  
  16. function turnRight()
  17. turtle.turnRight()
  18. move()
  19. turtle.turnRight()
  20. end
  21.  
  22. function turnLeft()
  23. turtle.turnLeft()
  24. move()
  25. turtle.turnLeft()
  26. end
  27.  
  28. function buildLayer()
  29. for i = 1, platformRadius do
  30. turtle.placeDown()
  31. turnLeft()
  32. turtle.placeDown()
  33. turnRight()
  34. end
  35. end
  36.  
  37. function buildPlatform()
  38. print("Checking Fuel...")
  39. if turtle.getFuelLevel() < requiredFuel then
  40. print("Error: Not enough fuel to complete the platform!")
  41. return false
  42. end
  43.  
  44. print("Counting blocks needed...")
  45. local blocksNeeded = (height / gap) * platformRadius * 2
  46.  
  47. print("Blocks needed: ", blocksNeeded)
  48. print("Fuel needed: ", requiredFuel)
  49.  
  50. print("Building Platform...")
  51. while blockCount < height do
  52. buildLayer()
  53. blockCount = blockCount + (2 * platformRadius)
  54. platformRadius = platformRadius + gap
  55. steps = steps + 1
  56. if steps == 2 then -- adjust for the double layer in the first step
  57. platformRadius = platformRadius - 1
  58. end
  59. end
  60.  
  61. print("Returning to chest...")
  62. turtle.turnLeft()
  63. turtle.turnLeft()
  64.  
  65. while blockCount > 0 do
  66. turtle.digDown()
  67. move()
  68. blockCount = blockCount - 1
  69. if blockCount == 0 then
  70. for i = 1, 16 do -- loop through all inventory slots
  71. turtle.select(i)
  72. if turtle.getItemCount() > 0 then -- check if slot is not empty
  73. turtle.dropDown() -- drop item below
  74. end
  75. end
  76. turtle.refuel()
  77. platformRadius = 10 -- reset platform radius for new platform
  78. break
  79. end
  80. end
  81.  
  82. print("Restocking...")
  83. turtle.select(1) -- select the first slot
  84. turtle.suck() -- suck items from chest into inventory
  85. turtle.suckUp() -- suck fuel from chest into inventory
  86. return true
  87. end
  88.  
  89. print("Checking Fuel...")
  90. if turtle.getFuelLevel() < requiredFuel then
  91. print("Error: Not enough fuel to start the platform!")
  92. return
  93. end
  94.  
  95. while true do
  96. if buildPlatform() == false then
  97. print("Pausing for 30 seconds to allow restocking...")
  98. sleep(30)
  99. end
  100. end
Add Comment
Please, Sign In to add comment