public void MoveFirstItemToConstructionStockpile(IMyComponentInventory fromInventory) { if (MySession.Static.CreativeMode) { return; } EnsureConstructionStockpileExists(); MyComponentStack.GroupInfo info = ComponentStack.GetGroupInfo(0); m_stockpile.ClearSyncList(); if ((int)fromInventory.GetItemAmount(info.Component.Id) >= 1) { //Other player cant move your inventory and you also when trying to cosntruct so its safe already after check above ^^ fromInventory.RemoveItemsOfType(1, info.Component.Id, MyItemFlags.None); //Debug.Assert(removed, "Item not found, but reported available few lines above"); m_stockpile.AddItems(1, info.Component.Id); } CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList()); m_stockpile.ClearSyncList(); }
public void MoveItemsToConstructionStockpile(IMyComponentInventory fromInventory) { if (MySession.Static.CreativeMode || MySession.Static.SimpleSurvival) return; m_tmpComponents.Clear(); GetMissingComponents(m_tmpComponents); if (m_tmpComponents.Count() != 0) { EnsureConstructionStockpileExists(); m_stockpile.ClearSyncList(); foreach (var kv in m_tmpComponents) { var id = new MyDefinitionId(typeof(MyObjectBuilder_Component), kv.Key); int amountAvailable = (int)fromInventory.GetItemAmount(id); int moveAmount = Math.Min(kv.Value, amountAvailable); if (moveAmount > 0) { fromInventory.RemoveItemsOfType(moveAmount, id); m_stockpile.AddItems(moveAmount, new MyDefinitionId(typeof(MyObjectBuilder_Component), kv.Key)); } } CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList()); m_stockpile.ClearSyncList(); } }
public static void SetBlockComponents(MyHudBlockInfo hudInfo, MySlimBlock block, IMyComponentInventory availableInventory = null) { hudInfo.Components.Clear(); for (int i = 0; i < block.ComponentStack.GroupCount; i++) { var groupInfo = block.ComponentStack.GetGroupInfo(i); var componentInfo = new MyHudBlockInfo.ComponentInfo(); componentInfo.DefinitionId = groupInfo.Component.Id; componentInfo.ComponentName = groupInfo.Component.DisplayNameText; componentInfo.Icon = groupInfo.Component.Icon; componentInfo.TotalCount = groupInfo.TotalCount; componentInfo.MountedCount = groupInfo.MountedCount; if (availableInventory != null) componentInfo.AvailableAmount = (int)availableInventory.GetItemAmount(groupInfo.Component.Id); hudInfo.Components.Add(componentInfo); } if (!block.StockpileEmpty) { // For each component foreach (var comp in block.BlockDefinition.Components) { // Get amount in stockpile int amount = block.GetConstructionStockpileItemAmount(comp.Definition.Id); for (int i = 0; amount > 0 && i < hudInfo.Components.Count; i++) { if (block.ComponentStack.GetGroupInfo(i).Component == comp.Definition) { if (block.ComponentStack.IsFullyDismounted) { return; } // Distribute amount in stockpile from bottom to top var info = hudInfo.Components[i]; int space = info.TotalCount - info.MountedCount; int movedItems = Math.Min(space, amount); info.StockpileCount = movedItems; amount -= movedItems; hudInfo.Components[i] = info; } } } } }