Advertisement
psychedelixx

Minecraft Turtle: Room

May 22nd, 2013
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.     2013 (c) psychedelixx
  3.     Minecraft Turtle: Room
  4.     2013-05-22
  5.  
  6.     Digs a room with specified dimensions.
  7.  
  8.     Usage:
  9.         - use turtle and type "label set <name>"
  10.           (to give your turtle an unique name so it remembers its programs)
  11.         - type "pastebin get tPQVZfmw room"
  12.         - type "room <width> [<length>] [<height>]"
  13.     - default length = width
  14.     - default height = 2
  15.     - place solid blocks in slot 16 to fill the ground
  16. --]]
  17.  
  18. function move()
  19.     if turtle.getFuelLevel() < 2 then
  20.         turtle.refuel()
  21.     end
  22.     if fillGround and not turtle.detectDown() then 
  23.         turtle.select(16)
  24.         turtle.placeDown()
  25.     end
  26.  
  27.     while not turtle.forward() do
  28.         turtle.dig()
  29.     end
  30.     repeat
  31.         turtle.digUp()
  32.     until not turtle.detectUp()
  33. end
  34.  
  35. local args = { ... }
  36. if #args < 1 then
  37.     print("")
  38.     print("Usage: room <width> [<length>] [<height>]")
  39.     print("# default length = width")
  40.     print("# default height = 2")
  41.     print("# place solid blocks in slot 16 to fill the ground")
  42.     print("")
  43.  
  44.     error()
  45. end
  46.  
  47. width = tonumber(args[1])
  48. length = width
  49. height = 2
  50. fillGround = true
  51.  
  52. if #args >= 2 then
  53.     length = tonumber(args[2])
  54. end
  55. if #args == 3 then
  56.     height = tonumber(args[3])
  57. end
  58.  
  59. if height*width*length < 1 then
  60.   print( "A room must be at least 1m^3." )
  61.   error()
  62. end
  63.  
  64. if turtle.getFuelLevel() == 0 then
  65.     turtle.refuel()
  66. end
  67.  
  68. if turtle.getFuelLevel() == 0 then
  69.     print("I need fuel!")
  70. else
  71.     print("======== 2013 (c) psychedelixx ========")
  72.     print("Let's go!")
  73.     print("Digging " .. width .. "*" .. length .. "*" .. height .. " (w*l*h)")
  74.     move()
  75.  
  76.     nextTurnRight = true
  77.     h = 0
  78.    
  79.     repeat
  80.         w = 1
  81.         while w <= width do
  82.             print("")
  83.                 if turtle.getFuelLevel() ~= "unlimited" then
  84.                 print("Fuel: " .. turtle.getFuelLevel())
  85.             end
  86.             for l = 1, length-1 do
  87.                 move()
  88.             end
  89.             if w < width then
  90.                 if nextTurnRight then
  91.                     turtle.turnRight()
  92.                     move()
  93.                     turtle.turnRight()
  94.                     nextTurnRight = false
  95.                 else
  96.                     turtle.turnLeft()
  97.                     move()
  98.                     turtle.turnLeft()
  99.                     nextTurnRight = true
  100.                 end
  101.             end
  102.             w = w+1
  103.         end
  104.         if h < height-1 then       
  105.             h = h+2
  106.         else
  107.             if h == height-1 then
  108.                 h = h+1
  109.             end
  110.         end
  111.        
  112.         if h < height then
  113.             turtle.turnRight()
  114.             turtle.turnRight()
  115.             turtle.up()
  116.             turtle.digUp()
  117.             if h < height-1 then
  118.                 turtle.up()
  119.                 turtle.digUp()
  120.             end
  121.         end
  122.         fillGround = false
  123.     until h >= height
  124.    
  125.     while h > 2 do
  126.         turtle.down()
  127.         h = h-1
  128.     end
  129.    
  130.  
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement