Advertisement
melzneni

simpleDigger

Mar 11th, 2020
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.50 KB | None | 0 0
  1. local args = { ... }
  2.  
  3. function digForward()
  4.     while turtle.detect() do
  5.         turtle.dig()
  6.     end
  7. end
  8.  
  9. function digUp()
  10.     while turtle.detectUp() do
  11.         turtle.digUp()
  12.     end
  13. end
  14.  
  15. function digDown()
  16.     while turtle.detectDown() do
  17.         turtle.digDown()
  18.     end
  19. end
  20.  
  21. function forward(count)
  22.     for i = 1, count do
  23.         digForward(1)
  24.         while not turtle.forward() do
  25.             digForward(1)
  26.             turtle.attack()
  27.         end
  28.     end
  29. end
  30.  
  31. function up(count)
  32.     for i = 1, count do
  33.         digUp(1)
  34.         while not turtle.up() do
  35.             digUp(1)
  36.             turtle.attackUp()
  37.         end
  38.     end
  39. end
  40.  
  41. function down(count)
  42.     for i = 1, count do
  43.         digDown(1)
  44.         while not turtle.down() do
  45.             digDown(1)
  46.             turtle.attackDown()
  47.         end
  48.     end
  49. end
  50.  
  51. function turnLeft(count)
  52.     for i = 1, count do
  53.         turtle.turnLeft()
  54.     end
  55. end
  56.  
  57. function turnRight(count)
  58.     for i = 1, count do
  59.         turtle.turnRight()
  60.     end
  61. end
  62.  
  63. if #args ~= 3 then
  64.     error("expected exactly 3 arguments (" .. #args .. " given)  [turtle is standing in area and facing x, right is y and top is z args:[x,y,z]]")
  65. end
  66.  
  67. local d = tonumber(args[1])
  68. local w = tonumber(args[2])
  69. local h = tonumber(args[3])
  70.  
  71. function digModed(mode)
  72.     if mode > 0 then digUp() end --height>1
  73.     if mode > 1 then digDown() end --height=3
  74. end
  75.  
  76. function digSurface(x, y, mode)
  77.     if mode > 1 then up(1) end --height=3
  78.     for y1 = 1, y do
  79.         for x1 = 1, x - 1 do
  80.             digModed(mode)
  81.             forward(1)
  82.         end
  83.         digModed(mode)
  84.  
  85.         if y1 ~= y then
  86.             if y1 % 2 == 1 then
  87.                 turnRight(1)
  88.                 forward(1)
  89.                 digModed(mode)
  90.                 turnRight(1)
  91.             else
  92.                 turnLeft(1)
  93.                 forward(1)
  94.                 digModed(mode)
  95.                 turnLeft(1)
  96.             end
  97.         end
  98.     end
  99.     if mode > 1 then down(1) end --height=3
  100. end
  101.  
  102. local mode = h % 3
  103. h = h / 3 - mode / 3
  104.  
  105. mode=mode-1
  106.  
  107. if mode==-1 then mode=2 end
  108.  
  109. if mode ~= 2 then h = h + 1 end
  110.  
  111.  
  112. print("mode: ",mode)
  113.  
  114. for h1 = 1, h do
  115.     if h1 == h then
  116.         print(1)
  117.         digSurface(d, w, mode)
  118.     else
  119.         print(2)
  120.         digSurface(d, w, 3)
  121.         up(3)
  122.         if w % 2 == 0 then
  123.             turnRight(1)
  124.             local p = d
  125.             d = w
  126.             w = p
  127.         else
  128.             turnLeft(2)
  129.         end
  130.     end
  131. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement