HectorHW

коробочка

Oct 17th, 2020 (edited)
554
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SIZE = 7;
  2.  
  3. function refuelIfNeeded()
  4.     local fuel = turtle.getFuelLevel();
  5.     if fuel<160 then
  6.         local prev_slot = turtle.getSelectedSlot();
  7.         turtle.select(16);
  8.         turtle.refuel(math.ceil(fuel/80));
  9.         turtle.select(prev_slot);
  10.     end
  11.    
  12. end
  13.  
  14. function checkFindSlot(item_name)
  15.     if  turtle.getItemCount()==0 or turtle.getItemDetail().name ~= item_name then
  16.         for i=1,16,1 do
  17.             turtle.select(i);
  18.             if  turtle.getItemCount()~=0 and turtle.getItemDetail().name == item_name then
  19.                 return true;
  20.             end
  21.        
  22.         end
  23.         error("no blocks found");
  24.     end
  25.    
  26. end
  27.  
  28. function checkedPlace(item_name)
  29.     checkFindSlot(item_name);
  30.     turtle.placeDown();
  31. end
  32.  
  33. function checkedForward()
  34.     refuelIfNeeded();
  35.     if turtle.getFuelLevel()==0 then error("failed to refuel") end
  36.     turtle.forward();
  37. end
  38.  
  39. function checkedUp()
  40.     refuelIfNeeded();
  41.     if turtle.getFuelLevel()==0 then error("failed to refuel") end
  42.     turtle.up();
  43. end
  44.  
  45. function checkedDown()
  46.     refuelIfNeeded();
  47.     if turtle.getFuelLevel()==0 then error("failed to refuel") end
  48.     turtle.down();
  49. end
  50.  
  51. function drawLine(n)
  52.    
  53.     for i = 1,n-1,1 do
  54.    
  55.         checkedPlace(BLOCK);
  56.        
  57.         checkedForward();
  58.     end
  59.    
  60.     checkedPlace(BLOCK);
  61. end
  62.  
  63. function drawSquare(size)
  64.  
  65.     for row_number = 1,size,1 do
  66.         drawLine(size);
  67.        
  68.         if row_number==size then break; end
  69.        
  70.         if row_number%2==1 then
  71.             turtle.turnRight();
  72.             checkedForward();
  73.             turtle.turnRight();
  74.         else
  75.             turtle.turnLeft();
  76.             checkedForward();
  77.             turtle.turnLeft();
  78.         end
  79.     end
  80.  
  81. end
  82.  
  83. function drawPerimeter(size)
  84.  
  85.     for i = 1,4,1 do
  86.         drawLine(size);
  87.         turtle.turnRight();
  88.     end
  89.  
  90. end
  91.  
  92. turtle.select(1);
  93.  
  94.  
  95. BLOCK = turtle.getItemDetail().name;
  96.  
  97. print(BLOCK);
  98.  
  99.  
  100. drawSquare(SIZE);
  101.  
  102. if SIZE%2==1 then
  103.     turtle.turnLeft();
  104.     turtle.turnLeft();
  105. else
  106.     turtle.turnRight();
  107. end
  108.  
  109. checkedUp();
  110.  
  111. for i=1,3,1 do
  112.     drawPerimeter(SIZE);
  113.     checkedUp();
  114. end
  115.  
  116. drawSquare(SIZE);
  117.  
  118. checkedForward();
  119.  
  120. for i=1,1+3+1,1 do
  121.     checkedDown();
  122. end
RAW Paste Data