From 87cb22838b0632b0d4a9242ab65d4ffe57f71930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Aguilera=20Puerto?= Date: Sat, 31 Oct 2020 14:17:33 +0100 Subject: [PATCH] Fix bug where built computers would spawn with an extra board. --- .../Construction/Completions/BuildComputer.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Content.Server/Construction/Completions/BuildComputer.cs b/Content.Server/Construction/Completions/BuildComputer.cs index a377e48993..b2eb368369 100644 --- a/Content.Server/Construction/Completions/BuildComputer.cs +++ b/Content.Server/Construction/Completions/BuildComputer.cs @@ -1,4 +1,5 @@ #nullable enable +using System.Linq; using System.Threading.Tasks; using Content.Server.GameObjects.Components.Construction; using Content.Shared.Construction; @@ -53,7 +54,18 @@ namespace Content.Server.Construction.Completions var computer = entityManager.SpawnEntity(boardComponent.Prototype, entity.Transform.Coordinates); computer.Transform.LocalRotation = entity.Transform.LocalRotation; - var computerContainer = ContainerManagerComponent.Ensure(Container, computer); + var computerContainer = ContainerManagerComponent.Ensure(Container, computer, out var existed); + + if (existed) + { + // In case there are any entities inside this, delete them. + foreach (var ent in computerContainer.ContainedEntities.ToArray()) + { + computerContainer.ForceRemove(ent); + ent.Delete(); + } + } + computerContainer.Insert(board); if (computer.TryGetComponent(out ConstructionComponent? construction))