From f61015a8672b60e2413a20e28cccd87ba61c767a Mon Sep 17 00:00:00 2001 From: killzoms Date: Tue, 2 Apr 2024 20:39:20 -0400 Subject: [PATCH 1/5] fix entitySlot entities under PrefabPlaceholders --- .../DefaultWorldEntitySpawner.cs | 31 ++++++++++--------- .../PrefabPlaceholderEntitySpawner.cs | 10 ++++-- .../Entities/PrefabPlaceholderEntity.cs | 9 ++++-- .../Entities/Spawning/BatchEntitySpawner.cs | 4 +-- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/NitroxClient/GameLogic/Spawning/WorldEntities/DefaultWorldEntitySpawner.cs b/NitroxClient/GameLogic/Spawning/WorldEntities/DefaultWorldEntitySpawner.cs index df75194fe5..a7d77c3e1a 100644 --- a/NitroxClient/GameLogic/Spawning/WorldEntities/DefaultWorldEntitySpawner.cs +++ b/NitroxClient/GameLogic/Spawning/WorldEntities/DefaultWorldEntitySpawner.cs @@ -38,34 +38,35 @@ private void SetupObject(WorldEntity entity, Optional parent, GameOb CrafterLogic.NotifyCraftEnd(gameObject, techType); WaterPark parentWaterPark = parent.HasValue ? parent.Value.GetComponent() : null; - if (!parentWaterPark) + + if (parent.HasValue) { - if (parent.HasValue && !parent.Value.GetComponent()) - { - LargeWorldEntity.Register(gameObject); // This calls SetActive on the GameObject - } - else if (gameObject.GetComponent() && !gameObject.transform.parent && cellRoot.liveRoot) + if (parentWaterPark && gameObject.TryGetComponent(out Pickupable pickupable)) { - gameObject.transform.SetParent(cellRoot.liveRoot.transform, true); - LargeWorldEntity.Register(gameObject); + pickupable.SetVisible(false); + pickupable.Activate(false); + parentWaterPark.AddItem(pickupable); } else { - gameObject.SetActive(true); + gameObject.transform.SetParent(parent.Value.transform, true); } } - if (parent.HasValue) + if (!parentWaterPark) { - if (parentWaterPark && gameObject.TryGetComponent(out Pickupable pickupable)) + if (parent.HasValue && !parent.Value.GetComponent()) { - pickupable.SetVisible(false); - pickupable.Activate(false); - parentWaterPark.AddItem(pickupable); + LargeWorldEntity.Register(gameObject); // This calls SetActive on the GameObject + } + else if (gameObject.GetComponent() && cellRoot.liveRoot) + { + gameObject.transform.SetParent(cellRoot.liveRoot.transform, true); + LargeWorldEntity.Register(gameObject); } else { - gameObject.transform.SetParent(parent.Value.transform, true); + gameObject.SetActive(true); } } } diff --git a/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs b/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs index 6fd25271eb..97d4175dfe 100644 --- a/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs +++ b/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs @@ -28,7 +28,7 @@ public IEnumerator SpawnAsync(WorldEntity entity, Optional parent, E yield break; } - SetupObject(entity, result.value.Value); + SetupObject(entity, result.value.Value, placeholder.transform.parent.gameObject); } public bool SpawnsOwnChildren() => false; @@ -45,7 +45,7 @@ public bool SpawnSync(WorldEntity entity, Optional parent, EntityCel return false; } - SetupObject(entity, result.value.Value); + SetupObject(entity, result.value.Value, placeholder.transform.parent.gameObject); return true; } @@ -63,10 +63,14 @@ private bool VerifyCanSpawnOrError(WorldEntity entity, Optional pare return false; } - private void SetupObject(WorldEntity entity, GameObject gameObject) + private void SetupObject(WorldEntity entity, GameObject gameObject, GameObject parent) { gameObject.transform.localPosition = entity.Transform.LocalPosition.ToUnity(); gameObject.transform.localRotation = entity.Transform.LocalRotation.ToUnity(); gameObject.transform.localScale = entity.Transform.LocalScale.ToUnity(); + if (entity is PrefabPlaceholderEntity prefabEntity && !prefabEntity.IsEntitySlotEntity && parent) + { + gameObject.transform.SetParent(parent.transform, false); + } } } diff --git a/NitroxModel/DataStructures/GameLogic/Entities/PrefabPlaceholderEntity.cs b/NitroxModel/DataStructures/GameLogic/Entities/PrefabPlaceholderEntity.cs index 293254148e..ee743b9b00 100644 --- a/NitroxModel/DataStructures/GameLogic/Entities/PrefabPlaceholderEntity.cs +++ b/NitroxModel/DataStructures/GameLogic/Entities/PrefabPlaceholderEntity.cs @@ -16,13 +16,16 @@ public class PrefabPlaceholderEntity : WorldEntity [DataMember(Order = 1)] public int ComponentIndex { get; set; } + [DataMember(Order = 2)] + public bool IsEntitySlotEntity { get; set; } + [IgnoreConstructor] protected PrefabPlaceholderEntity() { // Constructor for serialization. Has to be "protected" for json serialization. } - public PrefabPlaceholderEntity(WorldEntity worldEntity, int componentIndex = 0) + public PrefabPlaceholderEntity(WorldEntity worldEntity, bool isEntitySlotEntity, int componentIndex = 0) { Id = worldEntity.Id; TechType = worldEntity.TechType; @@ -34,14 +37,16 @@ public PrefabPlaceholderEntity(WorldEntity worldEntity, int componentIndex = 0) SpawnedByServer = worldEntity.SpawnedByServer; ChildEntities = worldEntity.ChildEntities; ComponentIndex = componentIndex; + IsEntitySlotEntity = isEntitySlotEntity; } /// Used for deserialization - public PrefabPlaceholderEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List childEntities, int componentIndex) : + public PrefabPlaceholderEntity(NitroxTransform transform, int level, string classId, bool spawnedByServer, NitroxId id, NitroxTechType techType, EntityMetadata metadata, NitroxId parentId, List childEntities, bool isEntitySlotEntity, int componentIndex) : base(transform, level, classId, spawnedByServer, id, techType, metadata, parentId, childEntities) { ComponentIndex = componentIndex; + IsEntitySlotEntity = isEntitySlotEntity; } public override string ToString() diff --git a/NitroxServer/GameLogic/Entities/Spawning/BatchEntitySpawner.cs b/NitroxServer/GameLogic/Entities/Spawning/BatchEntitySpawner.cs index 131fcce7b0..c4204afe98 100644 --- a/NitroxServer/GameLogic/Entities/Spawning/BatchEntitySpawner.cs +++ b/NitroxServer/GameLogic/Entities/Spawning/BatchEntitySpawner.cs @@ -392,7 +392,7 @@ private bool TryCreatePrefabPlaceholdersGroupWithChildren(ref WorldEntity entity } else { - spawnedEntity = new PrefabPlaceholderEntity(spawnedEntity, i); + spawnedEntity = new PrefabPlaceholderEntity(spawnedEntity, true, i); } entity.ChildEntities.Add(spawnedEntity); } @@ -415,7 +415,7 @@ private bool TryCreatePrefabPlaceholdersGroupWithChildren(ref WorldEntity entity } else { - spawnedEntity = new PrefabPlaceholderEntity(spawnedEntity, i); + spawnedEntity = new PrefabPlaceholderEntity(spawnedEntity, false, i); } entity.ChildEntities.Add(spawnedEntity); From 50ce0ce10cddf26ef973b78a43965c8baed32719 Mon Sep 17 00:00:00 2001 From: killzoms Date: Wed, 3 Apr 2024 04:38:40 -0400 Subject: [PATCH 2/5] Fix entities in Wrecks --- .../WorldEntities/PrefabPlaceholderEntitySpawner.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs b/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs index 97d4175dfe..f7cf7c73f9 100644 --- a/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs +++ b/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs @@ -65,11 +65,11 @@ private bool VerifyCanSpawnOrError(WorldEntity entity, Optional pare private void SetupObject(WorldEntity entity, GameObject gameObject, GameObject parent) { - gameObject.transform.localPosition = entity.Transform.LocalPosition.ToUnity(); - gameObject.transform.localRotation = entity.Transform.LocalRotation.ToUnity(); - gameObject.transform.localScale = entity.Transform.LocalScale.ToUnity(); if (entity is PrefabPlaceholderEntity prefabEntity && !prefabEntity.IsEntitySlotEntity && parent) { + gameObject.transform.localPosition = entity.Transform.LocalPosition.ToUnity(); + gameObject.transform.localRotation = entity.Transform.LocalRotation.ToUnity(); + gameObject.transform.localScale = entity.Transform.LocalScale.ToUnity(); gameObject.transform.SetParent(parent.transform, false); } } From 64cf380eb54d07da4d065b34690e94b8ba7d85b9 Mon Sep 17 00:00:00 2001 From: killzoms Date: Tue, 24 Dec 2024 05:56:02 -0500 Subject: [PATCH 3/5] Fixed Placement Bug Fixed floating stones --- .../WorldEntities/PlaceholderGroupWorldEntitySpawner.cs | 5 +++++ .../Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/NitroxClient/GameLogic/Spawning/WorldEntities/PlaceholderGroupWorldEntitySpawner.cs b/NitroxClient/GameLogic/Spawning/WorldEntities/PlaceholderGroupWorldEntitySpawner.cs index b89a910190..250d33fa7d 100644 --- a/NitroxClient/GameLogic/Spawning/WorldEntities/PlaceholderGroupWorldEntitySpawner.cs +++ b/NitroxClient/GameLogic/Spawning/WorldEntities/PlaceholderGroupWorldEntitySpawner.cs @@ -121,6 +121,11 @@ public IEnumerator SpawnAsync(WorldEntity entity, Optional parent, E } } + if (prefabPlaceholderGroup.OnPrefabGroupSpawned != null) // Handles setting isKinematic on Floating Stones + { + prefabPlaceholderGroup.OnPrefabGroupSpawned(); + } + result.Set(prefabPlaceholderGroupGameObject); } diff --git a/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs b/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs index f7cf7c73f9..486bea8581 100644 --- a/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs +++ b/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs @@ -58,14 +58,14 @@ private bool VerifyCanSpawnOrError(WorldEntity entity, Optional pare return true; } - Log.Error($"[{nameof(PrefabPlaceholderEntitySpawner)}] Can't find a {nameof(PrefabPlaceholdersGroup)} on parent for {entity.Id}"); + Log.Error($"[{nameof(PrefabPlaceholderEntitySpawner)}] Can't find a {nameof(PrefabPlaceholdersGroup)} on parent: {parent}\n for: {entity}"); placeholder = null; return false; } private void SetupObject(WorldEntity entity, GameObject gameObject, GameObject parent) { - if (entity is PrefabPlaceholderEntity prefabEntity && !prefabEntity.IsEntitySlotEntity && parent) + if (parent) { gameObject.transform.localPosition = entity.Transform.LocalPosition.ToUnity(); gameObject.transform.localRotation = entity.Transform.LocalRotation.ToUnity(); From 70cfabf14a6f49d3bd533b0d0e23b387247e31c7 Mon Sep 17 00:00:00 2001 From: killzoms Date: Tue, 24 Dec 2024 08:08:51 -0500 Subject: [PATCH 4/5] handle EntitySlot entities again... --- .../WorldEntities/PrefabPlaceholderEntitySpawner.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs b/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs index 486bea8581..96c3b470c7 100644 --- a/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs +++ b/NitroxClient/GameLogic/Spawning/WorldEntities/PrefabPlaceholderEntitySpawner.cs @@ -72,5 +72,13 @@ private void SetupObject(WorldEntity entity, GameObject gameObject, GameObject p gameObject.transform.localScale = entity.Transform.LocalScale.ToUnity(); gameObject.transform.SetParent(parent.transform, false); } + + if (entity is PrefabPlaceholderEntity pEntity && pEntity.IsEntitySlotEntity && gameObject.TryGetComponent(out LargeWorldEntity lwe)) + { + lwe.cellLevel = (LargeWorldEntity.CellLevel)pEntity.Level; + bool enabled = LargeWorld.main.streamer.cellManager.RegisterEntity(lwe); + + gameObject.SetActive(enabled); + } } } From 183586759de7b7b3859b479101f412e0b86efc15 Mon Sep 17 00:00:00 2001 From: killzoms Date: Sun, 5 Jan 2025 14:42:49 -0500 Subject: [PATCH 5/5] requested change --- .../WorldEntities/PlaceholderGroupWorldEntitySpawner.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/NitroxClient/GameLogic/Spawning/WorldEntities/PlaceholderGroupWorldEntitySpawner.cs b/NitroxClient/GameLogic/Spawning/WorldEntities/PlaceholderGroupWorldEntitySpawner.cs index 250d33fa7d..6096cf5f6a 100644 --- a/NitroxClient/GameLogic/Spawning/WorldEntities/PlaceholderGroupWorldEntitySpawner.cs +++ b/NitroxClient/GameLogic/Spawning/WorldEntities/PlaceholderGroupWorldEntitySpawner.cs @@ -121,10 +121,7 @@ public IEnumerator SpawnAsync(WorldEntity entity, Optional parent, E } } - if (prefabPlaceholderGroup.OnPrefabGroupSpawned != null) // Handles setting isKinematic on Floating Stones - { - prefabPlaceholderGroup.OnPrefabGroupSpawned(); - } + prefabPlaceholderGroup.OnPrefabGroupSpawned?.Invoke(); // Handles setting isKinematic on Floating Stones result.Set(prefabPlaceholderGroupGameObject); }