Kulgan_Starkk

planeMaker

Mar 26th, 2014
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tArgs = { ... }
  2. local numBlocks = 0
  3.  
  4. local function pbBuildRow(length)
  5. if length > 0 then
  6. shell.run("go", "[_9_8_7_6_5_4_3_2_1f]" .. length-1)
  7. shell.run("go", "[_9_8_7_6_5_4_3_2_1]")
  8. else
  9. print("Plane length must be at least one")
  10. end
  11. end
  12.  
  13. local function pbCheckInventory()
  14. numBlocks = 0
  15. for j=1,9 do
  16. numBlocks = numBlocks + turtle.getItemCount(j)
  17. end
  18. if numBlocks < planeLength then
  19. print("Not enough blocks to complete the next row, please add more blocks to slots 1 through 9 and press a key to continue")
  20. while true do
  21. event = os.pullEvent()
  22. if event == "char" then
  23. pbCheckInventory()
  24. end
  25. end
  26. else
  27. return true
  28. end
  29. end
  30.  
  31. local function pbNextLayer()
  32. shell.run("go", "ua")
  33. end
  34.  
  35. local function pbNextRow(direction)
  36. if direction == 1 then
  37. shell.run("go", "rfr")
  38. else
  39. shell.run("go", "lfl")
  40. end
  41. end
  42.  
  43. if fs.exists("go") then
  44. if #tArgs < 2 or #tArgs > 4 then
  45. shell.run("clear")
  46. print("The number of parameters must be 2-4, first length then height, then optionally an orientation character, 'h' for horizontal, 'v' for vertical (default). Then the direction relative to the turtle for the plane to extend: l for left or 'r' for right (default).")
  47. return false
  48. end
  49.  
  50. planeLength = tonumber(tArgs[1])
  51. planeHeight = tonumber(tArgs[2])
  52. planeOrientation = "v"
  53. -- turn dir is specified by the parameter and represents the direction from the turtle's start position that the horizontal planes are placed in
  54. -- the decision whether to turn right or left at the end of a row is decided by the modulus of a division by 2 of the row count, modified by the turnDir
  55. turnDir = "r"
  56. -- turnDir has a default value, as does planeOrientation, but turnDir is only ever used when planeOrientation is set to horizontal
  57. if #tArgs > 2 then
  58. planeOrientation = tArgs[3]
  59. end
  60.  
  61. if #tArgs > 3 then
  62. turnDir = tArgs[4]
  63. end
  64.  
  65. -- For the 'height' aka depth dimension, do a row of the specified length of blocks
  66. for i=1,planeHeight do
  67. -- Place the row of blocks for the specified row length regardless of plane orientation
  68. pbCheckInventory()
  69. pbBuildRow(planeLength)
  70. -- If the orientation is vertical, call the function to continue the plane in that direction, and when coming to the end of the plane, go back to near the starting location
  71. if planeOrientation == "v" then
  72. pbNextLayer()
  73. -- If the orientation is horizontal, call the function to continue the plane in that direction, and when coming to the end of the plane, go back to near the starting location
  74. else
  75. if i < 2 then
  76. nextDirection = i%2
  77. nextDirection =
  78. if turnDir == "r" then
  79. pbNextRow((i+2)%2)
  80. else
  81. pbNextRow((i+1)%2)
  82. end
  83. end
  84. end
  85. else
  86. shell.run("clear")
  87. print("You must install rob's modified version of the 'go' utility program, located on pastebin at t0vyUwmt")
  88. end
Advertisement
Add Comment
Please, Sign In to add comment