Guest User

double

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