diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 97198b19c..c8284253c 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -36,14 +36,17 @@ END TEMPLATE--> ### Breaking changes * Remove the duplicate serialization copy of components kept on ComponentRegistryEntry; now it only stores the deserialized component. To get the raw MappingDataNode for EntityPrototypes use PrototypeManager. This is expected to significantly reduce memory usage. +* 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 * Add a BoundUserInterfaceMessageReceivedEvent that will be raised whenever a BoundUserInterfaceMessage is received regardless of validation. +* SpawnNextToOrDrop methods can now offset their spawns by passing in a Vector2. This offset is always relative to the target. ### Bugfixes * Windows will stay at relative position not absolute pixel position on window resize. +* 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 a83ef38a9..c4694061e 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; @@ -69,9 +70,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 94a86489b..df62e04e2 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; @@ -141,9 +141,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; } @@ -183,15 +183,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; } @@ -275,9 +277,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 9c4c05504..676d06851 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; @@ -1013,12 +1014,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); } /// @@ -1088,12 +1089,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 9a973cb4f..234a3e210 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 2fa10c984..01d06434b 100644 --- a/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs +++ b/Robust.Shared/GameObjects/Systems/SharedTransformSystem.Component.cs @@ -1634,7 +1634,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)) @@ -1647,7 +1647,7 @@ public void DropNextTo(Entity entity, Entity