mauza

basement

Jun 13th, 2021 (edited)
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 0
  1.  
  2. direction = { FORWARD=0, RIGHT=1, BACK=2, LEFT=3, UP=4, DOWN=5 }
  3. local last_empty_slot = 16
  4.  
  5. function ensure_inventory_space()
  6.     if turtle.getItemCount(last_empty_slot) > 0 then
  7.         for i = 1, last_empty_slot do
  8.             turtle.select(i)
  9.             turtle.drop()
  10.         end
  11.     end
  12.     turtle.select(1)
  13. end
  14.  
  15. function Attack(side)
  16.     local result = false
  17.     if side == direction.UP then
  18.         result = turtle.attackUp()
  19.     elseif side == direction.DOWN then
  20.         result = turtle.attackDown()
  21.     elseif side == direction.FORWARD then
  22.         result = turtle.attack()
  23.     end
  24.     return result
  25. end
  26.  
  27. function Move(move_direction, times)
  28.     local move = turtle.forward
  29.     local detect = turtle.detect
  30.     if move_direction == direction.UP then
  31.         move = turtle.up
  32.         detect = turtle.detectUp
  33.     elseif move_direction == direction.DOWN then
  34.         move = turtle.down
  35.         detect = turtle.detectDown
  36.     end
  37.     times = times or 1
  38.     for i = 1, times, 1 do
  39.         while not move() do
  40.             if detect() then
  41.                 if not Dig(move_direction) then
  42.                     return false
  43.                 end
  44.             elseif Attack(move_direction) then
  45.                 while Attack(move_direction) do end
  46.             end
  47.         end
  48.     end
  49.     return true
  50. end
  51.  
  52. function Dig(side)
  53.     local result = false
  54.     ensure_inventory_space()
  55.     if side == direction.UP then
  56.         result = turtle.digUp()
  57.     elseif side == direction.DOWN then
  58.         result = turtle.digDown()
  59.     elseif side == direction.FORWARD then
  60.         result = turtle.dig()
  61.     end
  62.     return result
  63. end
  64.  
  65.  
  66. local args = { ... }
  67.  
  68. l = tonumber(args[1])
  69. w = tonumber(args[2])
  70. h = tonumber(args[3])
  71.  
  72. turtle.select(1)
  73. current_x = 0
  74.  
  75. while current_x <= w do
  76.     for x = 1, l, 1 do
  77.         Move(direction.DOWN, h)
  78.         Move(direction.UP, h)
  79.         Move(direction.FORWARD, 1)
  80.     end
  81.     if current_x % 2 == 0 then
  82.         turtle.turnLeft()
  83.         Move(direction.FORWARD, 1)
  84.         turtle.turnLeft()
  85.     else
  86.         turtle.turnRight()
  87.         Move(direction.FORWARD, 1)
  88.         turtle.turnRight()
  89.     end
  90.     current_x = current_x + 1
  91. end
  92.  
Add Comment
Please, Sign In to add comment