public static List <MapEntity> PasteEntities(Vector2 position, Submarine sub, XElement configElement, string filePath = null, bool selectInstance = false) { int idOffset = Entity.FindFreeID(1); if (MapEntity.mapEntityList.Any()) { idOffset = MapEntity.mapEntityList.Max(e => e.ID); } List <MapEntity> entities = MapEntity.LoadAll(sub, configElement, filePath, idOffset); if (entities.Count == 0) { return(entities); } Vector2 offset = sub?.HiddenSubPosition ?? Vector2.Zero; foreach (MapEntity me in entities) { me.Move(position); me.Submarine = sub; if (!(me is Item item)) { continue; } Wire wire = item.GetComponent <Wire>(); //Vector2 subPosition = Submarine == null ? Vector2.Zero : Submarine.HiddenSubPosition; if (wire != null) { //fix wires that have been erroneously saved at the "hidden position" if (sub != null && Vector2.Distance(me.Position, sub.HiddenSubPosition) > sub.HiddenSubPosition.Length() / 2) { me.Move(position); } wire.MoveNodes(position - offset); } } MapEntity.MapLoaded(entities, true); #if CLIENT if (Screen.Selected == GameMain.SubEditorScreen && selectInstance) { MapEntity.SelectedList.Clear(); entities.ForEach(MapEntity.AddSelection); } #endif return(entities); }