Fixed oxygen tank & welding fuel tank crafting causing everyone to desync. The item condition NetEntityEvent was created before the spawn event of the item, preventing clients from reading the condition event because the item doesn't exist yet. Closes #617
This commit is contained in:
@@ -12,6 +12,7 @@ namespace Barotrauma.Items.Components
|
||||
{
|
||||
public readonly ItemPrefab TargetItem;
|
||||
|
||||
//TODO: refactor this (maybe make it a struct)
|
||||
public readonly List<Tuple<ItemPrefab, int, float, bool>> RequiredItems;
|
||||
|
||||
public readonly float RequiredTime;
|
||||
|
||||
@@ -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<Items.Components.ItemContainer>();
|
||||
if (containers != null && containers.Any())
|
||||
if ((inventoryOwner as Item).components[itemContainerIndex] is ItemContainer container)
|
||||
{
|
||||
inventory = containers.Last().Inventory;
|
||||
inventory = container.Inventory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user