internal void Init(ICoreServerAPI api) { IAsset asset = api.Assets.Get("worldgen/rockstrata.json"); RockstrataWorldProperty rockstrata = asset.ToObject <RockstrataWorldProperty>(); asset = api.Assets.Get("worldgen/blocklayerconfig.json"); blockLayerConfig = asset.ToObject <BlockLayerConfig>(); blockLayerConfig.ResolveBlockIds(api, rockstrata); for (int i = 0; i < Structures.Length; i++) { Structures[i].Init(api, blockLayerConfig); } }
/// <summary> /// Loads and caches the BlockLayerConfig if it's not already loaded. Otherwise /// returns the cached value /// </summary> /// <param name="api"></param> /// <returns></returns> public static BlockLayerConfig GetInstance(ICoreServerAPI api) { if (api.ObjectCache.ContainsKey(cacheKey)) { return(api.ObjectCache[cacheKey] as BlockLayerConfig); } else { IAsset asset = api.Assets.Get("worldgen/rockstrata.json"); RockstrataWorldProperty rockstrata = asset.ToObject <RockstrataWorldProperty>(); asset = api.Assets.Get("worldgen/blocklayerconfig.json"); BlockLayerConfig blockLayerConfig = asset.ToObject <BlockLayerConfig>(); blockLayerConfig.ResolveBlockIds(api, rockstrata); api.ObjectCache[cacheKey] = blockLayerConfig; return(blockLayerConfig); } }
public void Init(ICoreServerAPI api, BlockLayerConfig config) { rand = api.World.Rand; List <BlockSchematicStructure[]> schematics = new List <BlockSchematicStructure[]>(); for (int i = 0; i < Schematics.Length; i++) { string error = ""; IAsset[] assets; if (Schematics[i].EndsWith("*")) { assets = api.Assets.GetMany("worldgen/schematics/" + Schematics[i].Substring(0, Schematics[i].Length - 1)).ToArray(); } else { assets = new IAsset[] { api.Assets.Get("worldgen/schematics/" + Schematics[i] + ".json") }; } for (int j = 0; j < assets.Length; j++) { IAsset asset = assets[j]; BlockSchematicStructure schematic = asset.ToObject <BlockSchematicStructure>(); if (schematic == null) { api.World.Logger.Warning("Could not load {0}: {1}", Schematics[i], error); continue; } BlockSchematicStructure[] rotations = new BlockSchematicStructure[4]; rotations[0] = schematic; for (int k = 0; k < 4; k++) { if (k > 0) { rotations[k] = rotations[0].Clone(); rotations[k].TransformWhilePacked(api.World, EnumOrigin.BottomCenter, k * 90); } rotations[k].blockLayerConfig = config; rotations[k].Init(api.World.BlockAccessor); rotations[k].LoadMetaInformation(api.World.BlockAccessor); } schematics.Add(rotations); } } this.schematicDatas = schematics.ToArray(); if (ReplaceWithBlocklayers != null) { replaceblockids = new ushort[ReplaceWithBlocklayers.Length]; for (int i = 0; i < replaceblockids.Length; i++) { replaceblockids[i] = (ushort)api.World.GetBlock(ReplaceWithBlocklayers[i]).Id; } } }