ivanzrer

Untitled

Nov 2nd, 2024
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. args = {...}
  2. height = tonumber(args[1])
  3. desireSize = tonumber(args[2])
  4. if args[3] then
  5. hasType = true
  6. else
  7. hasType = false
  8. end
  9. workType = tostring(args[3])
  10. blocksUsed = 1
  11.  
  12.  
  13. -- Digs the required space for the build, one level
  14. function digSpace (n)
  15. for i=1, 4,1 do
  16. for i=1, n,1 do
  17. if turtle.detect() then
  18. turtle.dig()
  19. end
  20. turtle.forward()
  21. end
  22. turtle.turnRight()
  23. end
  24. end
  25.  
  26. -- Digging over multiple levels
  27. function digHole (height, desireSizeOver)
  28. desireReSized = desireSizeOver - 1
  29. for i=1, height,1 do
  30. digSpace(desireReSized)
  31. turtle.digUp()
  32. turtle.up()
  33. end
  34. for i=1, height,1 do
  35. turtle.down()
  36. end
  37. end
  38.  
  39. -- Builds a wall, one block tall, leaves the turtle at origin + 1
  40. function buildRoom (n)
  41. turtle.forward()
  42. turtle.turnLeft()
  43. turtle.turnLeft()
  44. for i=1, n-2,1 do
  45. placeBlock()
  46. turtle.back()
  47. print(i)
  48. end
  49. placeBlock()
  50. turtle.turnRight()
  51. turtle.back()
  52.  
  53. -- Builds one wall segment, used for second and third segment.
  54. function buildLine (length)
  55. for i=1, length-2,1 do
  56. placeBlock()
  57. turtle.back()
  58. end
  59. placeBlock()
  60. turtle.turnRight()
  61. turtle.back()
  62. end
  63.  
  64. buildLine(n)
  65. buildLine(n)
  66.  
  67. for i=1, n-3,1 do
  68. placeBlock()
  69. turtle.back()
  70. end
  71. placeBlock()
  72. turtle.up()
  73. turtle.placeDown()
  74. blocksUsed = blocksUsed + 1
  75. turtle.back()
  76. turtle.turnLeft()
  77. end
  78.  
  79. -- Runs the buildRoom funtion n times to achieve desired height.
  80. function buildWalls (height, desireSize)
  81. for i=1, height,1 do
  82. buildRoom(desireSize)
  83. end
  84. end
  85.  
  86. function placeBlock ()
  87. turtle.place()
  88. if turtle.getItemCount() < 1 then
  89. turtle.select(turtle.getSelectedSlot() + 1)
  90. end
  91. end
  92.  
  93. function usageText ()
  94. print("Usage: room [Height] [Length of walls] [-d (only digs) / -b (only builds)]")
  95. print("Example: 'room 2 4 -b' builds a room that is two blocks tall, four blocks long, but does NOT dig the required space")
  96. end
  97. -- check for argument usage
  98. if (height and desireSize) then
  99. if hasType then
  100. if (workType == "-d") or (workType == "-b") then
  101. if workType == "-d" then
  102. print("Digging...")
  103. digHole(height, desireSize)
  104. else
  105. print("Building...")
  106. buildWalls(height, desireSize)
  107. end
  108. else
  109. usageText()
  110. print("debug: failed worktype")
  111. end
  112. else
  113. print("Digging and building...")
  114. digHole(height, desireSize)
  115. buildWalls(height, desireSize)
  116. end
  117. else
  118. usageText()
  119. print("debug: no argument(s)")
  120. end
Advertisement
Add Comment
Please, Sign In to add comment