Advertisement
Tanoro

Turtle buildBox

Feb 23rd, 2014
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. -- pastebin get QfSCbRgH buildBox
  2.  
  3. -- Ask how each side is
  4. print("How many blocks per side?")
  5. local side = io.read()
  6. side = tonumber(side)
  7.  
  8. local blocksNeeded = (side * 2) + ((side - 2) * 2)
  9.  
  10. print("I will need " .. blocksNeeded .. " blocks.")
  11. print("Type 'Start' when ready")
  12.  
  13. local go = io.read()
  14.  
  15. local blockCount = side - 1
  16. local selected = 1
  17. local fuel = 16 -- Put some coal into the bottom-right cell
  18. local itemCount = turtle.getItemCount(selected)
  19.  
  20. --[[
  21. * Check to see if refueling is needed
  22. ]]
  23. local function ifRefuel()
  24. if turtle.getFuelLevel() < side then
  25. turtle.select(fuel)
  26. turtle.refuel(1)
  27. turtle.select(selected)
  28. end
  29. end
  30.  
  31. if go == "Start" then
  32. -- Do we need to step up?
  33. if turtle.detectDown() then
  34. ifRefuel()
  35. turtle.up()
  36. end
  37.  
  38. -- Select the starting cell
  39. turtle.select(selected)
  40.  
  41. local s = 0
  42. local j = 0
  43. while s < 4 do
  44. -- Prepare turtle ro do one side of the box
  45. turtle.select(selected)
  46. ifRefuel()
  47.  
  48. if s == 3 then
  49. -- Last side
  50. blockCount = blockCount - 1
  51. end
  52.  
  53. j = 0
  54. while j < blockCount do
  55. -- Are we clear to place something?
  56. if turtle.detectDown() then
  57. turtle.digDown()
  58. end
  59.  
  60. -- Place block
  61. turtle.placeDown()
  62.  
  63. -- Step forward
  64. if turtle.detect() then
  65. turtle.dig()
  66. end
  67.  
  68. turtle.forward()
  69.  
  70. itemCount = turtle.getItemCount(selected)
  71.  
  72. if itemCount == 0 then
  73. -- Out of items; Switch cells
  74. selected = selected + 1
  75. turtle.select(selected)
  76. end
  77.  
  78. j = j + 1
  79. end
  80.  
  81. if s < 3 then
  82. -- Prepare for the next side
  83. turtle.turnLeft()
  84. end
  85.  
  86. s = s + 1
  87. end
  88.  
  89. -- Place the last block to complete the box
  90. if turtle.detectDown() then
  91. turtle.digDown()
  92. end
  93.  
  94. turtle.placeDown()
  95. turtle.forward()
  96. else
  97. print("Terminating")
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement