From 369eef146f8cff3d6cc4b829cc67a4772d1c5b23 Mon Sep 17 00:00:00 2001 From: Coolsurf6 Date: Sat, 19 Apr 2025 11:23:58 +1000 Subject: [PATCH] Fixed Attachbodypart Console Command (#34577) * remade command for attachbodypart * fixed up WriteError --- .../Body/Commands/AttachBodyPartCommand.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/Content.Server/Body/Commands/AttachBodyPartCommand.cs b/Content.Server/Body/Commands/AttachBodyPartCommand.cs index 82f7161937..9172e9e87e 100644 --- a/Content.Server/Body/Commands/AttachBodyPartCommand.cs +++ b/Content.Server/Body/Commands/AttachBodyPartCommand.cs @@ -100,21 +100,23 @@ namespace Content.Server.Body.Commands var slotId = $"AttachBodyPartVerb-{partUid}"; - // ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract - if (body.RootContainer.ContainedEntity != null) + if (body.RootContainer.ContainedEntity is null && !bodySystem.AttachPartToRoot(bodyId, partUid.Value, body, part)) { - bodySystem.AttachPartToRoot(bodyId, partUid.Value, body, part); + shell.WriteError("Body container does not have a root entity to attach to the body part!"); + return; } - else + + var (rootPartId, rootPart) = bodySystem.GetRootPartOrNull(bodyId, body)!.Value; + if (!bodySystem.TryCreatePartSlotAndAttach(rootPartId, + slotId, + partUid.Value, + part.PartType, + rootPart, + part)) { - var (rootPartId, rootPart) = bodySystem.GetRootPartOrNull(bodyId, body)!.Value; - if (!bodySystem.TryCreatePartSlotAndAttach(rootPartId, slotId, partUid.Value, part.PartType, rootPart, part)) - { - shell.WriteError($"Could not create slot {slotId} on entity {_entManager.ToPrettyString(bodyId)}"); - return; - } + shell.WriteError($"Could not create slot {slotId} on entity {_entManager.ToPrettyString(bodyId)}"); + return; } - shell.WriteLine($"Attached part {_entManager.ToPrettyString(partUid.Value)} to {_entManager.ToPrettyString(bodyId)}"); } } -- 2.51.2