Kagee

build-3d

May 1st, 2013
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.30 KB | None | 0 0
  1. os.loadAPI("libstruct")
  2. b=libstruct
  3. a=aware
  4. args = {...}
  5.  
  6. if #args < 1 then
  7.     error("Arguments: <name>")
  8. end
  9.  
  10. t=b.load(args[1]..".3d")
  11. height=t["height"]
  12. width=t["width"]
  13. depth=t["depth"]
  14. endblock=t["endblock"]
  15. parwidth=(width %2 == 0) -- width er partall
  16. moveleft=true
  17. a.setposition("start")
  18.  
  19. function refill(r)
  20.     if r == nil  then
  21.         print("refill got r == nil")
  22.         return
  23.     end
  24.     if r == 0  then return end
  25.     if turtle.getItemCount(r) > 5 then return end
  26.     if not (endblock==16) then
  27.             turtle.select(r)
  28.             for i=endblock+1,16 do
  29.                     if turtle.compareTo(i) then
  30.                             turtle.select(i)
  31.                             turtle.transferTo(r)
  32.                             free=turtle.getItemSpace(r)
  33.                     end
  34.                     turtle.select(r)
  35.                     if free == 0 then
  36.                             break
  37.                     end
  38.             end
  39.     end
  40.         if turtle.getItemCount(r) < 2 then
  41.         print("Sleeping while waiting for refill for slot " .. r)  
  42.         while (turtle.getItemCount(r) < 2) do
  43.                 os.sleep(15)
  44.             end
  45.     end
  46. end
  47.  
  48. function line()
  49.         print("Building line")
  50.         for d=0,depth do
  51.                 pos = a.getposition("current")
  52.                 print("Pos: h" .. pos[3]*-1 .. "-w" .. pos[1] .. "-d" .. pos[2])
  53.         block = t[pos[3]*-1][pos[1]][pos[2]]
  54.         refill(block)
  55.         b.place(block)
  56.                 if(d<depth) then
  57.                         a.df()
  58.                 end
  59.         end
  60. end
  61.  
  62.  
  63. function turn()
  64.         if(moveleft) then
  65.                 print("Moving left")
  66.                 a.l()
  67.                 a.df()
  68.                 a.l()
  69.         else
  70.                 print("Moving right")
  71.                 a.r()
  72.                 a.df()
  73.                 a.r()
  74.         end
  75.         moveleft = not moveleft
  76. end
  77.  
  78. function layer()
  79.     print("Building layer")
  80.     for w=0,width do
  81.         line()
  82.             if(w<width) then
  83.                 turn()
  84.             end
  85.     end
  86. end
  87.  
  88. -- we build from the bottom up
  89. for h=0,height-1 do
  90.     a.dd()
  91. end
  92.  
  93. for h=0,height do
  94.     layer()
  95.     if not (h == height) then
  96.         a.du()
  97.         b.t180()
  98.         if parwidth then
  99.             if h%2 == 0 then
  100.                 turnleft=false
  101.             else
  102.                 turnleft=true  
  103.             end
  104.         else
  105.             turnleft=true
  106.         end
  107.     end
  108. end
  109.  
  110. print("Finised, going home")
  111. a.goto(a.getposition("start"))
  112. b.awarecleanup()
Advertisement
Add Comment
Please, Sign In to add comment