Legrandfifou

autobuild

Nov 14th, 2014
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. --Turtle AutoBuilder v0.2
  2. --Created by pokemonmegaman, 2012
  3. --Uses files from BINVOX to create 3D models in game
  4. --Better put alot of materials in this, because it uses a TON.
  5. --
  6. --Changelog
  7. --v0.3: Turtle now returns to ground if it needs materials
  8. --v0.2.1: Reversed build direction to stop mirroring, as well as future development
  9. --v0.2: Stopped turtle from going up if there are no blocks to place, reducing build time signifigantly
  10. --v0.1: Initial release
  11.  
  12. --Declarations
  13. local x = 0
  14. local y = 0
  15. local z = 0
  16. local turtlex = 0
  17. local turtley = 0
  18. local turtlez = 0
  19. local size = {}
  20. local file = io.open("voxels.txt", "r")
  21. local s = file:read("*l")
  22. local sizestr = file:read("*l")
  23. local line = nil
  24. local blockarray = {}
  25. --Gets size of model
  26. for k, v in string.gmatch(sizestr, "%d+") do
  27. size = tonumber(k)
  28. end
  29. --We do this to move the "cursor" to the data
  30. s = file:read("*l")
  31. s = file:read("*l")
  32. s = file:read("*l")
  33. --And now we parse the file, line by line.
  34.  
  35.  
  36.  
  37.  
  38. while x < size do
  39. while y < size do
  40. line = file:read("*l")
  41. a = 0
  42.  
  43. for k in line:gmatch('%d+') do --Dumps line into an array
  44. a = a + 1
  45. blockarray[a] = k
  46. end
  47.  
  48. while z < size do
  49. z = z + 1
  50. if blockarray[z] == "1" then
  51. while turtlez < z do
  52. turtle.up()
  53. turtlez = turtlez + 1
  54. end
  55. turtle.place()
  56. if turtle.getItemCount(9) == 0 then
  57. local k = 0
  58. while turtle.detectDown() == false do
  59. k = k + 1
  60. turtle.down()
  61. end
  62. print("Please reload me with more items! (Press enter when done.)")
  63. io.read()
  64. while k > 0 do
  65. turtle.up()
  66. k = k - 1
  67. end
  68. end
  69. end
  70. end
  71. turtle.back()
  72. y = y + 1
  73.  
  74. while turtlez > 0 do
  75. turtle.down()
  76. turtlez = turtlez - 1
  77. end
  78. z = 0
  79. end
  80. turtle.turnLeft()
  81. turtle.back()
  82. x = x + 1
  83. turtle.turnRight()
  84. while y > 0 do
  85. turtle.forward()
  86. y = y - 1
  87. end
  88. end
Advertisement
Add Comment
Please, Sign In to add comment