diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 3de8ed70993..6e6c26f0a3c 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -35,15 +35,16 @@ END TEMPLATE--> ### Breaking changes -*None yet* +* SpawnNextToOrDrop methods have been changed to take `EntProtoId?, Entity, Vector2 = default` instead of `string?, EntityUid, TransformComponent? null`. Because of this, some `Entity`s will need to first be explicity converted into `EntityUid`s. ### New features * The `Color` API now includes a `bool TryFromHex(ReadOnlySpan hexColor, out Color color)` signature for returning a `bool` and `out Color` instead of a `Color?`. +* SpawnNextToOrDrop methods can now offset their spawns by passing in a Vector2. This offset is always relative to the target. ### Bugfixes -*None yet* +* SpawnNextToOrDrop no longer runs mapinit on entities in nullspace. ### Other diff --git a/Robust.Client/GameObjects/ClientEntityManager.Spawn.cs b/Robust.Client/GameObjects/ClientEntityManager.Spawn.cs index 46a97463b6b..b635bd5db61 100644 --- a/Robust.Client/GameObjects/ClientEntityManager.Spawn.cs +++ b/Robust.Client/GameObjects/ClientEntityManager.Spawn.cs @@ -1,4 +1,5 @@ using System.Diagnostics.CodeAnalysis; +using System.Numerics; using System.Runtime.CompilerServices; using Robust.Shared.Containers; using Robust.Shared.GameObjects; @@ -76,9 +77,9 @@ public override bool PredictedTrySpawnInContainer( return true; } - public override EntityUid PredictedSpawnNextToOrDrop(string? protoName, EntityUid target, TransformComponent? xform = null, ComponentRegistry? overrides = null) + public override EntityUid PredictedSpawnNextToOrDrop(EntProtoId? protoName, Entity target, Vector2 offset = default, ComponentRegistry? overrides = null) { - var ent = SpawnNextToOrDrop(protoName, target, xform, overrides); + var ent = SpawnNextToOrDrop(protoName, target, offset, overrides); FlagPredicted(ent); return ent; } diff --git a/Robust.Shared/GameObjects/EntityManager.Spawn.cs b/Robust.Shared/GameObjects/EntityManager.Spawn.cs index 046cf3deab5..541518af18d 100644 --- a/Robust.Shared/GameObjects/EntityManager.Spawn.cs +++ b/Robust.Shared/GameObjects/EntityManager.Spawn.cs @@ -3,11 +3,11 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Numerics; using System.Runtime.CompilerServices; using Robust.Shared.Collections; using Robust.Shared.Containers; using Robust.Shared.Maths; -using Robust.Shared.Serialization; namespace Robust.Shared.GameObjects; @@ -145,9 +145,9 @@ public bool TrySpawnNextTo( if (!xform.ParentUid.IsValid()) return false; - if (!_containers.TryGetContainingContainer(target, out var container)) + if (!_containers.TryGetContainingContainer((target, xform), out var container)) { - uid = SpawnNextToOrDrop(protoName, target, xform, overrides); + uid = SpawnNextToOrDrop(protoName, (target, xform), overrides: overrides); return true; } @@ -187,15 +187,17 @@ public bool TrySpawnInContainer( return false; } - public EntityUid SpawnNextToOrDrop(string? protoName, EntityUid target, TransformComponent? xform = null, ComponentRegistry? overrides = null) + public EntityUid SpawnNextToOrDrop(EntProtoId? protoName, Entity target, Vector2 offset = default, ComponentRegistry? overrides = null) { - xform ??= TransformQuery.GetComponent(target); - if (!xform.ParentUid.IsValid()) - return Spawn(protoName); - - var doMapInit = _mapSystem.IsInitialized(xform.MapUid); - var uid = Spawn(protoName, overrides, doMapInit); - _xforms.DropNextTo(uid, target); + if (!TransformQuery.Resolve(target, ref target.Comp) || + !target.Comp.ParentUid.IsValid()) + return Spawn(protoName, overrides); + + var uid = CreateEntityUninitialized(protoName, out var meta, overrides); + InitializeAndStartEntity((uid, meta), false); + _xforms.DropNextTo(uid, target, offset); + if (_mapSystem.IsInitialized(target.Comp.MapUid)) + RunMapInit(uid, meta); return uid; } @@ -284,9 +286,9 @@ public virtual bool PredictedTrySpawnInContainer( return TrySpawnInContainer(protoName, containerUid, containerId, out uid, containerComp, overrides); } - public virtual EntityUid PredictedSpawnNextToOrDrop(string? protoName, EntityUid target, TransformComponent? xform = null, ComponentRegistry? overrides = null) + public virtual EntityUid PredictedSpawnNextToOrDrop(EntProtoId? protoName, Entity target, Vector2 offset = default, ComponentRegistry? overrides = null) { - return SpawnNextToOrDrop(protoName, target, xform, overrides); + return SpawnNextToOrDrop(protoName, target, offset, overrides); } public virtual EntityUid PredictedSpawnInContainerOrDrop( diff --git a/Robust.Shared/GameObjects/EntitySystem.Proxy.cs b/Robust.Shared/GameObjects/EntitySystem.Proxy.cs index 8a8c7d380f6..9a0b8a5a74b 100644 --- a/Robust.Shared/GameObjects/EntitySystem.Proxy.cs +++ b/Robust.Shared/GameObjects/EntitySystem.Proxy.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Numerics; using System.Runtime.CompilerServices; using JetBrains.Annotations; using Robust.Shared.Containers; @@ -1035,12 +1036,12 @@ protected bool TrySpawnNextTo( [MethodImpl(MethodImplOptions.AggressiveInlining)] [ProxyFor(typeof(EntityManager))] protected EntityUid SpawnNextToOrDrop( - string? protoName, - EntityUid target, - TransformComponent? xform = null, + EntProtoId? protoName, + Entity target, + Vector2 offset = default, ComponentRegistry? overrides = null) { - return EntityManager.SpawnNextToOrDrop(protoName, target, xform, overrides); + return EntityManager.SpawnNextToOrDrop(protoName, target, offset, overrides); } /// @@ -1110,12 +1111,12 @@ protected bool PredictedTrySpawnNextTo( [MethodImpl(MethodImplOptions.AggressiveInlining)] [ProxyFor(typeof(EntityManager))] protected EntityUid PredictedSpawnNextToOrDrop( - string? protoName, - EntityUid target, - TransformComponent? xform = null, + EntProtoId? protoName, + Entity target, + Vector2 offset = default, ComponentRegistry? overrides = null) { - return EntityManager.PredictedSpawnNextToOrDrop(protoName, target, xform, overrides); + return EntityManager.PredictedSpawnNextToOrDrop(protoName, target, offset, overrides); } /// diff --git a/Robust.Shared/GameObjects/IEntityManager.Spawn.cs b/Robust.Shared/GameObjects/IEntityManager.Spawn.cs index 9a973cb4f94..234a3e21028 100644 --- a/Robust.Shared/GameObjects/IEntityManager.Spawn.cs +++ b/Robust.Shared/GameObjects/IEntityManager.Spawn.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using Robust.Shared.Collections; +using System.Numerics; using Robust.Shared.Containers; using Robust.Shared.Map; using Robust.Shared.Maths; @@ -100,8 +100,8 @@ bool TrySpawnNextTo( /// instead attempt to spawn the entity next to the target's parent. /// EntityUid SpawnNextToOrDrop( - string? protoName, - EntityUid target, - TransformComponent? xform = null, + EntProtoId? protoName, + Entity target, + Vector2 offset = default, ComponentRegistry? overrides = null); } diff --git a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs index ed74453afb6..132d324dffe 100644 --- a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs +++ b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs @@ -1664,7 +1664,7 @@ private void OnGridAdd(EntityUid uid, TransformComponent component, GridAddEvent /// this will attempt to insert that entity into the same container. Otherwise it will attach the entity to the /// grid or map at the same world-position as the target entity. /// - public void DropNextTo(Entity entity, Entity target) + public void DropNextTo(Entity entity, Entity target, Vector2 offset = default) { var xform = entity.Comp; if (!XformQuery.Resolve(entity, ref xform)) @@ -1677,7 +1677,7 @@ public void DropNextTo(Entity entity, Entity