public Template(object id, string name, Entity entity, string fileName, string typeName, string typeCode, bool templateByDefault, EnumTreeType treeType, byte[] content, IEnumerable <TemplateField> fields, IDictionary <string, string> parameters = null) : this(name, entity, typeCode, content, fields) { if (id == null) { throw new ArgumentNullException("id", Message.Get("Common.NullIdentifier")); } ID = id; //UserID = userID; FileName = fileName; TypeName = typeName; this.TemplateByDefault = templateByDefault; this.TreeTypeEnum = treeType; this.parameters = parameters; }
private void GenPatches(IBlockAccessor blockAccessor, BlockPos pos, float forestNess, EnumTreeType treetype, LCGRandom rnd) { var bpc = genPatchesSystem.bpc; int radius = 5; int worldheight = blockAccessor.MapSizeY; int cnt = underTreePatches?.Count ?? 0; for (int i = 0; i < cnt; i++) { BlockPatch bPatch = underTreePatches[i]; if (bPatch.TreeType != EnumTreeType.Any && bPatch.TreeType != treetype) { continue; } float chance = 0.003f * forestNess * bPatch.Chance * bpc.ChanceMultiplier.nextFloat(); //if (bPatch.blockCodes[0].Path.Contains("mushroom")) chance *= 20; - for debugging while (chance-- > rnd.NextDouble()) { int dx = rnd.NextInt(2 * radius) - radius; int dz = rnd.NextInt(2 * radius) - radius; tmpPos.Set(pos.X + dx, 0, pos.Z + dz); int y = blockAccessor.GetTerrainMapheightAt(tmpPos); if (y <= 0 || y >= worldheight - 8) { continue; } tmpPos.Y = y; var climate = blockAccessor.GetClimateAt(tmpPos, EnumGetClimateMode.WorldGenValues); if (climate == null) { continue; } if (bpc.IsPatchSuitableUnderTree(bPatch, worldheight, climate, y)) { int regionX = pos.X / blockAccessor.RegionSize; int regionZ = pos.Z / blockAccessor.RegionSize; if (bPatch.MapCode != null && rnd.NextInt(255) > genPatchesSystem.GetPatchDensity(bPatch.MapCode, tmpPos.X, tmpPos.Z, blockAccessor.GetMapRegion(regionX, regionZ))) { continue; } int firstBlockId = 0; bool found = true; if (bPatch.BlocksByRockType != null) { found = false; int dy = 1; while (dy < 5 && y - dy > 0) { string lastCodePart = blockAccessor.GetBlock(tmpPos.X, y - dy, tmpPos.Z).LastCodePart(); if (genPatchesSystem.RockBlockIdsByType.TryGetValue(lastCodePart, out firstBlockId)) { found = true; break; } dy++; } } if (found) { bPatch.Generate(blockAccessor, rnd, tmpPos.X, tmpPos.Y, tmpPos.Z, firstBlockId); } } } } cnt = onTreePatches?.Count ?? 0; for (int i = 0; i < cnt; i++) { BlockPatch blockPatch = onTreePatches[i]; float chance = 3 * forestNess * blockPatch.Chance * bpc.ChanceMultiplier.nextFloat(); while (chance-- > rnd.NextDouble()) { int dx = 1 - rnd.NextInt(2) * 2; int dy = rnd.NextInt(5); int dz = 1 - rnd.NextInt(2) * 2; tmpPos.Set(pos.X + dx, pos.Y + dy, pos.Z + dz); var block = api.GetBlock(tmpPos); if (block.Id != 0) { continue; } BlockFacing facing = null; for (int j = 0; j < 4; j++) { var f = BlockFacing.HORIZONTALS[j]; var nblock = api.GetBlock(tmpPos.X + f.Normali.X, tmpPos.Y, tmpPos.Z + f.Normali.Z); if (nblock is BlockLog && nblock.Variant["type"] != "resin") { facing = f; break; } } if (facing == null) { break; } var climate = blockAccessor.GetClimateAt(tmpPos, EnumGetClimateMode.WorldGenValues); if (climate == null) { continue; } if (bpc.IsPatchSuitableUnderTree(blockPatch, worldheight, climate, tmpPos.Y)) { int regionX = pos.X / blockAccessor.RegionSize; int regionZ = pos.Z / blockAccessor.RegionSize; if (blockPatch.MapCode != null && rnd.NextInt(255) > genPatchesSystem.GetPatchDensity(blockPatch.MapCode, tmpPos.X, tmpPos.Z, blockAccessor.GetMapRegion(regionX, regionZ))) { continue; } int index = rnd.NextInt(blockPatch.Blocks.Length); blockPatch.Blocks[index].TryPlaceBlockForWorldGen(blockAccessor, tmpPos, facing, rnd); } } } }