Advertisement
HectorHW

фундамент

Oct 17th, 2020
1,725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. function refuelIfNeeded()
  2.     local fuel = turtle.getFuelLevel();
  3.     if fuel<160 then
  4.         local prev_slot = turtle.getSelectedSlot();
  5.         turtle.select(16);
  6.         turtle.refuel(math.ceil(fuel/80));
  7.         turtle.select(prev_slot);
  8.     end
  9.    
  10. end
  11.  
  12. function checkFindSlot(item_name)
  13.     if  turtle.getItemCount()==0 or turtle.getItemDetail().name ~= item_name then
  14.         for i=1,16,1 do
  15.             turtle.select(i);
  16.             if  turtle.getItemCount()~=0 and turtle.getItemDetail().name == item_name then
  17.                 return true;
  18.             end
  19.        
  20.         end
  21.         error("no blocks found");
  22.     end
  23.    
  24. end
  25.  
  26. function checkedPlace(item_name)
  27.     checkFindSlot(item_name);
  28.     turtle.placeDown();
  29. end
  30.  
  31. function checkedForward()
  32.     refuelIfNeeded();
  33.     if turtle.getFuelLevel()==0 then error("failed to refuel") end
  34.     turtle.forward();
  35. end
  36.  
  37.  
  38. function drawLine(n)
  39.    
  40.     for i = 1,n-1,1 do
  41.    
  42.         checkedPlace(BLOCK);
  43.        
  44.         checkedForward();
  45.     end
  46.    
  47.     checkedPlace(BLOCK);
  48. end
  49.  
  50. turtle.select(1);
  51.  
  52. BLOCK = turtle.getItemDetail().name;
  53.  
  54. print(BLOCK);
  55.  
  56. SIZE = 5;
  57.  
  58. for row_number = 1,SIZE,1 do
  59.     drawLine(SIZE);
  60.    
  61.     if row_number==SIZE then break; end
  62.    
  63.     if row_number%2==1 then
  64.         turtle.turnRight();
  65.         checkedForward();
  66.         turtle.turnRight();
  67.     else
  68.         turtle.turnLeft();
  69.         checkedForward();
  70.         turtle.turnLeft();
  71.     end
  72. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement