Advertisement
soee

cave

Apr 23rd, 2014
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.75 KB | None | 0 0
  1. --pastebin:Sg9BVwcS
  2.  
  3. local tArgs = { ... }
  4.  
  5. os.loadAPI("movement")
  6.  
  7. local m = movement
  8.  
  9. local torchDist = 6
  10.  
  11. if #tArgs ~= 3 then
  12.     print("Usage: cave <width> <height> <length>")
  13.     print("Slot 1: floor")
  14.     print("Slot 2: ceiling")
  15.     print("Slot 3: sides")
  16.     print("Slot 4: torches")
  17.     print("Slot 5: front")
  18.     print("Slot 6: back")
  19.     return
  20. end
  21.  
  22. local width = tonumber(tArgs[1])
  23. if width < 1 then
  24.     print("Cave width must be positive")
  25.     return
  26. end
  27.  
  28. local height = tonumber(tArgs[2])
  29. if height < 1 then
  30.     print("Cave height must be positive")
  31.     return
  32. end
  33.  
  34. local length = tonumber(tArgs[3])
  35. if length < 1 then
  36.     print("Cave length must be positive")
  37.     return
  38. end
  39.  
  40.  
  41. local floorSlot = 1
  42. local ceilingSlot = 2
  43. local sideSlot = 3
  44. local torchSlot = 4
  45. local frontSlot = 5
  46. local backSlot = 6
  47.  
  48. m.reservedslots = 6
  49.  
  50.  
  51. local paintFloor = turtle.getItemCount(floorSlot) > 0
  52. local paintCeiling = turtle.getItemCount(ceilingSlot) > 0
  53. local paintSides = turtle.getItemCount(sideSlot) > 0
  54. local placeTorches = turtle.getItemCount(torchSlot) > 0
  55. local paintFront = turtle.getItemCount(frontSlot) > 0
  56. local paintBack = turtle.getItemCount(backSlot) > 0
  57.  
  58. local fuelLevel = turtle.getFuelLevel()
  59. print("Fuel level: " .. fuelLevel)
  60. if fuelLevel < 1 then
  61.     return
  62. end
  63.  
  64. print("caving " .. width .. " x " .. height .. " x " .. length)
  65.  
  66. local function doPaintSide()
  67.     if paintSides then
  68.         m.paintForward(sideSlot)
  69.     end
  70. end
  71.  
  72. local function doPaintFloor()
  73.     if paintFloor then
  74.         m.paintDown(floorSlot)
  75.     end
  76. end
  77.  
  78. local function doPaintCeiling()
  79.     if paintCeiling then
  80.         m.paintUp(ceilingSlot)
  81.     end
  82. end
  83.  
  84.  
  85. local goRight = true
  86. for i = 1, length do
  87.  
  88.     if ((i - 1) % torchDist == 0) then
  89.         if placeTorches then
  90.             if height > 2 then
  91.                 m.turtleUp()
  92.             end
  93.             m.turtleUp()
  94.             turtle.dig()
  95.             m.turtleDown()
  96.             if (m.selectMaterial(torchSlot)) then
  97.                 turtle.turnLeft()
  98.                 turtle.placeUp()
  99.                 turtle.turnRight()
  100.             end
  101.             if height > 2 then
  102.                 m.turtleDown()
  103.             end
  104.         end
  105.     end
  106.  
  107.     -- prepare for next slice
  108.     m.turtleForward()
  109.     m.turn( not goRight )
  110.     doPaintSide()
  111.     m.turn( goRight )
  112.     m.turn( goRight )
  113.  
  114.     for h = 1, height do
  115.  
  116.         for w = 1, width do
  117.  
  118.             if (h == 1) then
  119.                 doPaintFloor()
  120.             end
  121.             if (h == height) then
  122.                 doPaintCeiling()
  123.             end
  124.             if (paintFront and i == 1) then
  125.                 m.turn(goRight)
  126.                 m.paintForward(frontSlot)
  127.                 m.turn(not goRight)
  128.             end
  129.  
  130.             if (paintBack and i == length) then
  131.                 m.turn(not goRight)
  132.                 m.paintForward(backSlot)
  133.                 m.turn(goRight)
  134.             end
  135.  
  136.             if (w < width) then
  137.                 m.turtleForward()
  138.             end
  139.         end
  140.  
  141.         doPaintSide()
  142.         if h < height then
  143.             m.turtleUp()
  144.             doPaintSide()
  145.             turtle.turnRight()
  146.             turtle.turnRight()
  147.             goRight = not goRight
  148.         end
  149.     end
  150.  
  151.     for h = 1, height - 1 do
  152.         m.turtleDown()
  153.     end
  154.     m.turn( not goRight )
  155.     goRight = not goRight
  156. end
  157.  
  158. -- return to start position.
  159. if (not goRight) then
  160.     -- turtle is to the right, move back to left side
  161.     m.turn( false )
  162.     for i=1,width-1 do
  163.         m.turtleForward(width)
  164.     end
  165.     m.turn( false )
  166. else
  167.     -- else just turn around
  168.     m.turn( false )
  169.     m.turn( false )
  170. end
  171.  
  172. for i=1, length-1 do
  173.     m.turtleForward()
  174. end
  175. m.turn( false )
  176. m.turn( false )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement