public VoxelPlacementDefinition(MyObjectBuilder_VoxelMiningDefinition.MiningDef ob, NamedLogger log) { Material = MyDefinitionManager.Get <MyVoxelMaterialDefinition>(ob.VoxelMaterial); if (Material == null) { log.Warning($"Could not find voxel material definition {ob.VoxelMaterial}"); Material = MyVoxelMaterialDefinition.Default; } Volume = ob.VolumeAttribute; var replacementItems = new Dictionary <MyDefinitionId, int>(); foreach (var item in ob.MinedItems) { MyObjectBuilderType type; try { type = MyObjectBuilderType.Parse(item.Type); } catch { log.Warning($"Can not parse defined builder type {item.Type}"); continue; } var key = new MyDefinitionId(type, MyStringHash.GetOrCompute(item.Subtype)); replacementItems[key] = item.Amount; } Items = replacementItems; }
private void InitEntityComponents(MyObjectBuilder_CubeBlockDefinition.EntityComponentDefinition[] entityComponentDefinitions) { if (entityComponentDefinitions == null) { return; } EntityComponents = new Dictionary <string, MyObjectBuilder_ComponentBase>(entityComponentDefinitions.Length); for (int i = 0; i < entityComponentDefinitions.Length; ++i) { var definition = entityComponentDefinitions[i]; MyObjectBuilderType componentObType = MyObjectBuilderType.Parse(definition.BuilderType); Debug.Assert(!componentObType.IsNull, "Could not parse object builder type of component: " + definition.BuilderType); if (!componentObType.IsNull) { var componentBuilder = MyObjectBuilderSerializer.CreateNewObject(componentObType) as MyObjectBuilder_ComponentBase; Debug.Assert(componentBuilder != null, "Could not create object builder of type " + componentObType); if (componentBuilder != null) { EntityComponents.Add(definition.ComponentType, componentBuilder); } } } }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); MyObjectBuilder_CubeBlockStackSizeDefinition definition = builder as MyObjectBuilder_CubeBlockStackSizeDefinition; if ((definition != null) && (definition.Blocks != null)) { foreach (MyObjectBuilder_CubeBlockStackSizeDefinition.BlockStackSizeDef def in definition.Blocks) { if (def.TypeId == null) { string msg = "\"TypeId\" must be defined in a block item for " + builder.Id; MySandboxGame.Log.WriteLine(msg); throw new ArgumentException(msg); } MyObjectBuilderType type = MyObjectBuilderType.Parse(def.TypeId); if (def.SubtypeId == null) { string msg = "\"SubtypeId\" must be defined in a block item for " + builder.Id; MySandboxGame.Log.WriteLine(msg); throw new ArgumentException(msg); } this.BlockMaxStackSizes.Add(new MyDefinitionId(type, def.SubtypeId), def.MaxStackSize); } } }
private MyObjectBuilder_ContainerDefinition.ComponentEntry TranslateDependency(MyObjectBuilder_ContainerDefinition.ComponentEntry original) { var id = new MyDefinitionId(MyObjectBuilderType.Parse(original.Type), original.Subtype); var resultId = id; if (TranslationTable.TryGetValue(resultId, out var replacedId)) { resultId = replacedId; } else { var componentDef = SourceSet.GetDefinitions(id); if (componentDef.Count == 1) { var resultDef = Translate(componentDef[0]); if (resultDef != componentDef[0]) { resultId = resultDef.Id; } } } if (resultId != id) { return(new MyObjectBuilder_ContainerDefinition.ComponentEntry { Type = resultId.TypeId.ShortName, Subtype = resultId.SubtypeName, AlwaysCreate = original.AlwaysCreate }); } return(original); }
public ImmutableInventoryAction ToImmutable() { var targetId = Tag != null ? new MyDefinitionId(typeof(MyObjectBuilder_ItemTagDefinition), Tag) : new MyDefinitionId(MyObjectBuilderType.Parse(Type), Subtype); if (Amount <= 0) { throw new Exception($"Invalid inventory action with amount less than or equal to zero"); } switch (Mode) { case MutableInventoryActionMode.GiveItem: return(new ImmutableInventoryAction(targetId, Amount, ImmutableInventoryAction.InventoryActionMode.GiveTakeItem)); case MutableInventoryActionMode.TakeItem: return(new ImmutableInventoryAction(targetId, -Amount, ImmutableInventoryAction.InventoryActionMode.GiveTakeItem)); case MutableInventoryActionMode.RepairItem: return(new ImmutableInventoryAction(targetId, Amount, ImmutableInventoryAction.InventoryActionMode.RepairDamageItem)); case MutableInventoryActionMode.DamageItem: return(new ImmutableInventoryAction(targetId, -Amount, ImmutableInventoryAction.InventoryActionMode.RepairDamageItem)); case MutableInventoryActionMode.GiveLootTable: return(new ImmutableInventoryAction(targetId, Amount, ImmutableInventoryAction.InventoryActionMode.GiveTakeLootTable)); default: throw new Exception($"Failed to parse inventory action with mode {Mode}"); } }
public DefinedObjectType(String typeName, String subtypeName) { MyObjectBuilderType builderType; try { builderType = MyObjectBuilderType.Parse(typeName); } catch (Exception e) { Log.Error(String.Format( "Failed to find builder type \"{0}\"", typeName ), "ctr"); return; } MyDefinitionId id; try { id = new MyDefinitionId(builderType, subtypeName); } catch (Exception e) { Log.Error(String.Format( "Failed to find definitionId for \"{0}/{1}\"", builderType, subtypeName ), "ctr"); return; } try { Definition = MyDefinitionManager.Static.GetDefinition(id); } catch (Exception e) { Log.Error(String.Format( "Failed to find Definition for \"{0}\"", id ), "ctr"); return; /* * Log.Trace("Logging existing cb defs", "ctr"); * var entities = Sandbox.Game.Entities.MyEntities.GetEntities(); //.Select(x => x as Sandbox.Game.Entities.Cube.MySlimBlock).Where(x => x != null).ToList(); * * foreach (var entity in entities) { * if (entity is Sandbox.Game.Entities.MyCubeGrid) { * var grid = entity as Sandbox.Game.Entities.MyCubeGrid; * foreach (VRage.Game.ModAPI.IMySlimBlock block in grid.CubeBlocks) { * if (block.FatBlock != null) * Log.Trace(String.Format("{0}", block.FatBlock.BlockDefinition), "ctr"); * } * } * } * */ } }
private void DeleteItems(MyGuiControlButton sender) { var treeType = MyObjectBuilderType.Parse("MyObjectBuilder_Trees"); var items = new System.Collections.Generic.HashSet <MyEntity>(); foreach (var entity in Sandbox.Game.Entities.MyEntities.GetEntities()) { if (entity.GetObjectBuilder().TypeId == treeType) { items.Add(entity); } } foreach (var item in items) { item.Close(); } }
void InsertTree() { MyDefinitionId id = new MyDefinitionId(MyObjectBuilderType.Parse("MyObjectBuilder_Tree"), "Tree04_v2"); var itemDefinition = MyDefinitionManager.Static.GetEnvironmentItemDefinition(id); if (MyModels.GetModelOnlyData(itemDefinition.Model).HavokBreakableShapes != null) { var breakableShape = MyModels.GetModelOnlyData(itemDefinition.Model).HavokBreakableShapes[0].Clone(); MatrixD worldMatrix = MatrixD.CreateWorld(MySession.ControlledEntity.Entity.PositionComp.GetPosition() + 2 * MySession.ControlledEntity.Entity.WorldMatrix.Forward, Vector3.Forward, Vector3.Up); List <HkdShapeInstanceInfo> children = new List <HkdShapeInstanceInfo>(); breakableShape.GetChildren(children); children[0].Shape.SetFlagRecursively(HkdBreakableShape.Flags.IS_FIXED); var piece = Sandbox.Engine.Physics.MyDestructionHelper.CreateFracturePiece(breakableShape, MyPhysics.SingleWorld.DestructionWorld, ref worldMatrix, false, itemDefinition.Id, true); } }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var ob = (MyObjectBuilder_GameDefinition)builder; if (ob.InheritFrom != null) { var parent = MyDefinitionManagerBase.Static.GetLoadingSet().GetDefinition <MyGameDefinition>(new MyDefinitionId(typeof(MyObjectBuilder_GameDefinition), ob.InheritFrom)); if (parent == null) { MyLog.Default.Error("Could not find parent definition {0} for game definition {1}.", ob.InheritFrom, ob.SubtypeId); } else { SessionComponents = new Dictionary <string, MyDefinitionId?>(parent.SessionComponents); } } if (SessionComponents == null) { SessionComponents = new Dictionary <string, MyDefinitionId?>(); } foreach (var def in ob.SessionComponents) { if (def.Type != null) { SessionComponents[def.ComponentName] = new MyDefinitionId(MyObjectBuilderType.Parse(def.Type), def.Subtype); } else { SessionComponents[def.ComponentName] = default(MyDefinitionId?); } } if (ob.Default) { // Make the default this SetDefault(); } }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var ob = builder as MyObjectBuilder_CubeBlockStackSizeDefinition; if (ob != null) { if (ob.Blocks != null) { foreach (var item in ob.Blocks) { MyObjectBuilderType typeId; if (item.TypeId != null) { typeId = MyObjectBuilderType.Parse(item.TypeId); } else { string error = "\"TypeId\" must be defined in a block item for " + builder.Id; System.Diagnostics.Debug.Assert(false, error); Sandbox.MySandboxGame.Log.WriteLine(error); throw new ArgumentException(error); } if (item.SubtypeId != null) { BlockMaxStackSizes.Add(new MyDefinitionId(typeId, item.SubtypeId), item.MaxStackSize); } else { string error = "\"SubtypeId\" must be defined in a block item for " + builder.Id; System.Diagnostics.Debug.Assert(false, error); Sandbox.MySandboxGame.Log.WriteLine(error); throw new ArgumentException(error); } } } } }
private void Start() { MyObjectBuilderType obType = MyObjectBuilderType.Parse("MyObjectBuilder_Component"); foreach (var def in MyDefinitionManager.Static.GetPhysicalItemDefinitions()) { string name = def.DisplayNameText; if (!string.IsNullOrEmpty(name) && def.Id.TypeId == obType) { physicalItemNames[def.Id.SubtypeName] = name; } } if (Constants.IsServer) { Net.AddFactory(new PacketBuild()); MapSettings.Copy(MapSettings.Load()); Net.AddFactory(new PacketSettingsRequest()); } else { Net.AddFactory(new MapSettings()); new PacketSettingsRequest().SendToServer(); } if (MyAPIGateway.Session.Player != null) { chat = new SettingsChat(); } hud = new SettingsHud(); Net.AddFactory(new MapSettings.ValuePacket()); Net.AddFactory(new SyncableProjectorState()); Net.AddFactory(new SyncableProjectorSettings()); MyAPIGateway.TerminalControls.CustomActionGetter += RemoveVanillaSpawnAction; MyLog.Default.WriteLineAndConsole("Instant Projector initialized."); init = true; }
public override MyDefinitionId GetObject(byte[] data, ref int offset) { return(new MyDefinitionId(MyObjectBuilderType.Parse(r.GetObject(data, ref offset)), r.GetObject(data, ref offset))); }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var definitionBuilder = (builder as MyObjectBuilder_ContainerDefinition); Flags = definitionBuilder.Flags; if (definitionBuilder.DefaultComponents != null && definitionBuilder.DefaultComponents.Length > 0) { if (DefaultComponents == null) { DefaultComponents = new List <DefaultComponent>(); } foreach (var component in definitionBuilder.DefaultComponents) { DefaultComponent defComponent = new DefaultComponent(); try { if (component.BuilderType != null) { MyObjectBuilderType obType; obType = MyObjectBuilderType.Parse(component.BuilderType); defComponent.BuilderType = obType; } } catch (Exception) { System.Diagnostics.Debug.Fail(String.Format("Can not parse defined component builder type {0} for container {1}", component.BuilderType.ToString(), Id.ToString())); MyLog.Default.WriteLine(String.Format("Container definition error: can not parse defined component type {0} for container {1}", component, Id.ToString())); } try { if (component.InstanceType != null) { Type runtimeType = Type.GetType(component.InstanceType, true); defComponent.InstanceType = runtimeType; } } catch (Exception) { System.Diagnostics.Debug.Fail(String.Format("Can not parse defined component instance type {0} for container {1}", component.InstanceType.ToString(), Id.ToString())); MyLog.Default.WriteLine(String.Format("Container definition error: can not parse defined component type {0} for container {1}", component, Id.ToString())); } defComponent.ForceCreate = component.ForceCreate; if (component.SubtypeId != null) { defComponent.SubtypeId = MyStringHash.GetOrCompute(component.SubtypeId); } if (defComponent.IsValid()) { DefaultComponents.Add(defComponent); } else { System.Diagnostics.Debug.Fail(String.Format("Defined component {0} for container {1} is invalid, none builder type or instance type is defined! Skipping it.", component, Id.ToString())); MyLog.Default.WriteLine(String.Format("Defined component {0} for container {1} is invalid, none builder type or instance type is defined! Skipping it.", component, Id.ToString())); } } } }