Dission

rect

Mar 30th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1. local depth, width, height = ...
  2. depth = tonumber(depth)
  3. width = tonumber(width)
  4. height = tonumber(height)
  5. height_direction_to_go = 'up'
  6. width_direction_to_go = 'right'
  7.  
  8. function goHeight()
  9.     if height > 1 then
  10.         for h = 2, height do
  11.             if height_direction_to_go == 'up' then
  12.                 print('up')
  13.                 turtle.digUp()
  14.                 turtle.up()
  15.             elseif height_direction_to_go == 'down' then
  16.                 print('down')
  17.                 turtle.digDown()
  18.                 turtle.down()
  19.             end
  20.         end
  21.         if height_direction_to_go == 'up' then
  22.             height_direction_to_go = 'down'
  23.         elseif height_direction_to_go == 'down' then
  24.             height_direction_to_go = 'up'
  25.         end
  26.     end
  27. end
  28.  
  29. function goWidth(moveUp)
  30.     print('here 1')
  31.     if width > 1 then
  32.         print('here 2')
  33.         for w = 2, width do
  34.             print('here 3')
  35.             if w == 2 and width_direction_to_go == 'right' then
  36.                 print('here 4')
  37.                 print('turn right')
  38.                 turtle.turnRight()
  39.             elseif w == 2 and width_direction_to_go == 'left' then
  40.                 print('here 5')
  41.                 print('turn left')
  42.                 turtle.turnLeft()
  43.             end
  44.             print('width ' .. width_direction_to_go)
  45.             turtle.dig()
  46.             turtle.forward()
  47.             if moveUp == true then
  48.                 goHeight()
  49.             end
  50.         end
  51.         if width_direction_to_go == 'right' then
  52.             print('here 6')
  53.             print('turn left')
  54.             width_direction_to_go = 'left'
  55.             turtle.turnLeft()
  56.         elseif width_direction_to_go == 'left' then
  57.             print('here 7')
  58.             print('turn right')
  59.             width_direction_to_go = 'right'
  60.             turtle.turnRight()
  61.         end
  62.     end
  63. end
  64.  
  65. function forward()
  66.     for d = 1, depth do
  67.         print('forward')
  68.         turtle.dig()
  69.         turtle.forward()
  70.         goHeight()
  71.         goWidth(true)
  72.     end
  73. end
  74.  
  75. function goHome()
  76.     if height_direction_to_go == 'down' then
  77.         goHeight()
  78.     end
  79.     if width_direction_to_go == 'left' then
  80.         goWidth(false)
  81.     end
  82.     turtle.turnLeft()
  83.     turtle.turnLeft()
  84.     for d = 1, depth do
  85.         turtle.forward()
  86.     end
  87. end
  88.  
  89. function refuel()
  90.     for i = 1, 16 do
  91.         turtle.select(i)
  92.         turtle.refuel()
  93.     end
  94. end
  95.  
  96. function drop()
  97.     for i = 1, 16 do
  98.         turtle.select(i)
  99.         turtle.drop()
  100.     end
  101. end
  102.  
  103. function init()
  104.     refuel()
  105.     forward()
  106.     goHome()
  107.     drop()
  108. end
  109.  
  110. init()
Add Comment
Please, Sign In to add comment