StackSystem uses EntityUid for Split and Spawn

This commit is contained in:
Vera Aguilera Puerto
2021-11-09 15:34:40 +01:00
parent 6f2cc733e7
commit 8b57bafcd1
13 changed files with 60 additions and 44 deletions

View File

@@ -30,10 +30,10 @@ namespace Content.Server.Construction
return;
// If the used entity doesn't have a tool, return early.
if (!EntityManager.TryGetComponent(args.Used.Uid, out ToolComponent? usedTool))
if (!EntityManager.TryGetComponent(args.UsedUid, out ToolComponent? usedTool))
return;
args.Handled = await TryToggleAnchor(uid, args.User.Uid, args.Used.Uid, anchorable, usingTool:usedTool);
args.Handled = await TryToggleAnchor(uid, args.UserUid, args.UsedUid, anchorable, usingTool:usedTool);
}
/// <summary>

View File

@@ -91,7 +91,7 @@ namespace Content.Server.Construction.Components
if (stack == null)
throw new Exception($"Couldn't spawn stack of type {stackType}!");
if (!partContainer.Insert(stack))
if (!partContainer.Insert(Owner.EntityManager.GetEntity(stack)))
throw new Exception($"Couldn't insert machine material of type {stackType} to machine with prototype {Owner.Prototype?.ID ?? "N/A"}");
}

View File

@@ -319,7 +319,7 @@ namespace Content.Server.Construction.Components
if (splitStack == null)
return false;
if(!_partContainer.Insert(splitStack))
if(!_partContainer.Insert(Owner.EntityManager.GetEntity(splitStack.Value)))
return false;
_materialProgress[type] += needed;

View File

@@ -171,10 +171,10 @@ namespace Content.Server.Construction
if (string.IsNullOrEmpty(materialStep.Store))
{
if (!container.Insert(splitStack))
if (!container.Insert(EntityManager.GetEntity(splitStack.Value)))
continue;
}
else if (!GetContainer(materialStep.Store).Insert(splitStack))
else if (!GetContainer(materialStep.Store).Insert(EntityManager.GetEntity(splitStack.Value)))
continue;
handled = true;
@@ -186,7 +186,7 @@ namespace Content.Server.Construction
case ArbitraryInsertConstructionGraphStep arbitraryStep:
foreach (var entity in EnumerateNearby(user))
{
if (!arbitraryStep.EntityValid(entity))
if (!arbitraryStep.EntityValid(entity.Uid, EntityManager))
continue;
if (string.IsNullOrEmpty(arbitraryStep.Store))
@@ -430,7 +430,7 @@ namespace Content.Server.Construction
switch (step)
{
case EntityInsertConstructionGraphStep entityInsert:
if (entityInsert.EntityValid(holding))
if (entityInsert.EntityValid(holding.Uid, EntityManager))
valid = true;
break;
case ToolConstructionGraphStep _:

View File

@@ -273,11 +273,11 @@ namespace Content.Server.Construction
if (doAfterState == DoAfterState.Cancelled)
return HandleResult.False;
var insert = interactUsing.Used;
var insert = interactUsing.UsedUid;
// Since many things inherit this step, we delegate the "is this entity valid?" logic to them.
// While this is very OOP and I find it icky, I must admit that it simplifies the code here a lot.
if(!insertStep.EntityValid(insert))
if(!insertStep.EntityValid(insert, EntityManager))
return HandleResult.False;
// If we're only testing whether this step would be handled by the given event, then we're done.
@@ -312,7 +312,7 @@ namespace Content.Server.Construction
// we split the stack in two and insert the split stack.
if (insertStep is MaterialConstructionGraphStep materialInsertStep)
{
if (_stackSystem.Split(insert.Uid, materialInsertStep.Amount, interactUsing.User.Transform.Coordinates) is not { } stack)
if (_stackSystem.Split(insert, materialInsertStep.Amount, EntityManager.GetComponent<TransformComponent>(interactUsing.UserUid).Coordinates) is not {} stack)
return HandleResult.False;
insert = stack;
@@ -330,12 +330,12 @@ namespace Content.Server.Construction
// The container doesn't necessarily need to exist, so we ensure it.
_containerSystem.EnsureContainer<Container>(uid, store)
.Insert(insert);
.Insert(EntityManager.GetEntity(insert));
}
else
{
// If we don't store the item in a container on the entity, we just delete it right away.
insert.Delete();
EntityManager.DeleteEntity(insert);
}
// Step has been handled correctly, so we signal this.