Advertisement
GauHelldragon

GauFlattener v0.2

Mar 2nd, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.78 KB | None | 0 0
  1. local args = { ... }
  2. local xMax = tonumber(args[1])
  3. local yMax = tonumber(args[2])
  4.  
  5.  
  6.  
  7. if #args < 2 then
  8.   xMax = 7
  9.   yMax = 7
  10. end
  11.  
  12. if ( xMax < 7 ) then xMax = 7 end
  13. if ( yMax < 7 ) then yMax = 7 end
  14.  
  15. local fuelNeeded = yMax * xMax * 4 + yMax * 3 + xMax * 3
  16. if ( turtle.getFuelLevel() < fuelNeeded ) then
  17.   print("Not enough fuel, need at least " .. fuelNeeded .. " to make a maze of that size")
  18.   return
  19. end
  20.  
  21. local selection = 1
  22. turtle.select(selection)
  23.  
  24.  
  25. function tryForward()
  26.   if ( turtle.forward() == false ) then
  27.     print("Get out of my way!!")
  28.     while ( turtle.forward() == false ) do
  29.       os.sleep(2)  
  30.     end
  31.   end
  32. end
  33.  
  34.  
  35. function selectBlock()
  36.   if ( selection == 16 ) then return end
  37.  
  38.   while ( turtle.getItemCount(selection) <= 0 ) do
  39.     if ( selection == 16 ) then return end
  40.     selection = selection + 1      
  41.     turtle.select(selection)
  42.   end
  43. end
  44.  
  45.  
  46. function DropBlock()
  47.   selectBlock()
  48.   turtle.placeDown()
  49. end  
  50.  
  51.  
  52. function CutZLevel(addFloor)
  53.   local x = 1
  54.   while ( x <= xMax ) do
  55.     local y = 1
  56.     while ( y < yMax ) do
  57.       if ( addFloor ) then DropBlock() end
  58.       turtle.dig()
  59.       tryForward()
  60.       y = y + 1
  61.     end
  62.     if ( addFloor ) then DropBlock() end       
  63.     x = x + 1
  64.     if ( x > xMax ) then
  65.       turtle.up()
  66.       turtle.turnLeft()
  67.       turtle.turnLeft()
  68.     else
  69.       if ( x % 2 == 1 ) then
  70.         turtle.turnRight()
  71.         turtle.dig()
  72.         tryForward()
  73.         turtle.turnRight()
  74.       else
  75.         turtle.turnLeft()
  76.         turtle.dig()
  77.         tryForward()
  78.         turtle.turnLeft()
  79.       end
  80.     end
  81.   end
  82. end
  83.  
  84. function ReturnHome()
  85.   local i = 1
  86.   while ( i < yMax ) do
  87.     tryForward()
  88.     i = i + 1
  89.   end
  90.   turtle.turnLeft()
  91.   i = 1
  92.   while ( i < xMax ) do
  93.     tryForward()
  94.     i = i + 1
  95.   end
  96.   turtle.turnLeft()
  97. end
  98.  
  99. CutZLevel(true)
  100. ReturnHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement