|
3 | 3 | using NitroxClient.Communication;
|
4 | 4 | using NitroxClient.GameLogic.Helper;
|
5 | 5 | using NitroxClient.GameLogic.Spawning.Abstract;
|
| 6 | +using NitroxClient.GameLogic.Spawning.Metadata; |
6 | 7 | using NitroxClient.GameLogic.Spawning.WorldEntities;
|
7 | 8 | using NitroxClient.MonoBehaviours;
|
8 | 9 | using NitroxClient.Unity.Helper;
|
|
16 | 17 |
|
17 | 18 | namespace NitroxClient.GameLogic.Spawning;
|
18 | 19 |
|
19 |
| -public class InventoryItemEntitySpawner : SyncEntitySpawner<InventoryItemEntity> |
| 20 | +public class InventoryItemEntitySpawner(EntityMetadataManager entityMetadataManager) : SyncEntitySpawner<InventoryItemEntity> |
20 | 21 | {
|
| 22 | + private readonly EntityMetadataManager entityMetadataManager = entityMetadataManager; |
| 23 | + |
21 | 24 | protected override IEnumerator SpawnAsync(InventoryItemEntity entity, TaskResult<Optional<GameObject>> result)
|
22 | 25 | {
|
23 | 26 | if (!CanSpawn(entity, out GameObject parentObject, out ItemsContainer container, out string errorLog))
|
@@ -116,17 +119,28 @@ private void SetupObject(InventoryItemEntity entity, GameObject gameObject, Game
|
116 | 119 | {
|
117 | 120 | planter.Subscribe(subscribedValue);
|
118 | 121 |
|
119 |
| - PostponeAddNotification(() => planter.subscribed, () => planter, true, () => |
| 122 | + if (entity.Metadata is PlantableMetadata metadata) |
120 | 123 | {
|
121 |
| - if (entity.Metadata is PlantableMetadata metadata) |
| 124 | + PostponeAddNotification(() => planter.subscribed, () => planter, true, () => |
122 | 125 | {
|
123 | 126 | // Adapted from Planter.AddItem(InventoryItem) to be able to call directly AddItem(Plantable, slotID) with our parameters
|
124 |
| - Plantable component = pickupable.GetComponent<Plantable>(); |
125 |
| - pickupable.SetTechTypeOverride(component.plantTechType, false); |
| 127 | + Plantable plantable = pickupable.GetComponent<Plantable>(); |
| 128 | + pickupable.SetTechTypeOverride(plantable.plantTechType, false); |
126 | 129 | inventoryItem.isEnabled = false;
|
127 |
| - planter.AddItem(component, metadata.SlotID); |
128 |
| - } |
129 |
| - }); |
| 130 | + planter.AddItem(plantable, metadata.SlotID); |
| 131 | + |
| 132 | + // Reapply the plantable metadata after the GrowingPlant (or the GrownPlant) is spawned |
| 133 | + entityMetadataManager.ApplyMetadata(plantable.gameObject, metadata); |
| 134 | + |
| 135 | + // Plant spawning occurs in multiple steps over frames: |
| 136 | + // spawning the item, adding it to the planter, having the GrowingPlant created, and eventually having it create a GrownPlant (when progress == 1) |
| 137 | + // therefore we give the metadata to the object so it can be used when required |
| 138 | + if (metadata.FruitPlantMetadata != null && plantable.growingPlant && plantable.growingPlant.GetProgress() == 1f) |
| 139 | + { |
| 140 | + MetadataHolder.AddMetadata(plantable.growingPlant.gameObject, metadata.FruitPlantMetadata); |
| 141 | + } |
| 142 | + }); |
| 143 | + } |
130 | 144 | }
|
131 | 145 | else if (parentObject.TryGetComponent(out Trashcan trashcan))
|
132 | 146 | {
|
|
0 commit comments