internal void Init(ICoreServerAPI api) { IAsset asset = api.Assets.Get("worldgen/rockstrata.json"); RockStrataConfig rockstrata = asset.ToObject <RockStrataConfig>(); asset = api.Assets.Get("worldgen/blocklayers.json"); blockLayerConfig = asset.ToObject <BlockLayerConfig>(); blockLayerConfig.ResolveBlockIds(api, rockstrata); for (int i = 0; i < Structures.Length; i++) { LCGRandom rand = new LCGRandom(api.World.Seed + i + 512); Structures[i].Init(api, blockLayerConfig, rand); } }
public void InitWorldGen() { LoadGlobalConfig(api); IAsset asset = api.Assets.Get("worldgen/rockstrata.json"); RockStrataConfig rockstrata = asset.ToObject <RockStrataConfig>(); asset = api.Assets.Get("worldgen/blocklayers.json"); blockLayerConfig = asset.ToObject <BlockLayerConfig>(); blockLayerConfig.ResolveBlockIds(api, rockstrata); rnd = new LCGRandom(api.WorldManager.Seed); grassDensity = new ClampedSimplexNoise(new double[] { 4 }, new double[] { 0.5 }, rnd.NextInt()); grassHeight = new ClampedSimplexNoise(new double[] { 1.5 }, new double[] { 0.5 }, rnd.NextInt()); mapheight = api.WorldManager.MapSizeY; }
private void initWorldGen() { LoadGlobalConfig(api); IAsset asset = api.Assets.Get("worldgen/blocklayers.json"); blockLayerConfig = asset.ToObject<BlockLayerConfig>(); blockLayerConfig.SnowLayer.BlockId = api.WorldManager.GetBlockId(blockLayerConfig.SnowLayer.BlockCode); rnd = new Random(api.WorldManager.Seed); chunksize = api.WorldManager.ChunkSize; worldheight = api.WorldManager.MapSizeY; transSize = blockLayerConfig.SnowLayer.TransitionSize; maxTemp = blockLayerConfig.SnowLayer.MaxTemp; minTemp = maxTemp - transSize; }
/// <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"); RockStrataConfig rockstrata = asset.ToObject <RockStrataConfig>(); asset = api.Assets.Get("worldgen/blocklayers.json"); BlockLayerConfig blockLayerConfig = asset.ToObject <BlockLayerConfig>(); blockLayerConfig.ResolveBlockIds(api, rockstrata); api.ObjectCache[cacheKey] = blockLayerConfig; return(blockLayerConfig); } }
public void initWorldGen() { LoadGlobalConfig(api); rand = new LCGRandom(api.WorldManager.Seed - 12); searchSize = 3 * chunksize; mapOffset = chunksize; minBoundary = -chunksize + 1; maxBoundary = 2 * chunksize - 1; mapheight = api.WorldManager.MapSizeY; didCheckPosition = new bool[searchSize * searchSize]; IAsset asset = api.Assets.Get("worldgen/rockstrata.json"); RockStrataConfig rockstrata = asset.ToObject <RockStrataConfig>(); asset = api.Assets.Get("worldgen/blocklayers.json"); BlockLayerConfig blockLayerConfig = asset.ToObject <BlockLayerConfig>(); blockLayerConfig.ResolveBlockIds(api, rockstrata); lakebedLayerConfig = blockLayerConfig.LakeBedLayer; }
public void Init(ICoreServerAPI api, BlockLayerConfig config, RockStrataConfig rockstrata, LCGRandom rand) { this.rand = 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; } schematic.FromFileName = asset.Name; 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].LoadMetaInformationAndValidate(api.World.BlockAccessor, api.World, schematic.FromFileName); } schematics.Add(rotations); } } this.schematicDatas = schematics.ToArray(); if (ReplaceWithBlocklayers != null) { replaceblockids = new int[ReplaceWithBlocklayers.Length]; for (int i = 0; i < replaceblockids.Length; i++) { Block block = api.World.GetBlock(ReplaceWithBlocklayers[i]); if (block == null) { throw new Exception(string.Format("Schematic with code {0} has replace block layer {1} defined, but no such block found!", Code, ReplaceWithBlocklayers[i])); } else { replaceblockids[i] = block.Id; } } } if (InsideBlockCodes != null) { for (int i = 0; i < InsideBlockCodes.Length; i++) { Block block = api.World.GetBlock(InsideBlockCodes[i]); if (block == null) { throw new Exception(string.Format("Schematic with code {0} has inside block {1} defined, but no such block found!", Code, InsideBlockCodes[i])); } else { insideblockids.Add(block.Id); } } } if (ReplaceWithRockType != null) { resolvedReplaceWithRocktype = new Dictionary <int, Dictionary <int, int> >(); foreach (var val in ReplaceWithRockType) { int sourceBlockId = api.World.GetBlock(val.Key).Id; Dictionary <int, int> blockIdByRockId = new Dictionary <int, int>(); foreach (var strat in rockstrata.Variants) { Block rockBlock = api.World.GetBlock(strat.BlockCode); AssetLocation resolvedLoc = val.Value.Clone(); resolvedLoc.Path = resolvedLoc.Path.Replace("{rock}", rockBlock.LastCodePart()); Block resolvedBlock = api.World.GetBlock(resolvedLoc); if (resolvedBlock != null) { blockIdByRockId[rockBlock.Id] = resolvedBlock.Id; Block quartzBlock = api.World.GetBlock(new AssetLocation("ore-quartz-" + rockBlock.LastCodePart())); if (quartzBlock != null) { blockIdByRockId[quartzBlock.Id] = resolvedBlock.Id; } } } resolvedReplaceWithRocktype[sourceBlockId] = blockIdByRockId; } } }
public void Init(ICoreServerAPI api, BlockLayerConfig config, LCGRandom rand) { this.rand = 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; } schematic.FromFileName = asset.Name; 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].LoadMetaInformationAndValidate(api.World.BlockAccessor, api.World, schematic.FromFileName); } schematics.Add(rotations); } } this.schematicDatas = schematics.ToArray(); if (ReplaceWithBlocklayers != null) { replaceblockids = new ushort[ReplaceWithBlocklayers.Length]; for (int i = 0; i < replaceblockids.Length; i++) { Block block = api.World.GetBlock(ReplaceWithBlocklayers[i]); if (block == null) { throw new Exception(string.Format("Schematic with code {0} has replace block layer {1} defined, but no such block found!", Code, ReplaceWithBlocklayers[i])); } else { replaceblockids[i] = (ushort)block.Id; } } } }