Advertisement
GauHelldragon

GauBricks v0.3

Mar 17th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.77 KB | None | 0 0
  1.  
  2. local dim = 16
  3. local totalBlocks = 0
  4. local selection = 1
  5. local outOfBlocks = false
  6. turtle.select(1)
  7.  
  8. function setTotalBlocks()
  9.   local count = 1
  10.   while ( count <= 15 and turtle.getItemCount(count) > 1) do
  11.     totalBlocks = count
  12.     count = count + 1
  13.   end
  14. end
  15.  
  16. function selectBlock()
  17.   if ( outOfBlocks ) then return false end
  18.   if ( turtle.getItemCount(selection) < 1 ) then
  19.     if ( selection >= totalBlocks ) then
  20.       outOfBlocks = true
  21.       return false -- out of placeable blocks
  22.     end
  23.     selection = selection + 1
  24.     turtle.select(selection)
  25.   end
  26.   return true
  27.  
  28. end
  29.  
  30. function checkSpace()
  31.    if ( selectBlock() ) then
  32.      if ( turtle.compareDown() == false ) then
  33.        local needNewBlock = ( turtle.getItemCount(selection) == 1 )
  34.        turtle.digDown()
  35.        
  36.        if ( outOfBlocks == false ) then turtle.placeDown() end
  37.        if ( needNewBlock ) then
  38.          if ( selection < totalBlocks ) then
  39.            selection = selection + 1
  40.            turtle.select(selection)
  41.          else
  42.            outOfBlocks = true
  43.          end
  44.        end
  45.      end
  46.    else
  47.      turtle.select(16)
  48.      if ( turtle.compareDown() == false ) then turtle.digDown() end
  49.    end
  50. end
  51.  
  52. function forward()
  53.    if ( turtle.forward() == false ) then
  54.      repeat
  55.        os.sleep(3)
  56.      until ( turtle.forward() == true )
  57.    end
  58. end
  59.  
  60. function checkAllTiles()
  61.    local x,y = 0,0
  62.    for x = 1,dim do
  63.      for y = 1,dim do
  64.        checkSpace()
  65.        forward()       
  66.      end
  67.      if ( x % 2 == 0 ) then
  68.        turtle.turnLeft()
  69.        forward()
  70.        turtle.turnLeft()
  71.      else
  72.        turtle.turnRight()
  73.        forward()
  74.        turtle.turnRight()
  75.      end
  76.      forward()
  77.      
  78.    end
  79.  
  80. end
  81.  
  82.  
  83. if ( turtle.detectDown() ) then turtle.up() end
  84. setTotalBlocks()
  85. while true do
  86.   checkAllTiles()
  87.   turtle.turnLeft()
  88.   forward()
  89.   os.Sleep(60)
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement