Advertisement
psychedelixx

Minecraft Turtle: Room (Robust)

Apr 21st, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | None | 0 0
  1. --[[
  2.     2014 (c) psychedelixx
  3.     Minecraft Turtle: Room (Tobust)
  4.     2014-04-21
  5.  
  6.     Digs a room with specified dimensions.
  7.  
  8.     Robust API:
  9.     http://computercraft.info/wiki/Robust_Turtle_API
  10.  
  11.     Usage:
  12.         - use turtle and type "label set <name>"
  13.           (to give your turtle an unique name so it remembers its programs)
  14.         - type "pastebin get VRR7iLat room"
  15.         - type "room <width> [<length>] [<height>]"
  16.     - default length = width
  17.     - default height = 2
  18.     - place solid blocks in slot 16 to fill the ground
  19. --]]
  20.  
  21. function move()
  22.     t.digUp()
  23.     t.dig()
  24.     t.forward()
  25.    
  26.     empty = 0
  27.     if nextTurnRight then
  28.         print("w"..w.." l"..l.." h"..h.." next turn right. Fuel: " .. turtle.getFuelLevel())
  29.     else
  30.         print("w"..w.." l"..l.." h"..h.." next turn left. Fuel: " .. turtle.getFuelLevel())
  31.     end
  32.    
  33.     for slot = 1, 16 do
  34.         if turtle.getItemCount(slot) == 0 then
  35.             empty = 1
  36.             break
  37.         end
  38.     end
  39.     if empty == 0 then     
  40.         t.down(h-1)
  41.        
  42.         if (h-1)%4==0 then
  43.             if nextTurnRight then
  44.                 t.left()
  45.                 t.forward(w-1)
  46.                 t.left()
  47.                 t.forward(l)
  48.             else
  49.                 t.right()
  50.                 t.forward(w-1)
  51.                 t.left()
  52.                 t.forward(length-l-1)
  53.             end
  54.         else
  55.             if nextTurnRight then
  56.                 t.right()
  57.                 t.forward(width-w)
  58.                 t.left()
  59.                 t.forward(length-l-1)
  60.             else
  61.                 t.left()
  62.                 t.forward(width-w)
  63.                 t.left()
  64.                 t.forward(l)
  65.             end
  66.         end
  67.        
  68.         for slot = 1, 15 do
  69.                 turtle.select(slot)
  70.                 turtle.drop()
  71.         end
  72.        
  73.         t.turnAround()
  74.        
  75.         if (h-1)%4==0 then
  76.             if nextTurnRight then
  77.                 t.forward(l)
  78.                 t.right()
  79.                 t.forward(w-1)
  80.                 t.left()
  81.             else
  82.                 t.forward(length-l-1)
  83.                 t.right()
  84.                 t.forward(w-1)
  85.                 t.right()
  86.             end
  87.         else
  88.             if nextTurnRight then
  89.                 t.forward(length-l-1)
  90.                 t.right()
  91.                 t.forward(width-w)
  92.                 t.right()
  93.             else
  94.                 t.forward(l)
  95.                 t.right()
  96.                 t.forward(width-w)
  97.                 t.left()
  98.             end
  99.         end
  100.        
  101.         t.up(h-1)
  102.     end
  103. end
  104.  
  105. local args = { ... }
  106. if #args < 1 then
  107.     print("")
  108.     print("Usage: room <width> [<length>] [<height>]")
  109.     print("# default length = width")
  110.     print("# default height = 2")
  111.     print("")
  112.  
  113.     error()
  114. end
  115.  
  116. if #args >= 1 then
  117.     width = tonumber(args[1])
  118.     length = width
  119.     height = 2
  120. end
  121. if #args >= 2 then
  122.     length = tonumber(args[2])
  123. end
  124. if #args == 3 then
  125.     height = tonumber(args[3])
  126. end
  127.  
  128. if turtle.getFuelLevel() < height*width*length then
  129.     print("I need " .. height*width*length - turtle.getFuelLevel() .. " more fuel!")
  130. else
  131.     print("======== 2014 (c) psychedelixx ========")
  132.     print("Let's go!")
  133.     print("Digging " .. width .. "*" .. length .. "*" .. height .. " (w*l*h)")
  134.  
  135.     nextTurnRight = true
  136.     h = 1
  137.    
  138.     repeat
  139.         w = 1
  140.         while w <= width do
  141.             print("")
  142.             l = 1
  143.             while l < length do
  144.                 move()
  145.                 l = l+1
  146.             end
  147.             if w < width then
  148.                 if nextTurnRight then
  149.                     t.right()
  150.                     move()
  151.                     t.right()
  152.                     nextTurnRight = false
  153.                 else
  154.                     t.left()
  155.                     move()
  156.                     t.left()
  157.                     nextTurnRight = true
  158.                 end
  159.             end
  160.             w = w+1
  161.         end
  162.         if h < height then     
  163.             h = h+2
  164.         end
  165.         if h == height then
  166.             h = h+1
  167.         end
  168.        
  169.         if h < height then
  170.             t.turnAround()
  171.             t.up()
  172.             t.digUp()
  173.             if h < height then
  174.                 t.up()
  175.                 t.digUp()
  176.             end
  177.         end
  178.     until h >= height
  179.    
  180.     t.down(height-2)
  181.     for slot = 1, 15 do
  182.         turtle.select(slot)
  183.         turtle.drop()
  184.     end
  185. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement