Advertisement
neo34rd

room.lua

Mar 24th, 2019
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. os.loadAPI("transformation")
  2. os.loadAPI("move")
  3. t = transformation.newTransform()
  4.  
  5. local tArgs = {...}
  6. if #tArgs ~= 3 then
  7. print("Requires width, length, height")
  8. return
  9. end
  10.  
  11. local x = tonumber(tArgs[1])
  12. local z = tonumber(tArgs[2])
  13. local y = tonumber(tArgs[3])
  14.  
  15. if x == nil or z == nil or y == nil then
  16. print("Invalid dimensions")
  17. return
  18. end
  19.  
  20. if x < 0 or z < 0 or y < 0 then
  21. print("Invalid (negative) dimensions")
  22. return
  23. end
  24.  
  25. local fuel = turtle.getFuelLevel()
  26. local roomSize = x * z * y
  27. while fuel < roomSize do
  28. if not turtle.refuel(1) then
  29. print("Not enough fuel")
  30. return
  31. end
  32. end
  33.  
  34. os.loadAPI("transformation")
  35. t = transformation.newTransform()
  36.  
  37. function digClear()
  38. while turtle.detect() do
  39. turtle.dig()
  40. end
  41. return true
  42. end
  43.  
  44. function digClearUp()
  45. while turtle.detectUp() do
  46. turtle.digUp()
  47. end
  48. return true
  49. end
  50.  
  51. x = x - 1
  52. z = z - 1
  53. --if z == 0 then
  54. --z = 1
  55. --end
  56. --
  57. y = y - 1
  58. --if y == 0 then
  59. -- y = 1
  60. --end
  61.  
  62. turnLeft = transformation.turnLeft
  63. turnRight = transformation.turnRight
  64.  
  65. for yI = 0, y do
  66. for zI = 0, z do
  67.  
  68. turn = turnLeft
  69. count = (yI * z) + zI
  70. if count % 2 == 0 then
  71. turn = turnRight
  72. end
  73.  
  74. move.lineMotionDoWhile(t, x, digClear)
  75.  
  76. if zI < z then
  77. turn(t)
  78. digClear()
  79. transformation.forward(t)
  80. turn(t)
  81. end
  82.  
  83. end
  84.  
  85. if yI < y then
  86. digClearUp()
  87. transformation.up(t)
  88. end
  89. transformation.turnAround(t)
  90.  
  91. end
  92.  
  93. transformation.gotoPosition(t, vector.makeZero())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement