Advertisement
posicat

/placeBlocks

Sep 10th, 2024 (edited)
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. --File: /placeBlocks
  2.  
  3. dofile("/cattech/common.lua")
  4.  
  5. function placeBlockEveryX(mvFwd,itemList)
  6.  
  7. local continue=true
  8. while continue do
  9. refuelIfNeeded(10)
  10.  
  11. local placeItem = selectTurtleItemByList(itemList)
  12. if (placeItem) then
  13. if placeItemByList(itemList,"down") then
  14. -- print("Placed")
  15. else
  16. print("Could not place " .. table.concat(itemList))
  17. end
  18.  
  19. for i = 1, mvFwd do
  20. if turtle.detect() then
  21. print("Obstacle detected! Stopping.")
  22. continue = false
  23. else
  24. turtle.forward()
  25. end
  26. end
  27. else
  28. print("Out of item " .. table.concat(itemList))
  29. continue = false
  30. end
  31.  
  32. end
  33. end
  34.  
  35.  
  36.  
  37. -- Main program
  38.  
  39. if #arg < 1 then
  40. print("Usage: placeBlocks <number_of_spaces>")
  41. else
  42. local spaces = tonumber(arg[1]) -- Get the first argument
  43. local itemDetail = turtle.getItemDetail(1)
  44.  
  45. if itemDetail then
  46. local itemList = {itemDetail.name};
  47. print("Placing : " .. table.concat(itemList))
  48. placeBlockEveryX(spaces,itemList) -- Call the function with the given spaces
  49. else
  50. print("No item in slot 1, stopping!")
  51. end
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement