Fixed items not being placed in the same hull and sub as the item they're inside if the ItemContainer is not the first of the parent's ItemContainer components (e.g. fabricator output inventory). Closes #430
This commit is contained in:
@@ -179,7 +179,6 @@ namespace Barotrauma.Items.Components
|
|||||||
return (picker != null);
|
return (picker != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override bool Combine(Item item)
|
public override bool Combine(Item item)
|
||||||
{
|
{
|
||||||
if (!containableItems.Any(x => x.MatchesItem(item))) return false;
|
if (!containableItems.Any(x => x.MatchesItem(item))) return false;
|
||||||
@@ -195,6 +194,42 @@ namespace Barotrauma.Items.Components
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetContainedItemPositions()
|
||||||
|
{
|
||||||
|
Vector2 simPos = item.SimPosition;
|
||||||
|
Vector2 displayPos = item.Position;
|
||||||
|
|
||||||
|
foreach (Item contained in Inventory.Items)
|
||||||
|
{
|
||||||
|
if (contained == null) continue;
|
||||||
|
|
||||||
|
if (contained.body != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
contained.body.FarseerBody.SetTransformIgnoreContacts(ref simPos, 0.0f);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
DebugConsole.ThrowError("SetTransformIgnoreContacts threw an exception in SetContainedItemPositions", e);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contained.Rect =
|
||||||
|
new Rectangle(
|
||||||
|
(int)(displayPos.X - contained.Rect.Width / 2.0f),
|
||||||
|
(int)(displayPos.Y + contained.Rect.Height / 2.0f),
|
||||||
|
contained.Rect.Width, contained.Rect.Height);
|
||||||
|
|
||||||
|
contained.Submarine = item.Submarine;
|
||||||
|
contained.CurrentHull = item.CurrentHull;
|
||||||
|
|
||||||
|
contained.SetContainedItemPositions();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void OnMapLoaded()
|
public override void OnMapLoaded()
|
||||||
{
|
{
|
||||||
if (itemIds == null) return;
|
if (itemIds == null) return;
|
||||||
|
|||||||
@@ -602,7 +602,7 @@ namespace Barotrauma
|
|||||||
foreach (Item item in ItemList) item.FindHull();
|
foreach (Item item in ItemList) item.FindHull();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Hull FindHull()
|
public Hull FindHull()
|
||||||
{
|
{
|
||||||
if (parentInventory != null && parentInventory.Owner != null)
|
if (parentInventory != null && parentInventory.Owner != null)
|
||||||
{
|
{
|
||||||
@@ -648,39 +648,9 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public void SetContainedItemPositions()
|
public void SetContainedItemPositions()
|
||||||
{
|
{
|
||||||
if (ownInventory == null) return;
|
foreach (ItemComponent component in components)
|
||||||
|
|
||||||
Vector2 simPos = SimPosition;
|
|
||||||
Vector2 displayPos = Position;
|
|
||||||
|
|
||||||
foreach (Item contained in ownInventory.Items)
|
|
||||||
{
|
{
|
||||||
if (contained == null) continue;
|
(component as ItemContainer)?.SetContainedItemPositions();
|
||||||
|
|
||||||
if (contained.body != null)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
contained.body.FarseerBody.SetTransformIgnoreContacts(ref simPos, 0.0f);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
#if DEBUG
|
|
||||||
DebugConsole.ThrowError("SetTransformIgnoreContacts threw an exception in SetContainedItemPositions", e);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
contained.Rect =
|
|
||||||
new Rectangle(
|
|
||||||
(int)(displayPos.X - contained.Rect.Width / 2.0f),
|
|
||||||
(int)(displayPos.Y + contained.Rect.Height / 2.0f),
|
|
||||||
contained.Rect.Width, contained.Rect.Height);
|
|
||||||
|
|
||||||
contained.Submarine = Submarine;
|
|
||||||
contained.CurrentHull = CurrentHull;
|
|
||||||
|
|
||||||
contained.SetContainedItemPositions();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -804,7 +774,7 @@ namespace Barotrauma
|
|||||||
private bool IsInWater()
|
private bool IsInWater()
|
||||||
{
|
{
|
||||||
if (CurrentHull == null) return true;
|
if (CurrentHull == null) return true;
|
||||||
|
|
||||||
float surfaceY = CurrentHull.Surface;
|
float surfaceY = CurrentHull.Surface;
|
||||||
|
|
||||||
return CurrentHull.WaterVolume > 0.0f && Position.Y < surfaceY;
|
return CurrentHull.WaterVolume > 0.0f && Position.Y < surfaceY;
|
||||||
|
|||||||
Reference in New Issue
Block a user