Advertisement
asweigart

twitch build wall

Oct 10th, 2016
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. local function quitIfNoFuel()
  2. if turtle.getFuelLevel() == 0 then
  3. error('Out of fuel.')
  4. end
  5. end
  6.  
  7. local function countItem(name)
  8. local total = 0
  9. for slot = 1, 16 do
  10. local itemDetail = turtle.getItemDetail(slot)
  11. if itemDetail ~= nil then
  12. if itemDetail['name'] == name then
  13. total = total + itemDetail['count']
  14. end
  15. end
  16. end
  17. return total
  18. end
  19.  
  20. local function selectItem(name)
  21. local slot
  22. for slot = 1, 16 do
  23. local itemDetail = turtle.getItemDetail(slot)
  24. if itemDetail ~= nil then
  25. if itemDetail['name'] == name then
  26. turtle.select(slot)
  27. return true
  28. end
  29. end
  30. end
  31. return false
  32. end
  33.  
  34.  
  35.  
  36. local cmdArgs = {...}
  37.  
  38. local LENGTH = tonumber(cmdArgs[1])
  39. local HEIGHT = tonumber(cmdArgs[2])
  40. if cmdArgs[2] == nil then
  41. print('Usage: buildwall <length> <height>')
  42. return
  43. end
  44.  
  45. local numStoneBrick = countItem('minecraft:stonebrick')
  46. if LENGTH * HEIGHT > numStoneBrick then
  47. print('You have ' .. numStoneBrick .. ' bricks.')
  48. print('You need ' .. (LENGTH * HEIGHT) .. ' to build this wall.')
  49. return
  50. end
  51.  
  52.  
  53. quitIfNoFuel()
  54. turtle.up()
  55. local curHeight, curLength
  56.  
  57. for curHeight = 1, HEIGHT do
  58. for curLength = 1, LENGTH do
  59. quitIfNoFuel()
  60. selectItem('minecraft:stonebrick')
  61. if turtle.placeDown() == false then
  62. error('Could not place blocks')
  63. end
  64.  
  65. if curLength ~= LENGTH then
  66. if curHeight % 2 == 0 then
  67. turtle.back()
  68. else
  69. turtle.forward()
  70. end
  71. end
  72. end
  73.  
  74. if curHeight ~= HEIGHT then
  75. turtle.up()
  76. end
  77. end
  78.  
  79. -- move to the end of the wall
  80. if HEIGHT % 2 == 0 then
  81. for i = 1, LENGTH - 1 do
  82. turtle.forward()
  83. end
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement