public override void UpdateBeforeSimulation100() { if (_cargoTeleporter == null) { return; } if (!((IMyFunctionalBlock)_cargoTeleporter).Enabled) { return; } try { if (MyAPIGateway.Session == null) { Write("MyAPIGateway.Session is null"); return; } Write("MainRun"); var name = ""; var gridName = ""; var toMode = true; ParseName(ref name, ref gridName, ref toMode); if (name.Length < 2) { Write("Name too small"); UpdateStatus("Status: No filters\n\nPlease add [T:Block Name] or [F:Block Name].\nPlease add [G:Grid Name] if using antennas."); return; } if (_inventory == null) { _inventory = _cargoTeleporter.GetInventory(); } if (toMode && _inventory.Empty()) { UpdateStatus("Status: Source Empty"); return; } Write("GetBlocks"); var cubeBlocks = _cargoTeleporter.CubeGrid.GetFatBlocks(); //We use true, if it goes through the ref; (which I treat like an out) it will be changed. //If it goes through the linq; then we are unchanged and true is the correct value. (we have found the grid, it is this one) bool gridFound = true; var target = gridName.Length > 2 && gridName != _cargoTeleporter.CubeGrid.Name ? GetTarget(gridName, name, _cargoTeleporter.CubeGrid, ref gridFound) : cubeBlocks.First(x => x?.DisplayNameText == name && OwnershipUtils.isSameFactionOrOwner(_cargoTeleporter, x)); var disonnectedStatus = "Status: Disconnected"; //If grid not found, if (!gridFound) { Write("Grid Not Found"); } disonnectedStatus += $"\nGrid: {(gridFound ? "" : "Not ")}Found"; if (target == null) { Write("Target Not Found"); } //This message should only ever say T/S Not Found, but in case I flubbed it; it can say found disonnectedStatus += $"\n{(toMode ? "Target" : "Source")}: {(target != null ? "" : "Not ")}Found"; if (target == null || !gridFound) { UpdateStatus(disonnectedStatus); return; } var targetInventory = target.GetInventory(); var status = "Status: Connected\nTarget: "; var targetStatus = targetInventory.IsFull ? "Full" : targetInventory.Empty() ? "Empty" : "Some"; var inventoryStatus = _inventory.IsFull ? "Full" : _inventory.Empty() ? "Empty" : "Some"; status += toMode ? targetStatus : inventoryStatus; status += "\nSource: "; status += !toMode ? targetStatus : inventoryStatus; UpdateStatus(status); if (!targetInventory.IsFull && toMode) { targetInventory.TransferItemFrom(_inventory, 0, null, true, null, false); } else if (!targetInventory.Empty() && !_inventory.IsFull && !toMode) { _inventory.TransferItemFrom(targetInventory, 0, null, true, null, false); } } catch (Exception ex) { Logging.WriteLine(ex.ToString()); } }