Advertisement
Padilk

test

Aug 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. x=0 --R/L
  2. y=0 --U/D
  3. z=0 --fwd/bck
  4. rot=0
  5.  
  6. function rotate(direction)
  7. if rot==0 and direction == 3 then
  8. rot=4
  9. end
  10. if rot==3 and direction == 0 then
  11. rot=-1
  12. end
  13. while rot<direction do rot = rot+1 turtle.turnRight() end
  14. while rot>direction do rot = rot-1 turtle.turnLeft() end
  15. end
  16.  
  17. function move(direction,dist)
  18. rotate(direction)
  19. while dist>0 do
  20. while not turtle.forward() do os.sleep(1) end
  21. dist = dist-1
  22. if rot == 0 then z = z+1 end
  23. if rot == 1 then x = x+1 end
  24. if rot == 2 then z = z-1 end
  25. if rot == 3 then x = x-1 end
  26. end
  27. end
  28.  
  29. function moveV(dist)
  30. while dist>0 do
  31. if not turtle.up() then return false end
  32. dist = dist-1
  33. y = y+1
  34. end
  35. while dist<0 do
  36. if not turtle.down() then return false end
  37. dist = dist+1
  38. y = y-1
  39. end
  40. return true
  41. end
  42.  
  43. function moveTo(tx,ty,tz)
  44. r=0
  45. if z<tz then r=0 else r=2 end
  46. d = math.abs(tz-z)
  47. move(r,d)
  48. if x<tx then r=1 else r=3 end
  49. d = math.abs(tx-x)
  50. move(r,d)
  51. moveV(ty-y)
  52. end
  53.  
  54. function khuyam()
  55. --[[if turtle.detectUp() then
  56. turtle.digUp()
  57. moveV(1)
  58. khuyam()
  59. moveV(-1)
  60. end
  61. dirs = {0,1,3,2}
  62. for i=0,3 do
  63. rotate(dirs[i+1])
  64. if turtle.detect() then
  65. turtle.dig()
  66. move(dirs[i+1],1)
  67. khuyam()
  68. move(dirs[i+1]+2%4,1)
  69. end
  70. end
  71. --]]
  72. end
  73.  
  74. rowLen=4
  75. colLen=2
  76.  
  77. moveTo(0,0,3)
  78. turtle.select(1)
  79. for j=0,(colLen-1) do
  80. moveTo(-3*j-1,0,3)
  81. for i=0,(rowLen-1) do
  82. moveTo(-1-3*j,0,4+3*i)
  83. rotate(3)
  84. if not turtle.detect() then
  85. turtle.place()
  86. else
  87. repr = moveV(1)
  88. if turtle.detect() or repr==false then
  89. shell.run("chop")
  90. if repr then
  91. moveV(-1)
  92. end
  93. rotate(3)
  94. turtle.dig()
  95. turtle.place()
  96. else
  97. moveV(-1)
  98. end
  99. end
  100. end
  101. moveTo(-3*j-1,0,3)
  102. end
  103. moveTo(0,0,0)
  104. rotate(0)
  105. print("X: "..x)
  106. print("Y: "..y)
  107. print("Z: "..z)
  108. for i=2,16 do
  109. turtle.select(i)
  110. turtle.dropDown()
  111. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement