soee

wallup

Jun 10th, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tArgs = { ... }
  2.  
  3. if #tArgs == 0 then
  4.         print( "Usage: wallup <length> [depth] " )
  5.         return
  6. end
  7.  
  8. local length = tonumber( tArgs[1] )
  9. if length < 2 then
  10.         print( "wall length must be > 2" )
  11.         return
  12. end
  13.  
  14. local depth = 256
  15. if #tArgs >= 2 then
  16.   depth = tonumber( tArgs[2] )
  17.   if depth < 1 then
  18.         print( "wall depth must be positive" )
  19.         return
  20.   end
  21. end
  22.  
  23. local function digForward()
  24.   while (turtle.detect()) do
  25.     turtle.dig()
  26.     sleep(0.2)
  27.   end
  28. end
  29.  
  30. local function digUp()
  31.   while (turtle.detectUp()) do
  32.     turtle.digUp()
  33.     sleep(0.2)
  34.   end
  35. end
  36.  
  37.  
  38. local relY = 0
  39.  
  40. local function tryDown()
  41.   if (turtle.detectDown()) then
  42.      turtle.digDown()
  43.   end
  44.  
  45.   if (turtle.detectDown()) then
  46.     return false
  47.   end
  48.   if (turtle.down()) then
  49.     relY = relY-1
  50.     return true
  51.   else
  52.     return false
  53.   end
  54. end
  55.  
  56.  
  57. local function tryUp()
  58.   while (turtle.detectUp()) do
  59.      turtle.digUp()
  60.   end
  61.   if (turtle.up()) then
  62.     relY = relY + 1
  63.     return true
  64.   else
  65.     return false
  66.   end
  67. end
  68.  
  69. local function suckAll()
  70.   while turtle.suck() do
  71.   end
  72. end
  73.  
  74. local function wallLayer()
  75.   for side=1,4 do
  76.     for i=1,(length) do
  77.       turtle.turnLeft()
  78.       suckAll()
  79.       if not turtle.compare() then
  80.         digForward()
  81.         suckAll()
  82.         turtle.place()
  83.       end
  84.       turtle.turnRight()
  85.       if i< length then
  86.         digForward()
  87.         turtle.forward()
  88.       end
  89.     end
  90.     turtle.turnRight()
  91.   end
  92. end
  93.  
  94. local function returnToTop()
  95.   while relY < 0 do
  96.     local canUp = tryUp()
  97.     if not canUp then
  98.       break
  99.     end
  100.   end
  101. end
  102.  
  103. turtle.select(1)
  104. for curDepth=1,depth do
  105.   wallLayer()
  106.   if curDepth < depth then
  107.     local canDown = tryDown()
  108.     if not canDown then
  109.       break
  110.     end
  111.   end
  112. end
  113. returnToTop()
Advertisement
Add Comment
Please, Sign In to add comment