mrWhiskasss

роботы укреп

Jul 29th, 2021
1,109
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component");
  2. local robot_api = require("robot");
  3. local computer = require("computer");
  4. local sides = require("sides");
  5.  
  6. local inventory = component.inventory_controller;
  7. --local robot = component.robot;
  8. local geolyzer = component.geolyzer;
  9. local redstone = component.redstone;
  10.  
  11. local iron_scaffold = "ic2:scaffold";
  12. local foam = "ic2:foam";
  13. local reinforced_stone = "ic2:resource";
  14. local air = "minecraft:air";
  15. local sand = "minecraft:sand";
  16.  
  17. local iron_scaffol_inventory_number = 3;
  18. local reinforced_stone_inventory_number = 5;
  19. local sand_inventory_number = 4;
  20. local bore_inventory_number = 2;
  21. local spray_inventory_number = 1;
  22.  
  23. local sand_slot = 4;
  24. local scaffold_slot = 7;
  25. local stone_slot = 1;
  26.  
  27. local function isBlock(name)
  28.     local info_from_geolyzer = geolyzer.analyze(sides.forward);
  29.     if (info_from_geolyzer.name == name)
  30.         then return true
  31.     else return false
  32.     end
  33. end
  34.  
  35. local function placeIronScaffold()
  36.     robot_api.select(iron_scaffol_inventory_number);
  37.     result_of_placing = robot_api.place();
  38.     return result_of_placing;
  39. end
  40.    
  41. local function foamTheScaffold()
  42.     robot_api.select(spray_inventory_number);
  43.     inventory.equip();
  44.     result_of_foaming = robot_api.use();
  45.     inventory.equip();
  46.     return result_of_foaming;
  47. end
  48.  
  49. local function useSandOnFoam()
  50.     robot_api.select(sand_inventory_number);
  51.     inventory.equip();
  52.     result_of_sanding = robot_api.use();
  53.     inventory.equip();
  54.     return result_of_sanding;
  55. end
  56.  
  57. local function boreTheStone()
  58.     robot_api.select(bore_inventory_number);
  59.     inventory.equip();
  60.     result = robot_api.swing();
  61.     inventory.equip();
  62.     return result;
  63. end
  64.  
  65. local function refuelSprayer()
  66.     print("refuel sprayer");
  67.     robot_api.select(spray_inventory_number);
  68.     inventory.dropIntoSlot(sides.up, 1);
  69.     os.sleep(4);
  70.     robot_api.suckUp();
  71. end;
  72.  
  73. local function isEnergyBelow30Procent()
  74.     local max_energy = computer.maxEnergy();
  75.     local current_energy = computer.energy();
  76.     local current_energy_in_procents = (current_energy * 100) / max_energy;
  77.     return current_energy_in_procents;
  78. end
  79.    
  80. local function chargeUp()
  81.     redstone.setOutput(sides.right, 15);
  82.     while (true) do
  83.             os.sleep(2);
  84.             if (computer.energy() >= (computer.maxEnergy()*0.9)) then break; end;
  85.     end
  86.     redstone.setOutput(sides.right, 0);
  87. end
  88.    
  89. local function takeSandAndScaffoldFromExternalInventory()
  90.     robot_api.select(sand_inventory_number);
  91.     if (inventory.suckFromSlot(sides.down, sand_slot) == false) then print("There is no sand in external inventory!"); end;
  92.     robot_api.select(iron_scaffol_inventory_number);
  93.     if (inventory.suckFromSlot(sides.down, scaffold_slot) == false) then print("There is no iron scaffold in external inventory!"); end;
  94. end
  95.    
  96. local function isOutOfMaterials()
  97.         robot_api.select(sand_inventory_number);
  98.         local stack = inventory.getStackInInternalSlot();
  99.         if (stack == nil)
  100.             then return true;
  101.             end;
  102.         local size = stack.size;
  103.         if (size <= 0) then return true; end;
  104.         return false;
  105. end
  106.    
  107. local function isStoneFull()
  108.         robot_api.select(reinforced_stone_inventory_number);
  109.         local stack = inventory.getStackInInternalSlot();
  110.         if (stack == nil)
  111.             then return false;
  112.             end;
  113.         local size = stack.size;
  114.         print("I have ", size, " stone");
  115.         if (size >= 5) then return true; end;
  116.         return false;
  117. end
  118.  
  119. local function getRidOfStone()
  120.         robot_api.select(reinforced_stone_inventory_number);
  121.         inventory.dropIntoSlot(sides.down, stone_slot, 5);
  122.         print("Get rid of stone.");
  123. end
  124.  
  125. local function main()
  126.     chargeUp();
  127.     local remaining_foam = 80;
  128.     while (true) do
  129.         if (isEnergyBelow30Procent() == true)
  130.              then chargeUp();
  131.              end;
  132.         if (isOutOfMaterials() == true)
  133.              then takeSandAndScaffoldFromExternalInventory();
  134.              end;
  135.         if (isStoneFull() == true)
  136.              then getRidOfStone();
  137.              end;
  138.         if (remaining_foam <= 40)
  139.             then
  140.                print(remaining_foam);
  141.                refuelSprayer();
  142.                remaining_foam = 80;
  143.             end;
  144.         if (isBlock(air) == true)
  145.              then placeIronScaffold();
  146.              end;
  147.         if (isBlock(iron_scaffold) == true)
  148.              then
  149.                 if (foamTheScaffold() == true)
  150.                     then
  151.                         remaining_foam = remaining_foam - 1;
  152.                     else refuelSprayer(); remaining_foam = 80;
  153.                     end;
  154.              end;
  155.         if (isBlock(foam) == true)
  156.              then useSandOnFoam();
  157.              end;
  158.         if (isBlock(reinforced_stone) == true)
  159.              then boreTheStone();
  160.              end;
  161.     end;
  162. end;
  163.  
  164. main();
  165. --refuelSprayer();
  166.  
RAW Paste Data