Guest User

platform

a guest
Dec 3rd, 2012
13,048
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. local blocks = turtle.getItemCount(2)
  2.  
  3. for slot=3,16 do
  4. if turtle.compareTo(2) then
  5. blocks = blocks + turtle.getItemCount(slot)
  6. end
  7. end
  8.  
  9. size = math.floor(math.sqrt(blocks))
  10. sizeStr = tostring(size)
  11. print("Making a " .. sizeStr .. "x" .. sizeStr .. " platform")
  12.  
  13. function prevBlockSlot(curSlot)
  14. for slot=curSlot,2,-1 do
  15. turtle.select(slot)
  16. if turtle.compareTo(2) then
  17. return slot
  18. end
  19. end
  20. end
  21.  
  22. function forward(curSlot)
  23. if turtle.getFuelLevel() < 1 then
  24. select(1)
  25. turtle.refuel(1)
  26. turtle.select(curSlot)
  27. end
  28. for i=1,10 do
  29. if turtle.detect() then
  30. turtle.dig()
  31. end
  32. if turtle.forward() then
  33. return true
  34. end
  35. end
  36.  
  37. return nil
  38. end
  39.  
  40. function placeDown(curSlot)
  41. if not turtle.compareTo(2) then
  42. curSlot = prevBlockSlot(curSlot)
  43. end
  44. turtle.placeDown()
  45. return curSlot
  46. end
  47.  
  48. local curSlot = prevBlockSlot(16)
  49.  
  50. for row=1,size do
  51. for i=1,size-1 do
  52. curSlot = placeDown(curSlot)
  53. if not forward(curSlot) then
  54. print("Error: block in the way")
  55. return
  56. end
  57. end
  58. curSlot = placeDown(curSlot)
  59. if row%2 == 1 then
  60. turtle.turnRight()
  61. if not forward(curSlot) then
  62. print("Error: block in the way")
  63. return
  64. end
  65. turtle.turnRight()
  66. else
  67. turtle.turnLeft()
  68. if not forward(curSlot) then
  69. print("Error: block in the way")
  70. return
  71. end
  72. turtle.turnLeft()
  73. end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment