diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs index ca08ce693..9c1693851 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Machines/Fabricator.cs @@ -12,6 +12,7 @@ namespace Barotrauma.Items.Components { public readonly ItemPrefab TargetItem; + //TODO: refactor this (maybe make it a struct) public readonly List> RequiredItems; public readonly float RequiredTime; diff --git a/Barotrauma/BarotraumaShared/Source/Items/Item.cs b/Barotrauma/BarotraumaShared/Source/Items/Item.cs index bad381cb9..bd0b18f85 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Item.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Item.cs @@ -1659,8 +1659,25 @@ namespace Barotrauma { msg.Write(ParentInventory.Owner.ID); - int index = ParentInventory.FindIndex(this); - msg.Write(index < 0 ? (byte)255 : (byte)index); + //find the index of the ItemContainer this item is inside to get the item to + //spawn in the correct inventory in multi-inventory items like fabricators + byte containerIndex = 0; + if (Container != null) + { + for (int i = 0; i < Container.components.Count; i++) + { + if (Container.components[i] is ItemContainer container && + container.Inventory == ParentInventory) + { + containerIndex = (byte)i; + break; + } + } + } + msg.Write(containerIndex); + + int slotIndex = ParentInventory.FindIndex(this); + msg.Write(slotIndex < 0 ? (byte)255 : (byte)slotIndex); } byte teamID = 0; @@ -1698,10 +1715,12 @@ namespace Barotrauma Vector2 pos = Vector2.Zero; Submarine sub = null; + int itemContainerIndex = -1; int inventorySlotIndex = -1; if (inventoryId > 0) { + itemContainerIndex = msg.ReadByte(); inventorySlotIndex = msg.ReadByte(); } else @@ -1741,10 +1760,9 @@ namespace Barotrauma } else if (inventoryOwner is Item) { - var containers = (inventoryOwner as Item).GetComponents(); - if (containers != null && containers.Any()) + if ((inventoryOwner as Item).components[itemContainerIndex] is ItemContainer container) { - inventory = containers.Last().Inventory; + inventory = container.Inventory; } } } diff --git a/Barotrauma/BarotraumaShared/Source/Networking/EntitySpawner.cs b/Barotrauma/BarotraumaShared/Source/Networking/EntitySpawner.cs index 14bd2ad22..4dc229269 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/EntitySpawner.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/EntitySpawner.cs @@ -49,7 +49,6 @@ namespace Barotrauma public Entity Spawn() { Item spawnedItem = null; - if (Inventory != null) { spawnedItem = new Item(Prefab, Vector2.Zero, null); @@ -59,8 +58,6 @@ namespace Barotrauma { spawnedItem = new Item(Prefab, Position, Submarine); } - spawnedItem.Condition = Condition; - return spawnedItem; } } @@ -159,6 +156,10 @@ namespace Barotrauma if (spawnedEntity != null) { CreateNetworkEvent(spawnedEntity, false); + if (spawnedEntity is Item) + { + ((Item)spawnedEntity).Condition = ((ItemSpawnInfo)entitySpawnInfo).Condition; + } } }