Advertisement
hackobster

Wall Build

Jun 16th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. local targs = {...}
  2.  
  3. if #targs ~= 2 then
  4.         print("floor <length> <width>")
  5.         error()
  6. end
  7.  
  8. local length = tonumber(targs[1])
  9. local height = tonumber(targs[2])
  10.  
  11. local curBlockSelection = 2
  12. -- Functions used in Main code
  13. function confirmBlock()
  14.     if turtle.getItemCount(curSelection) <= 1 then
  15.         for i = 1, 16 do
  16.             if turtle.compareTo(i) and not (i == curBlockSelection) then
  17.                 turtle.select(i)
  18.                 turtle.transferTo(curBlockSelection)
  19.                 turtle.select(curBlockSelection)
  20.             end
  21.         end
  22.         if turtle.getItemCount(curSelection) <= 1 then
  23.             print("No more wall block in inventory, we fucked")
  24.             error()
  25.         end
  26.     end
  27. end
  28. function moveUp()
  29.     if not turtle.up() then
  30.         turtle.digUp()
  31.         turtle.up()
  32.     end
  33. end
  34. function placeUp()
  35.     confirmBlock()
  36.     if not turtle.placeUp() then
  37.         turtle.digUp()
  38.         turtle.placeUp()
  39.     end
  40. end
  41. function moveDown()
  42.     if not turtle.down() then
  43.         turtle.digDown()
  44.         turtle.down()
  45.     end
  46. end
  47. function placeDown()
  48.     confirmBlock()
  49.     if not turtle.placeDown() then
  50.         turtle.digDown()
  51.         turtle.placeDown()
  52.     end
  53. end
  54. function moveForward()
  55.     confirmBlock()
  56.     if not turtle.forward() then
  57.         turtle.dig()
  58.         turtle.forward()
  59.     end
  60. end
  61.  
  62. --Initialization (refuel and get initial position)
  63. turtle.refuel()
  64. turtle.select(curSelection)
  65. for i = 1, height - 2 do
  66.     moveUp()
  67. end
  68. -- Starts on opposite side on odd cases so it will reposition back correctly at the end
  69. if (height % 2) == 1 then
  70.     for i = 1, length do
  71.         moveForward()
  72.     end
  73.     turtle.turnLeft()
  74.     turtle.turnLeft()
  75. end
  76. --Main Wall-Making Code
  77. for j = 1, height do
  78.     for i = 1, length do
  79.         if (turtle.getFuelLevel() <= 1) then
  80.             turtle.refuel()
  81.         end
  82.         placeUp()
  83.         moveForward()
  84.     end
  85.     print("Finished ", j ," out of ", height, " rows")
  86.     moveDown()
  87.     turtle.turnLeft()
  88.     turtle.turnLeft()
  89.     moveForward()
  90. end
  91. turtle.back()
  92. for i = 1, 2 do
  93.     moveUp()
  94.     turtle.turnLeft()
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement