Telida

Hard stone

Jul 28th, 2021 (edited)
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.98 KB | None | 0 0
  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 +5;
  18. local reinforced_stone_inventory_number = 1;
  19. local sand_inventory_number = 4 +5;
  20. local bore_inventory_number = 2 +5;
  21. local spray_inventory_number = 1 +5;
  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("spray_refuel");
  67.     robot_api.select(spray_inventory_number);
  68.     inventory.equip();
  69.     robot_api.turnAround();
  70.     robot_api.use();
  71.     robot_api.turnAround();
  72.     inventory.equip();
  73. end;
  74.  
  75. local function isEnergyBelow30Procent()
  76.     local max_energy = computer.maxEnergy();
  77.     local current_energy = computer.energy();
  78.     local current_energy_in_procents = (current_energy * 100) / max_energy;
  79.     return current_energy_in_procents;
  80. end
  81.    
  82. local function chargeUp()
  83.     redstone.setOutput(sides.right, 15);
  84.     while (true) do
  85.             os.sleep(2);
  86.             if (computer.energy() >= (computer.maxEnergy()*0.9)) then break; end;
  87.     end
  88.     redstone.setOutput(sides.right, 0);
  89. end
  90.    
  91. local function takeSandAndScaffoldFromExternalInventory()
  92.     robot_api.select(sand_inventory_number);
  93.     inventory.suckFromSlot(sides.down, sand_slot);
  94.     robot_api.select(iron_scaffol_inventory_number);
  95.     inventory.suckFromSlot(sides.down, scaffold_slot);
  96. end
  97.    
  98. local function isOutOfMaterials()
  99.         robot_api.select(sand_inventory_number);
  100.         local stack = inventory.getStackInInternalSlot();
  101.         if (stack == nil)
  102.             then return true;
  103.             end;
  104.         local size = stack.size;
  105.         if (size <= 0) then return true; end;
  106.         return false;
  107. end
  108.    
  109. local function isStoneFull()
  110.         robot_api.select(reinforced_stone_inventory_number);
  111.         local stack = inventory.getStackInInternalSlot();
  112.         if (stack == nil)
  113.             then return false;
  114.             end;
  115.         local size = stack.size;
  116.         if (size >= 1) then return true; end;
  117.         return false;
  118. end
  119.  
  120. local function getRidOfStone()
  121.         for i=1, 8, 1
  122.         do
  123.             local item = inventory.getStackInInternalSlot(i);
  124.             if (item)
  125.             then
  126.                 if (item.name == reinforced_stone)
  127.                 then
  128.                     inventory.dropIntoSlot(sides.down, stone_slot);
  129.                 end;
  130.             end;        
  131.         end;
  132. end;
  133.  
  134. local function main()
  135.     chargeUp();
  136.     local remaining_foam = 80;
  137.     while (true) do
  138.         if (isEnergyBelow30Procent() == true)
  139.              then chargeUp();
  140.              end;
  141.         if (isOutOfMaterials() == true)
  142.              then takeSandAndScaffoldFromExternalInventory();
  143.              end;
  144.        
  145.         if (remaining_foam <= 0)
  146.             then
  147.                print(remaining_foam);
  148.                refuelSprayer();
  149.                remaining_foam = 80;
  150.                getRidOfStone();
  151.                inventory.equip();
  152.                getRidOfStone();
  153.                inventory.equip();
  154.             end;
  155.        
  156.         robot_api.select(iron_scaffol_inventory_number);
  157.        
  158.         if (isBlock(air) == true)
  159.              then placeIronScaffold();
  160.              end;
  161.         if (isBlock(iron_scaffold) == true)
  162.              then
  163.                 if (foamTheScaffold() == true)
  164.                     then
  165.                         remaining_foam = remaining_foam - 1;
  166.                     else refuelSprayer(); remaining_foam = 80;
  167.                     end;
  168.              end;
  169.         if (isBlock(foam) == true)
  170.              then useSandOnFoam();
  171.              end;
  172.         if (isBlock(reinforced_stone) == true)
  173.              then boreTheStone();
  174.              end;
  175.     end;
  176. end;
  177.  
  178. main();
  179. --refuelSprayer();
  180.  
Add Comment
Please, Sign In to add comment