Kulgan_Starkk

planeMaker

Mar 26th, 2014
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  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. local input = read("*")
  21. pbCheckInventory()
  22. else
  23. return true
  24. end
  25. end
  26.  
  27. local function pbNextLayer()
  28. shell.run("go", "ua")
  29. end
  30.  
  31. local function pbNextRow(direction)
  32. if direction == 1 then
  33. shell.run("go", "rfr")
  34. else
  35. shell.run("go", "lfl")
  36. end
  37. end
  38.  
  39. if fs.exists("go") then
  40. if #tArgs < 2 or #tArgs > 4 then
  41. shell.run("clear")
  42. 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).")
  43. return false
  44. end
  45.  
  46. planeLength = tonumber(tArgs[1])
  47. planeHeight = tonumber(tArgs[2])
  48. planeOrientation = "v"
  49. -- turn dir is specified by the parameter and represents the direction from the turtle's start position that the horizontal planes are placed in
  50. -- 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
  51. turnDir = "r"
  52. -- turnDir has a default value, as does planeOrientation, but turnDir is only ever used when planeOrientation is set to horizontal
  53. if #tArgs > 2 then
  54. planeOrientation = tArgs[3]
  55. end
  56.  
  57. if #tArgs > 3 then
  58. turnDir = tArgs[4]
  59. end
  60.  
  61. -- For the 'height' aka depth dimension, do a row of the specified length of blocks
  62. for i=1,planeHeight do
  63. -- Place the row of blocks for the specified row length regardless of plane orientation
  64. pbCheckInventory()
  65. pbBuildRow(planeLength)
  66. -- 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
  67. if planeOrientation == "v" then
  68. pbNextLayer()
  69. -- 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
  70. else
  71. if turnDir == "r" then
  72. pbNextRow((i+2)%2)
  73. else
  74. pbNextRow((i+1)%2)
  75. end
  76. end
  77. end
  78. else
  79. shell.run("clear")
  80. print("You must install rob's modified version of the 'go' utility program, located on pastebin at t0vyUwmt")
  81. end
Advertisement
Add Comment
Please, Sign In to add comment