public override void AfterPostprocess(MyDefinitionSet set, Dictionary <MyStringHash, MyDefinitionBase> definitions) { List <int> indices = new List <int>(); foreach (MyDefinitionBase base2 in definitions.Values) { MyPlanetGeneratorDefinition definition = (MyPlanetGeneratorDefinition)base2; if (definition.EnvironmentId != null) { definition.EnvironmentDefinition = MyDefinitionManager.Static.GetDefinition <MyWorldEnvironmentDefinition>(definition.EnvironmentId.Value); } else { definition.EnvironmentDefinition = MyProceduralEnvironmentDefinition.FromLegacyPlanet(definition.m_pgob, base2.Context); set.AddOrRelaceDefinition(definition.EnvironmentDefinition); definition.m_pgob = null; } if (definition.EnvironmentDefinition != null) { definition.EnvironmentSectorType = definition.EnvironmentDefinition.SectorType; using (Dictionary <int, Dictionary <string, List <MyPlanetEnvironmentMapping> > > .ValueCollection.Enumerator enumerator2 = definition.MaterialEnvironmentMappings.Values.GetEnumerator()) { while (enumerator2.MoveNext()) { using (Dictionary <string, List <MyPlanetEnvironmentMapping> > .ValueCollection.Enumerator enumerator3 = enumerator2.Current.Values.GetEnumerator()) { while (enumerator3.MoveNext()) { foreach (MyPlanetEnvironmentMapping mapping in enumerator3.Current) { int index = 0; while (true) { MyEnvironmentItemsDefinition definition2; if (index >= mapping.Items.Length) { if (indices.Count > 0) { mapping.Items = mapping.Items.RemoveIndices <MyMaterialEnvironmentItem>(indices); mapping.ComputeDistribution(); indices.Clear(); } break; } if (mapping.Items[index].IsEnvironemntItem && !MyDefinitionManager.Static.TryGetDefinition <MyEnvironmentItemsDefinition>(mapping.Items[index].Definition, out definition2)) { MyLog.Default.WriteLine($"Could not find environment item definition for {mapping.Items[index].Definition}."); indices.Add(index); } index++; } } } } } } } } }
// Called after all definitions are merged to one set // Anything that may refere to other definitions from game or that may be modified by mods should be postprocessed here. public override void AfterPostprocess(MyDefinitionSet set, Dictionary <MyStringHash, MyDefinitionBase> definitions) { List <int> toRemove = new List <int>(); foreach (var def in definitions.Values) { var pgdef = (MyPlanetGeneratorDefinition)def; // Legacy planet with automatically converted definition if (!pgdef.EnvironmentId.HasValue) { pgdef.EnvironmentDefinition = MyProceduralEnvironmentDefinition.FromLegacyPlanet(pgdef.m_pgob, def.Context); set.AddOrRelaceDefinition(pgdef.EnvironmentDefinition); pgdef.m_pgob = null; } else { pgdef.EnvironmentDefinition = MyDefinitionManager.Static.GetDefinition <MyWorldEnvironmentDefinition>(pgdef.EnvironmentId.Value); } if (pgdef.EnvironmentDefinition == null) { continue; } pgdef.EnvironmentSectorType = pgdef.EnvironmentDefinition.SectorType; Debug.Assert(typeof(MyEnvironmentSector).IsAssignableFrom(pgdef.EnvironmentSectorType)); foreach (var bmap in pgdef.MaterialEnvironmentMappings.Values) { foreach (var mmap in bmap.Values) { foreach (var env in mmap) { for (int i = 0; i < env.Items.Length; ++i) { if (env.Items[i].IsEnvironemntItem) { MyEnvironmentItemsDefinition eidef; if (!MyDefinitionManager.Static.TryGetDefinition(env.Items[i].Definition, out eidef)) { MyLog.Default.WriteLine(string.Format("Could not find environment item definition for {0}.", env.Items[i].Definition)); toRemove.Add(i); } } } if (toRemove.Count > 0) { env.Items = env.Items.RemoveIndices(toRemove); env.ComputeDistribution(); toRemove.Clear(); } } } } } }