Advertisement
HarvDad

walls3

Jun 23rd, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1.  
  2. version = "walls3: Rev 0.1"
  3. mission= "Place 3-block high walls at the length and width specified."
  4. instructions = "Place stack(s) of material starting in first slot."
  5.  
  6. args = {...}
  7. nArgs = #args
  8.  
  9. usage = "walls3 <length> <width>"
  10.  
  11. materialSlot = 1
  12.  
  13. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  14. print(version)
  15. print(mission)
  16. print(instructions)
  17. print(usage)
  18. return
  19. end
  20.  
  21. if nArgs ~= 2 then
  22. print(usage)
  23. return
  24. end
  25.  
  26. length = tonumber(args[1])
  27. if length == nil then
  28. print("\"", args[1], "\" is not a valid length")
  29. return
  30. end
  31. if length < 1 then
  32. print("length must be a positive number greater than zero")
  33. end
  34.  
  35. width = tonumber(args[2])
  36. if width == nil then
  37. print("\"", args[2], "\" is not a valid width")
  38. return
  39. end
  40. if width < 1 then
  41. print("width must be a positive number greater than zero")
  42. end
  43.  
  44. function place()
  45. ensureMaterial()
  46. turtle.place()
  47. end
  48.  
  49. function placeUp()
  50. ensureMaterial()
  51. turtle.placeUp()
  52. end
  53.  
  54. function placeDown()
  55. ensureMaterial()
  56. turtle.placeDown()
  57. end
  58.  
  59. function ensureMaterial()
  60. if turtle.getItemCount(materialSlot) < 3 then
  61. organizeMaterial()
  62. end
  63. if turtle.getItemCount(materialSlot) < 3 then
  64. print("No more material")
  65. return false
  66. end
  67. return true
  68. end
  69.  
  70. function organizeMaterial()
  71. local i
  72. materialCount = turtle.getItemCount(materialSlot)
  73.  
  74. if materialCount < 6 then
  75. -- print("Attempting to refill slot ", materialSlot)
  76. for i=2,12 do
  77. turtle.select(i)
  78. if turtle.compareTo(materialSlot) then
  79. turtle.transferTo(materialSlot)
  80. end
  81. end
  82. end
  83. turtle.select(materialSlot)
  84. end
  85.  
  86. function buildWall(length)
  87. for i=1,length do
  88. ensureMaterial()
  89. turtle.select(materialSlot)
  90. placeUp()
  91. placeDown()
  92. if i == length then
  93. turtle.turnLeft()
  94. end
  95. turtle.back()
  96. place()
  97. end
  98. end
  99.  
  100. turtle.turnLeft()
  101. turtle.turnLeft()
  102. turtle.up()
  103. buildWall(length)
  104. buildWall(length-1)
  105. buildWall(length-1)
  106. buildWall(length-2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement