Advertisement
HarvDad

pillars

Oct 1st, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1.  
  2. args = {...}
  3. nArgs = #args
  4.  
  5. version = "pillar: Rev 0.1"
  6.  
  7.  
  8. materialSlot = 1
  9. spacing = 8
  10.  
  11. function placePillar()
  12. local y = 0
  13.  
  14. while turtle.down() do
  15. y = y-1
  16. if y < -20 then
  17. break
  18. end
  19. end
  20.  
  21. turtle.select(1)
  22. while y < 0 do
  23. turtle.up()
  24. if ensureMaterial() then
  25. turtle.placeDown()
  26. end
  27. y = y+1
  28. end
  29. end
  30.  
  31. function forward(nBlocks)
  32. local i = 0
  33. for i=1,nBlocks do
  34. turtle.forward()
  35. end
  36. end
  37.  
  38. function ensureMaterial()
  39. if turtle.getItemCount(materialSlot) < 3 then
  40. organizeMaterial()
  41. end
  42. if turtle.getItemCount(materialSlot) < 3 then
  43. print("No more material")
  44. return false
  45. end
  46. return true
  47. end
  48.  
  49. function organizeMaterial()
  50. local i
  51. materialCount = turtle.getItemCount(materialSlot)
  52.  
  53. if materialCount < 3 then
  54. for i=2,16 do
  55. turtle.select(i)
  56. if turtle.compareTo(materialSlot) then
  57. turtle.transferTo(materialSlot)
  58. end
  59. end
  60. end
  61. turtle.select(materialSlot)
  62. end
  63.  
  64. -- ================= Main Program ===================
  65.  
  66. if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
  67. print(version)
  68. print("Fill all slots with building material.")
  69. return
  70. end
  71.  
  72. --[[
  73. if nArgs < 2 or nArgs > 3 then
  74. print(usage)
  75. return
  76. end
  77. --]]
  78.  
  79. nPillars = tonumber(args[1])
  80. if nPillars == nil then
  81. print("\"", args[1], "\" is not a valid number.")
  82. return
  83. end
  84. if nPillars < 1 then
  85. print("Number of pillars must be a positive integer.")
  86. end
  87.  
  88. for i=1,nPillars do
  89. placePillar()
  90. if i < nPillars then
  91. forward(spacing)
  92. end
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement