Skip to content

Instantly share code, notes, and snippets.

@Cranc
Created January 6, 2017 17:22
Show Gist options
  • Save Cranc/2630df264548d4de682fbe75899377d4 to your computer and use it in GitHub Desktop.
Save Cranc/2630df264548d4de682fbe75899377d4 to your computer and use it in GitHub Desktop.
public void Main(string argument) {
//get furnaces
var furnace_list = new List<IMyTerminalBlock>();
var temp_list = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyRefinery>(temp_list);
foreach(IMyTerminalBlock t in temp_list) {
if( t.CustomName.Contains("Furnace"))
furnace_list.Add(t);
}
//get containers
var container_list = new List<IMyTerminalBlock>();
temp_list.Clear();
GridTerminalSystem.GetBlocksOfType<IMyCargoContainer>(temp_list);
foreach(IMyTerminalBlock t in temp_list){
if( t.CustomName.Contains("Ingot"))
container_list.Add(t);
}
temp_list.Clear();
//checks
if(furnace_list.Count == 0)
throw new Exception("no furnace found!");
if(container_list.Count == 0)
throw new Exception("no container found");
//get inventorys
var furnace_inventory = new List<IMyInventory>();
var container_inventory = new List<IMyInventory>();
foreach(IMyTerminalBlock t in furnace_list){
furnace_inventory.Add(t.GetInventory(0));
}
foreach(IMyTerminalBlock t in container_list){
container_inventory.Add(t.GetInventory(0));
}
//count gravel
VRage.MyFixedPoint g_count = 0;
foreach(IMyInventory i in container_inventory){
var temp_item_list = i.GetItems();
foreach(IMyInventoryItem t in temp_item_list){
if(t.Content.SubtypeName.Contains("Stone"))
g_count += t.Amount;
}
}
g_count -= 80000; //keep 80t
if (g_count < 0)
return;
//move gravel to furnace
var temp = 1/furnace_inventory.Count;
g_count *= temp;
foreach(IMyInventory i in container_inventory) {
var temp_item_list = i.GetItems();
var index = 0;
foreach(IMyInventoryItem t in temp_item_list){
if(t.Content.SubtypeName.Contains("Stone")) {
foreach(IMyInventory dest in furnace_inventory)
i.TransferItemTo(dest,index,null,true,g_count);
}
index++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment