private void OnSpawned(HashSet <IMyCubeGrid> grids) { onDone.Invoke(); Vector3D velocity = p.CubeGrid.Physics.LinearVelocity; Vector3D diff = Vector3D.Zero; bool first = true; HashSet <long> gridIds = new HashSet <long>(); foreach (IMyCubeGrid grid in grids) { grid.Physics.LinearVelocity = velocity; if (first) { diff = AccelerateTime(grid, velocity); } else { MatrixD temp = grid.WorldMatrix; temp.Translation += diff; grid.WorldMatrix = temp; } gridIds.Add(grid.EntityId); IMyEntity e = GridBounds.GetOverlappingEntity(grid); if (e != null) { Utilities.Notify(Utilities.GetOverlapString(true, e), Activator); ParallelSpawner.Close(grids); return; } if (grids.Count > 1) { var cubes = ((MyCubeGrid)grid).GetFatBlocks(); foreach (MyCubeBlock cube in cubes) { IMyMechanicalConnectionBlock baseBlock = cube as IMyMechanicalConnectionBlock; if (baseBlock != null) { baseBlock.Attach(); } } } } if (MyAPIGateway.Session.CreativeMode || comps.ConsumeComponents(Activator, Utilities.GetInventories(p))) { ParallelSpawner.Add(grids); } else { ParallelSpawner.Close(grids); } }
/// <summary> /// Gets actions for blocks implementing IMyMechanicalConnectionBlock. /// </summary> public static void GetMechActions(IMyTerminalBlock tBlock, List <IScrollableAction> actions) { List <IMyTerminalAction> terminalActions = new List <IMyTerminalAction>(); IMyMechanicalConnectionBlock mechBlock = (IMyMechanicalConnectionBlock)tBlock; IMyPistonBase piston; IMyMotorStator rotor; mechBlock.GetActions(terminalActions); foreach (IMyTerminalAction tAction in terminalActions) // sketchy, but I've done worse already { string tActionName = tAction.Name.ToString(); if (tAction.Name.ToString().StartsWith("Add ")) { actions.Add(new BlockAction( () => tActionName, () => tAction.Apply(mechBlock))); } } actions.Add(new BlockAction( () => "Attach Head", () => mechBlock.Attach())); actions.Add(new BlockAction( () => mechBlock.IsAttached ? "Detach Head (Ready)" : "Detach Head", () => mechBlock.Detach())); piston = mechBlock as IMyPistonBase; if (piston != null) { actions.Add(new BlockAction( () => "Reverse", () => piston.Reverse())); } else { rotor = mechBlock as IMyMotorStator; if (rotor != null) { actions.Add(new BlockAction( () => "Reverse", () => rotor.TargetVelocityRad = -rotor.TargetVelocityRad)); } } }