Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<IMyTerminalBlock> containers;
- IMyInventory containerDestination;
- void Main()
- {
- List<IMyTerminalBlock> assemblers = new List<IMyTerminalBlock>();
- containers = new List<IMyTerminalBlock>();
- GridTerminalSystem.GetBlocksOfType<IMyAssembler>(assemblers);
- GridTerminalSystem.SearchBlocksOfName("Ingot", containers);
- getNewContainer();
- for(int i = 0; i < assemblers.Count; i++)
- {
- cleanAssembler(assemblers[i] as IMyAssembler);
- }
- }
- void getNewContainer()
- {
- containerDestination = null;
- // search our containers until we find one with space
- for (int n = 0; n < containers.Count; n++)
- {
- var container = containers[n];
- var containerInv = container.GetInventory(0);
- if (!IsFull(containerInv)) // check to see if it has room
- {
- Echo("Found container");
- Echo(container.CustomName);
- containerDestination = containerInv;
- return;
- }
- }
- return;
- }
- void cleanAssembler(IMyAssembler assembler)
- {
- if (containerDestination == null)
- return;
- var assemblerInv = assembler.GetInventory(0);
- List<MyInventoryItem> assemblerItems = new List<MyInventoryItem>();
- assemblerInv.GetItems(assemblerItems);
- for (int i = 0; i < assemblerItems.Count; i++){
- if (!IsFull(containerDestination)){
- Echo("moving items");
- assemblerInv.TransferItemTo(containerDestination, i, null, true, null);
- }
- else { //look for new container
- getNewContainer();
- }
- }
- }
- float getPercent(IMyInventory inv)
- {
- return ((float)inv.CurrentVolume / (float)inv.MaxVolume) * 100f;
- }
- bool IsFull(IMyInventory inv)
- {
- if (getPercent(inv) >= 95)
- return true;
- else
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment