Advertisement
BillBodkin

AutoBuild

Dec 25th, 2016
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 0 0
  1. local dom = "http://tools.cablepost.co.uk"
  2.  
  3. --Turtle AutoBuilder v0.2
  4. --Created by pokemonmegaman, 2012
  5. --Uses files from BINVOX to create 3D models in game
  6. --Better put alot of materials in this, because it uses a TON.
  7. --
  8. --Changelog
  9. --v0.3: Turtle now returns to ground if it needs materials
  10. --v0.2.1: Reversed build direction to stop mirroring, as well as future development
  11. --v0.2: Stopped turtle from going up if there are no blocks to place, reducing build time signifigantly
  12. --v0.1: Initial release
  13.  
  14. --there are also a couple of mods by BillBodkin
  15. local arg = { ... }
  16. local model = arg[1]
  17.  
  18. local content = http.get(dom .. "/cc/binvox/" .. model).readAll()
  19. if not content then
  20.       error("Could not connect to website")
  21. end
  22. f = fs.open(model, "w")
  23. f.write(content)
  24. f.close()
  25.  
  26.  
  27. --Declarations
  28. local x = 0
  29. local y = 0
  30. local z = 0
  31. local turtlex = 0
  32. local turtley = 0
  33. local turtlez = 0
  34. local size = {}
  35. local file = io.open(model, "r")
  36. local s = file:read("*l")
  37. local sizestr = file:read("*l")
  38. local line = nil
  39. local blockarray = {}
  40. --Gets size of model
  41.      for k, v in string.gmatch(sizestr, "%d+") do
  42.        size = tonumber(k)
  43.      end
  44. --We do this to move the "cursor" to the data
  45. s = file:read("*l")
  46. s = file:read("*l")
  47. s = file:read("*l")
  48. --And now we parse the file, line by line.
  49.  
  50.  
  51.  
  52.  
  53. while x < size do
  54.     while y < size do
  55.         line = file:read("*l")
  56.         a = 0
  57.        
  58.         for k in line:gmatch('%d+') do --Dumps line into an array
  59.             a = a + 1
  60.             blockarray[a] = k
  61.         end
  62.        
  63.         while z < size do
  64.             z = z + 1
  65.             if blockarray[z] == "1" then
  66.                 while turtlez < z do
  67.                     turtle.up()
  68.                     turtlez = turtlez + 1
  69.                 end
  70.                 for i = 1, 16 do
  71.                     if turtle.getItemCount(i) == 0 then
  72.                         if i == 16 then
  73.                             print("Please reload me with more items!  (Press enter when done.)")
  74.                             io.read()
  75.                             turtle.select(1)
  76.                         else
  77.                             turtle.select(i+1)
  78.                         end
  79.                     else
  80.                         turtle.place()
  81.                     end
  82.                 end
  83.                 --turtle.place()
  84.                 if turtle.getItemCount(16) == 0 then
  85.                     local k = 0
  86.                     while turtle.detectDown() == false do
  87.                         k = k + 1
  88.                         turtle.down()
  89.                     end
  90.                     print("Please reload me with more items!  (Press enter when done.)")
  91.                     --io.read()
  92.                     while k > 0 do
  93.                         turtle.up()
  94.                         k = k - 1
  95.                     end
  96.                 end
  97.             end
  98.         end
  99.         turtle.back()
  100.         y = y + 1
  101.        
  102.         while turtlez > 0 do
  103.             turtle.down()
  104.             turtlez = turtlez - 1
  105.         end
  106.         z = 0
  107.     end
  108.     turtle.turnLeft()
  109.     turtle.back()
  110.     x = x + 1
  111.     turtle.turnRight()
  112.     while y > 0 do
  113.         turtle.forward()
  114.         y = y - 1
  115.     end
  116. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement