internal void OnDeserializedMethod(StreamingContext context) { if (angleVert == null) { angleVert = NatFloat.createUniform(0, 0); } }
public void Init(ICoreServerAPI api, RockStrataConfig rockstrata, LCGRandom rnd, int i) { List <Block> blocks = new List <Block>(); for (int j = 0; j < blockCodes.Length; j++) { AssetLocation code = blockCodes[j]; if (code.Path.Contains("{rocktype}")) { if (BlocksByRockType == null) { BlocksByRockType = new Dictionary <int, Block[]>(); } for (int k = 0; k < rockstrata.Variants.Length; k++) { string rocktype = rockstrata.Variants[k].BlockCode.Path.Split('-')[1]; AssetLocation rocktypedCode = code.CopyWithPath(code.Path.Replace("{rocktype}", rocktype)); Block rockBlock = api.World.GetBlock(rockstrata.Variants[k].BlockCode); if (rockBlock != null) { BlocksByRockType[rockBlock.BlockId] = new Block[] { api.World.GetBlock(rocktypedCode) }; } } } else { Block block = api.World.GetBlock(code); if (block != null) { blocks.Add(block); } else { api.World.Logger.Warning("Block patch Nr. {0}: Unable to resolve block with code {1}. Will ignore.", i, code); } } } Blocks = blocks.ToArray(); if (BlockCodeIndex == null) { BlockCodeIndex = NatFloat.createUniform(0, Blocks.Length); } if (RandomMapCodePool != null) { int index = rnd.NextInt(RandomMapCodePool.Length); MapCode = RandomMapCodePool[index]; } }
public void Init(ICoreServerAPI api) { ResolveBlockCodes(api); if (Placement == EnumDepositPlacement.Anywhere) { Depth.avg *= api.WorldManager.MapSizeY; Depth.var *= api.WorldManager.MapSizeY; } if (Placement == EnumDepositPlacement.FollowSeaLevel) { Depth.avg *= TerraGenConfig.seaLevel; Depth.var *= TerraGenConfig.seaLevel; } if (CheckClimate && Radius.avg + Radius.var >= 32) { api.Server.LogWarning("Deposit has CheckClimate=true and radius > 32 blocks - this is not supported, sorry. Defaulting to uniform radius 10"); Radius = NatFloat.createUniform(10, 0); } if (BlockIds.Length == 0) { string code = BlockCode.Path.Replace("{", "{{").Replace("}", "}}"); throw new Exception("Invalid deposits.json: Can't have a deposit without blockcode (maybe invalid name? " + code + ")!"); } if (ChildDeposits != null) { for (int i = 0; i < ChildDeposits.Length; i++) { if (ChildDeposits[i].ParentBlockCodes == null) { ChildDeposits[i].ParentBlockCodes = new AssetLocation[BlockIds.Length]; for (int j = 0; j < BlockIds.Length; j++) { ChildDeposits[i].ParentBlockCodes[j] = api.World.Blocks[BlockIds[j]].Code; } ChildDeposits[i].GrandParentBlockLocs = new AssetLocation[ParentBlockCodes.Length]; for (int j = 0; j < ParentBlockCodes.Length; j++) { ChildDeposits[i].GrandParentBlockLocs[j] = ParentBlockCodes[j]; } } ChildDeposits[i].Init(api); } } else { ChildDeposits = new DepositVariant[0]; } }
internal void ResolveBlockIds(ICoreServerAPI api, RockStrataConfig rockstrata) { for (int i = 0; i < Patches.Length; i++) { BlockPatch patch = Patches[i]; List <Block> blocks = new List <Block>(); for (int j = 0; j < patch.blockCodes.Length; j++) { AssetLocation code = patch.blockCodes[j]; if (code.Path.Contains("{rocktype}")) { if (patch.BlocksByRockType == null) { patch.BlocksByRockType = new Dictionary <int, Block[]>(); } for (int k = 0; k < rockstrata.Variants.Length; k++) { string rocktype = rockstrata.Variants[k].BlockCode.Path.Split('-')[1]; AssetLocation rocktypedCode = code.CopyWithPath(code.Path.Replace("{rocktype}", rocktype)); Block rockBlock = api.World.GetBlock(rockstrata.Variants[k].BlockCode); if (rockBlock != null) { patch.BlocksByRockType[rockBlock.BlockId] = new Block[] { api.World.GetBlock(rocktypedCode) }; } } } else { Block block = api.World.GetBlock(code); if (block != null) { blocks.Add(block); } else { api.World.Logger.Warning("Block patch Nr. {0}: Unable to resolve block with code {1}. Will ignore.", i, code); } } } patch.Blocks = blocks.ToArray(); if (patch.BlockCodeIndex == null) { patch.BlockCodeIndex = NatFloat.createUniform(0, patch.Blocks.Length); } } }
public override void Init() { if (Radius == null) { Api.Server.LogWarning("Alluvial Deposit {0} has no radius property defined. Defaulting to uniform radius 10", variant.fromFile); Radius = NatFloat.createUniform(10, 0); } if (variant.Climate != null && Radius.avg + Radius.var >= 32) { Api.Server.LogWarning("Alluvial Deposit {0} has CheckClimate=true and radius > 32 blocks - this is not supported, sorry. Defaulting to uniform radius 10", variant.fromFile); Radius = NatFloat.createUniform(10, 0); } }
internal void ResolveBlockIds(ICoreServerAPI api, RockstrataWorldProperty rockstrata) { for (int i = 0; i < Patches.Length; i++) { BlockPatch patch = Patches[i]; List <Block> blocks = new List <Block>(); for (int j = 0; j < patch.blockCodes.Length; j++) { AssetLocation code = patch.blockCodes[j]; if (code.Path.Contains("{rocktype}")) { if (patch.BlocksByRockType == null) { patch.BlocksByRockType = new Dictionary <ushort, Block[]>(); } for (int k = 0; k < rockstrata.Variants.Length; k++) { string rocktype = rockstrata.Variants[k].BlockCode.Path.Split('-')[1]; patch.BlocksByRockType.Add( api.WorldManager.GetBlockId(rockstrata.Variants[k].BlockCode), new Block[] { api.World.GetBlock(code.CopyWithPath(code.Path.Replace("{rocktype}", rocktype))) } ); } } else { blocks.Add(api.WorldManager.GetBlockType(api.WorldManager.GetBlockId(code))); } } patch.Blocks = blocks.ToArray(); if (patch.BlockCodeIndex == null) { patch.BlockCodeIndex = NatFloat.createUniform(0, patch.Blocks.Length); } } }
public override void Init() { if (Radius == null) { Api.Server.LogWarning("Deposit {0} has no radius property defined. Defaulting to uniform radius 10", variant.fromFile); Radius = NatFloat.createUniform(10, 0); } if (variant.Climate != null && Radius.avg + Radius.var >= 32) { Api.Server.LogWarning("Deposit {0} has CheckClimate=true and radius > 32 blocks - this is not supported, sorry. Defaulting to uniform radius 10", variant.fromFile); Radius = NatFloat.createUniform(10, 0); } if (InBlock != null) { Block[] blocks = Api.World.SearchBlocks(InBlock.Code); if (blocks.Length == 0) { Api.Server.LogWarning("Deposit in file {0}, no such blocks found by code/wildcard '{1}'. Deposit will never spawn.", variant.fromFile, InBlock.Code); } foreach (var block in blocks) { if (InBlock.AllowedVariants != null && !WildcardUtil.Match(InBlock.Code, block.Code, InBlock.AllowedVariants)) { continue; } if (InBlock.AllowedVariantsByInBlock != null && !InBlock.AllowedVariantsByInBlock.ContainsKey(block.Code)) { continue; } string key = InBlock.Name; string value = WildcardUtil.GetWildcardValue(InBlock.Code, block.Code); placeBlockByInBlockId[block.BlockId] = PlaceBlock.Resolve(variant.fromFile, Api, block, key, value); if (SurfaceBlock != null) { surfaceBlockByInBlockId[block.BlockId] = SurfaceBlock.Resolve(variant.fromFile, Api, block, key, value); } if (variant.ChildDeposits != null) { foreach (var val in variant.ChildDeposits) { if (val.GeneratorInst == null) { val.InitWithoutGenerator(Api); val.GeneratorInst = new ChildDepositGenerator(Api, val, DepositRand, DistortNoiseGen); JsonUtil.Populate(val.Attributes.Token, val.GeneratorInst); } foreach (Block depositblock in placeBlockByInBlockId[block.BlockId].Blocks) { (val.GeneratorInst as ChildDepositGenerator).ResolveAdd(depositblock, key, value); } } } // Host rock for if (block.Attributes == null) { block.Attributes = new JsonObject(JToken.Parse("{}")); } int[] oreIds = block.Attributes["hostRockFor"].AsArray <int>(new int[0]); oreIds = oreIds.Append(placeBlockByInBlockId[block.BlockId].Blocks.Select(b => b.BlockId).ToArray()); block.Attributes.Token["hostRockFor"] = JToken.FromObject(oreIds); // In host rock Block[] placeBlocks = placeBlockByInBlockId[block.BlockId].Blocks; for (int i = 0; i < placeBlocks.Length; i++) { Block pblock = placeBlocks[i]; if (pblock.Attributes == null) { pblock.Attributes = new JsonObject(JToken.Parse("{}")); } oreIds = pblock.Attributes["hostRock"].AsArray <int>(new int[0]); oreIds = oreIds.Append(block.BlockId); pblock.Attributes.Token["hostRock"] = JToken.FromObject(oreIds); } } } else { Api.Server.LogWarning("Deposit in file {0} has no inblock defined, it will never spawn.", variant.fromFile); } }