private void InitBlock() { var owner = Entity as MyCubeBlock; MyInventory blockInventory = null; owner.Components.ComponentAdded -= OnNewComponentAdded; if (owner != null) { if (owner.InventoryCount == 0) { // Inventory wasn't created yet, let's wait for it to be added.. owner.Components.ComponentAdded += OnNewComponentAdded; return; } else { blockInventory = owner.GetInventory(); } System.Diagnostics.Debug.Assert(blockInventory != null, "Block inventory was not initialized!"); blockInventory.SetFlags(MyInventoryFlags.CanReceive | MyInventoryFlags.CanSend); System.Diagnostics.Debug.Assert(blockInventory.MaxVolume > 0, "Max volume of the inventory is not positive, items won't be added!"); System.Diagnostics.Debug.Assert(blockInventory.MaxMass > 0, "Max volume of the inventory is not positive, items won't be added!"); var inventoryConstraint = new MyInventoryConstraint("Crafting constraints"); foreach (var blueprintClass in m_blueprintClasses) { foreach (var blueprint in blueprintClass) { foreach (var item in blueprint.Results) { inventoryConstraint.Add(item.Id); } foreach (var item in blueprint.Prerequisites) { inventoryConstraint.Add(item.Id); } } } blockInventory.Constraint = inventoryConstraint; } else { System.Diagnostics.Debug.Fail("InitBlockInventory can be called only when Entity owning this component is not null and is MyEntity type "); } UpdateBlock(); }
void DoChangeListId(SerializableDefinitionId id, bool add) { if (add) m_inventoryConstraint.Add(id); else m_inventoryConstraint.Remove(id); // Recompute because of new sorter settings CubeGrid.GridSystems.ConveyorSystem.FlagForRecomputation(); if (m_allowCurrentListUpdate) currentList.UpdateVisual(); }
internal bool DoChangeListId(SerializableDefinitionId id, bool add) { if (add) { m_inventoryConstraint.Add(id); } else { m_inventoryConstraint.Remove(id); } if (m_allowCurrentListUpdate) { currentList.UpdateVisual(); } return(true); }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var ob = builder as MyObjectBuilder_InventoryComponentDefinition; Volume = ob.Volume; if (ob.Size != null) { Vector3 size = ob.Size.Value; Volume = size.Volume; } Mass = ob.Mass; RemoveEntityOnEmpty = ob.RemoveEntityOnEmpty; MultiplierEnabled = ob.MultiplierEnabled; MaxItemCount = ob.MaxItemCount; if (ob.InputConstraint != null) { InputConstraint = new MyInventoryConstraint("Input", whitelist: ob.InputConstraint.IsWhitelist); foreach (var constraint in ob.InputConstraint.Entries) { if (string.IsNullOrEmpty(constraint.SubtypeName)) { InputConstraint.AddObjectBuilderType(constraint.TypeId); } else { InputConstraint.Add(constraint); } } } }
protected override void Init(MyObjectBuilder_DefinitionBase builder) { base.Init(builder); var ob = builder as MyObjectBuilder_InventoryComponentDefinition; Volume = ob.Volume; if (ob.Size != null) { Vector3 size = ob.Size.Value; Volume = size.Volume; } Mass = ob.Mass; RemoveEntityOnEmpty = ob.RemoveEntityOnEmpty; MultiplierEnabled = ob.MultiplierEnabled; MaxItemCount = ob.MaxItemCount; if (ob.InputConstraint != null) { InputConstraint = new MyInventoryConstraint("Input", whitelist: ob.InputConstraint.IsWhitelist); foreach (var constraint in ob.InputConstraint.Entries) { if (string.IsNullOrEmpty(constraint.SubtypeName)) InputConstraint.AddObjectBuilderType(constraint.TypeId); else InputConstraint.Add(constraint); } } }
private MyInventoryConstraint PrepareConstraint(MyStringId descriptionId, IEnumerable <MyBlueprintClassDefinition> classes, bool input) { string icon = null; foreach (MyBlueprintClassDefinition definition in classes) { string str2 = input ? definition.InputConstraintIcon : definition.OutputConstraintIcon; if (str2 != null) { if (icon == null) { icon = str2; continue; } if (icon != str2) { icon = null; break; } } } MyInventoryConstraint constraint = new MyInventoryConstraint(string.Format(MyTexts.GetString(descriptionId), this.DisplayNameText), icon, true); using (IEnumerator <MyBlueprintClassDefinition> enumerator = classes.GetEnumerator()) { while (enumerator.MoveNext()) { IEnumerator <MyBlueprintDefinitionBase> enumerator2 = enumerator.Current.GetEnumerator(); try { while (enumerator2.MoveNext()) { MyBlueprintDefinitionBase current = enumerator2.Current; foreach (MyBlueprintDefinitionBase.Item item in input ? current.Prerequisites : current.Results) { constraint.Add(item.Id); } } } finally { if (enumerator2 == null) { continue; } enumerator2.Dispose(); } } } return(constraint); }
public MyInventoryConstraint CreateAmmoInventoryConstraints(String displayName) { StringBuilder sb = new StringBuilder(); sb.AppendFormat(MyTexts.GetString(MySpaceTexts.ToolTipItemFilter_AmmoMagazineInput), displayName); MyInventoryConstraint output = new MyInventoryConstraint(sb.ToString()); foreach (MyDefinitionId ammoMagazineId in m_weaponProperties.WeaponDefinition.AmmoMagazinesId) { output.Add(ammoMagazineId); } return(output); }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; base.Init(objectBuilder, cubeGrid); var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator; InitializeConveyorEndpoint(); m_useConveyorSystem = generatorBuilder.UseConveyorSystem; NeedsUpdate = Common.MyEntityUpdateEnum.EACH_100TH_FRAME; m_inventory = new MyInventory( BlockDefinition.InventoryMaxVolume, BlockDefinition.InventorySize, MyInventoryFlags.CanReceive, this); m_inventory.Constraint = BlockDefinition.InputInventoryConstraint; m_oreConstraint = new MyInventoryConstraint(m_inventory.Constraint.Description, m_inventory.Constraint.Icon, m_inventory.Constraint.IsWhitelist); foreach (var id in m_inventory.Constraint.ConstrainedIds) { if (id.TypeId != typeof(MyObjectBuilder_OxygenContainerObject)) { m_oreConstraint.Add(id); } } m_inventory.Init(generatorBuilder.Inventory); m_inventory.ContentsChanged += m_inventory_ContentsChanged; m_autoRefill = generatorBuilder.AutoRefill; PowerReceiver = new MyPowerReceiver( MyConsumerGroupEnum.Factory, false, BlockDefinition.OperationalPowerConsumption, ComputeRequiredPower); PowerReceiver.IsPoweredChanged += PowerReceiver_IsPoweredChanged; PowerReceiver.Update(); UpdateEmissivity(); UpdateText(); AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint)); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; }
public override void UpdateOnceBeforeFrame() { MyInventory inv = (MyInventory)Entity.GetInventory(0); if (inv == null) { return; } if (inv.Constraint == null) { MyInventoryConstraint constraint = new MyInventoryConstraint("Inventory: Diesel Not Allowed", null, false); constraint.Add(new MyDefinitionId(PhysicalFuelObject.TypeId, PhysicalFuelObject.SubtypeId)); inv.Constraint = constraint; } else if (inv.Constraint.IsWhitelist == false) { inv.Constraint.Add(new MyDefinitionId(PhysicalFuelObject.TypeId, PhysicalFuelObject.SubtypeId)); } NeedsUpdate = MyEntityUpdateEnum.NONE; }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; var sourceDataList = new List<MyResourceSourceInfo>(); foreach (var producedInfo in BlockDefinition.ProducedGases) sourceDataList.Add(new MyResourceSourceInfo { ResourceTypeId = producedInfo.Id, DefinedOutput = BlockDefinition.IceConsumptionPerSecond * producedInfo.IceToGasRatio * (MySession.Static.CreativeMode ? 10f : 1f), ProductionToCapacityMultiplier = 1 }); SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList); base.Init(objectBuilder, cubeGrid); var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator; InitializeConveyorEndpoint(); m_useConveyorSystem.Value = generatorBuilder.UseConveyorSystem; NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; if (this.GetInventory() == null) // can be already initialized as deserialized component { MyInventory inventory = new MyInventory(BlockDefinition.InventoryMaxVolume, BlockDefinition.InventorySize, MyInventoryFlags.CanReceive); inventory.Constraint = BlockDefinition.InputInventoryConstraint; Components.Add<MyInventoryBase>(inventory); } else { this.GetInventory().Constraint = BlockDefinition.InputInventoryConstraint; } Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!"); m_oreConstraint = new MyInventoryConstraint(this.GetInventory().Constraint.Description, this.GetInventory().Constraint.Icon, this.GetInventory().Constraint.IsWhitelist); foreach (var id in this.GetInventory().Constraint.ConstrainedIds) { if (id.TypeId != typeof(MyObjectBuilder_GasContainerObject)) m_oreConstraint.Add(id); } if (MyFakes.ENABLE_INVENTORY_FIX) { FixSingleInventory(); } if (this.GetInventory() != null) { this.GetInventory().Init(generatorBuilder.Inventory); } else { Debug.Fail("Trying to init inventory, but it's null!"); } AutoRefill = generatorBuilder.AutoRefill; SourceComp.Enabled = Enabled; if (Sync.IsServer) SourceComp.OutputChanged += Source_OutputChanged; float iceAmount = IceAmount(); foreach (var gasId in SourceComp.ResourceTypes) { var tmpGasId = gasId; m_sourceComp.SetRemainingCapacityByType(gasId, IceToGas(ref tmpGasId, iceAmount)); } m_lastSourceUpdate = MySession.Static.GameplayFrameCounter; ResourceSink.Init(BlockDefinition.ResourceSinkGroup, new MyResourceSinkInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower }); ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged; ResourceSink.Update(); UpdateEmissivity(); UpdateText(); AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint)); m_useConveyorSystem.Value = generatorBuilder.UseConveyorSystem; SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; IsWorkingChanged += MyGasGenerator_IsWorkingChanged; }
public MyInventoryConstraint CreateAmmoInventoryConstraints(String displayName) { StringBuilder sb = new StringBuilder(); sb.AppendFormat(MyTexts.GetString(MySpaceTexts.ToolTipItemFilter_AmmoMagazineInput), displayName); MyInventoryConstraint output = new MyInventoryConstraint(sb.ToString()); foreach (MyDefinitionId ammoMagazineId in m_weaponProperties.WeaponDefinition.AmmoMagazinesId) output.Add(ammoMagazineId); return output; }
public void LoadPostProcess() { // Remove invalid blueprint classes for (int i = 0; i < BlueprintClasses.Count;) { if (!BlueprintClassCanBeUsed(BlueprintClasses[i])) { BlueprintClasses.RemoveAt(i); } else { ++i; } } // Set the constraint icons only if all the blueprint classes agree upon them string firstInputIcon = null; string firstOutputIcon = null; if (BlueprintClasses.Count != 0) { firstInputIcon = BlueprintClasses[0].InputConstraintIcon; firstOutputIcon = BlueprintClasses[0].OutputConstraintIcon; for (int i = 1; i < BlueprintClasses.Count; ++i) { if (BlueprintClasses[i].InputConstraintIcon != firstInputIcon) { firstInputIcon = null; } if (BlueprintClasses[i].OutputConstraintIcon != firstOutputIcon) { firstOutputIcon = null; } } } StringBuilder sb = new StringBuilder(); sb.AppendFormat(MySpaceTexts.ToolTipItemFilter_GenericProductionBlockInput, DisplayNameText); InputInventoryConstraint = new MyInventoryConstraint(sb.ToString(), firstInputIcon); sb = new StringBuilder(); sb.AppendFormat(MySpaceTexts.ToolTipItemFilter_GenericProductionBlockOutput, DisplayNameText); OutputInventoryConstraint = new MyInventoryConstraint(sb.ToString(), firstOutputIcon); for (int i = 0; i < BlueprintClasses.Count; ++i) { foreach (var blueprint in BlueprintClasses[i]) { foreach (var input in blueprint.Prerequisites) { InputInventoryConstraint.Add(input.Id); } foreach (var output in blueprint.Results) { OutputInventoryConstraint.Add(output.Id); } } } }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; var sourceDataList = new List <MyResourceSourceInfo>(); foreach (var producedInfo in BlockDefinition.ProducedGases) { sourceDataList.Add(new MyResourceSourceInfo { ResourceTypeId = producedInfo.Id, DefinedOutput = BlockDefinition.IceConsumptionPerSecond * producedInfo.IceToGasRatio * (MySession.Static.CreativeMode ? 10f : 1f), ProductionToCapacityMultiplier = 1 }); } SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList); base.Init(objectBuilder, cubeGrid); var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator; InitializeConveyorEndpoint(); m_useConveyorSystem.Value = generatorBuilder.UseConveyorSystem; NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; if (this.GetInventory() == null) // can be already initialized as deserialized component { MyInventory inventory = new MyInventory(BlockDefinition.InventoryMaxVolume, BlockDefinition.InventorySize, MyInventoryFlags.CanReceive); inventory.Constraint = BlockDefinition.InputInventoryConstraint; Components.Add <MyInventoryBase>(inventory); } else { this.GetInventory().Constraint = BlockDefinition.InputInventoryConstraint; } Debug.Assert(this.GetInventory().Owner == this, "Ownership was not set!"); m_oreConstraint = new MyInventoryConstraint(this.GetInventory().Constraint.Description, this.GetInventory().Constraint.Icon, this.GetInventory().Constraint.IsWhitelist); foreach (var id in this.GetInventory().Constraint.ConstrainedIds) { if (id.TypeId != typeof(MyObjectBuilder_GasContainerObject)) { m_oreConstraint.Add(id); } } if (MyFakes.ENABLE_INVENTORY_FIX) { FixSingleInventory(); } if (this.GetInventory() != null) { this.GetInventory().Init(generatorBuilder.Inventory); } else { Debug.Fail("Trying to init inventory, but it's null!"); } AutoRefill = generatorBuilder.AutoRefill; SourceComp.Enabled = Enabled; if (Sync.IsServer) { SourceComp.OutputChanged += Source_OutputChanged; } float iceAmount = IceAmount(); foreach (var gasId in SourceComp.ResourceTypes) { var tmpGasId = gasId; m_sourceComp.SetRemainingCapacityByType(gasId, IceToGas(ref tmpGasId, iceAmount)); } m_lastSourceUpdate = MySession.Static.GameplayFrameCounter; ResourceSink.Init(BlockDefinition.ResourceSinkGroup, new MyResourceSinkInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower }); ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged; ResourceSink.Update(); UpdateEmissivity(); UpdateText(); AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint)); m_useConveyorSystem.Value = generatorBuilder.UseConveyorSystem; SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; IsWorkingChanged += MyGasGenerator_IsWorkingChanged; }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; base.Init(objectBuilder, cubeGrid); var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator; InitializeConveyorEndpoint(); m_useConveyorSystem = generatorBuilder.UseConveyorSystem; NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME; m_inventory = new MyInventory( BlockDefinition.InventoryMaxVolume, BlockDefinition.InventorySize, MyInventoryFlags.CanReceive, this) { Constraint = BlockDefinition.InputInventoryConstraint }; m_oreConstraint = new MyInventoryConstraint(m_inventory.Constraint.Description, m_inventory.Constraint.Icon, m_inventory.Constraint.IsWhitelist); foreach (var id in m_inventory.Constraint.ConstrainedIds) { if (id.TypeId != typeof(MyObjectBuilder_GasContainerObject)) m_oreConstraint.Add(id); } m_inventory.Init(generatorBuilder.Inventory); m_inventory.ContentsChanged += Inventory_ContentsChanged; AutoRefill = generatorBuilder.AutoRefill; var sourceDataList = new List<MyResourceSourceInfo>(); foreach (var producedInfo in BlockDefinition.ProducedGases) sourceDataList.Add(new MyResourceSourceInfo { ResourceTypeId = producedInfo.Id, DefinedOutput = BlockDefinition.IceConsumptionPerSecond * producedInfo.IceToGasRatio, ProductionToCapacityMultiplier = 1 }); SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList); if (Sync.IsServer) SourceComp.OutputChanged += Source_OutputChanged; float iceAmount = IceAmount(); foreach (var gasId in SourceComp.ResourceTypes) m_sourceComp.SetRemainingCapacityByType(gasId, IceToGas(gasId, iceAmount)); m_updateCounter = 0; m_lastSourceUpdate = m_updateCounter; ResourceSink.Init(BlockDefinition.ResourceSinkGroup, new MyResourceSinkInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower }); ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged; ResourceSink.Update(); UpdateEmissivity(); UpdateText(); AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint)); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; IsWorkingChanged += MyGasGenerator_IsWorkingChanged; }
private void InitBlock() { MyCubeBlock entity = base.Entity as MyCubeBlock; MyInventory inventory = null; entity.Components.ComponentAdded -= new Action <System.Type, MyEntityComponentBase>(this.OnNewComponentAdded); if (entity != null) { if (entity.InventoryCount == 0) { entity.Components.ComponentAdded += new Action <System.Type, MyEntityComponentBase>(this.OnNewComponentAdded); return; } inventory = entity.GetInventory(0); inventory.SetFlags(MyInventoryFlags.CanSend | MyInventoryFlags.CanReceive); MyInventoryConstraint constraint = new MyInventoryConstraint("Crafting constraints", null, true); using (List <MyBlueprintClassDefinition> .Enumerator enumerator = base.m_blueprintClasses.GetEnumerator()) { while (enumerator.MoveNext()) { IEnumerator <MyBlueprintDefinitionBase> enumerator2 = enumerator.Current.GetEnumerator(); try { while (enumerator2.MoveNext()) { MyBlueprintDefinitionBase current = enumerator2.Current; MyBlueprintDefinitionBase.Item[] results = current.Results; int index = 0; while (true) { if (index >= results.Length) { results = current.Prerequisites; index = 0; while (index < results.Length) { MyBlueprintDefinitionBase.Item item2 = results[index]; constraint.Add(item2.Id); index++; } break; } MyBlueprintDefinitionBase.Item item = results[index]; constraint.Add(item.Id); index++; } } } finally { if (enumerator2 == null) { continue; } enumerator2.Dispose(); } } } inventory.Constraint = constraint; } this.UpdateBlock(); }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; base.Init(objectBuilder, cubeGrid); var generatorBuilder = objectBuilder as MyObjectBuilder_OxygenGenerator; InitializeConveyorEndpoint(); m_useConveyorSystem = generatorBuilder.UseConveyorSystem; NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME; m_inventory = new MyInventory( BlockDefinition.InventoryMaxVolume, BlockDefinition.InventorySize, MyInventoryFlags.CanReceive, this) { Constraint = BlockDefinition.InputInventoryConstraint }; m_oreConstraint = new MyInventoryConstraint(m_inventory.Constraint.Description, m_inventory.Constraint.Icon, m_inventory.Constraint.IsWhitelist); foreach (var id in m_inventory.Constraint.ConstrainedIds) { if (id.TypeId != typeof(MyObjectBuilder_GasContainerObject)) { m_oreConstraint.Add(id); } } m_inventory.Init(generatorBuilder.Inventory); m_inventory.ContentsChanged += Inventory_ContentsChanged; AutoRefill = generatorBuilder.AutoRefill; var sourceDataList = new List <MyResourceSourceInfo>(); foreach (var producedInfo in BlockDefinition.ProducedGases) { sourceDataList.Add(new MyResourceSourceInfo { ResourceTypeId = producedInfo.Id, DefinedOutput = BlockDefinition.IceConsumptionPerSecond * producedInfo.IceToGasRatio, ProductionToCapacityMultiplier = 1 }); } SourceComp.Init(BlockDefinition.ResourceSourceGroup, sourceDataList); if (Sync.IsServer) { SourceComp.OutputChanged += Source_OutputChanged; } float iceAmount = IceAmount(); foreach (var gasId in SourceComp.ResourceTypes) { m_sourceComp.SetRemainingCapacityByType(gasId, IceToGas(gasId, iceAmount)); } m_updateCounter = 0; m_lastSourceUpdate = m_updateCounter; ResourceSink.Init(BlockDefinition.ResourceSinkGroup, new MyResourceSinkInfo { ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower }); ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged; ResourceSink.Update(); UpdateEmissivity(); UpdateText(); AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint)); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; IsWorkingChanged += MyGasGenerator_IsWorkingChanged; }