]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fixed Attachbodypart Console Command (#34577)
authorCoolsurf6 <coolsurf24@yahoo.com.au>
Sat, 19 Apr 2025 01:23:58 +0000 (11:23 +1000)
committerGitHub <noreply@github.com>
Sat, 19 Apr 2025 01:23:58 +0000 (11:23 +1000)
* remade command for attachbodypart

* fixed up WriteError

Content.Server/Body/Commands/AttachBodyPartCommand.cs

index 82f71619370aae36066d963eba345e4d5f563756..9172e9e87ec5d178c4eae0eab845795daa0734ed 100644 (file)
@@ -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)}");
         }
     }