public override void Decorate(ChunkColumn chunk, BiomeBase biome) { for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { //Check for temperature. for (var y = 0; y < StandardWorldProvider.WaterLevel; y++) { //Lake generation if (y < StandardWorldProvider.WaterLevel) { if (chunk.GetBlock(x, y, z) == 2 || chunk.GetBlock(x, y, z) == 3) //Grass or Dirt? { if (StandardWorldProvider.GetRandomNumber(1, 40) == 1 && y < StandardWorldProvider.WaterLevel - 4) chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(82)); //Clay else { chunk.SetBlock(x, y, z, new BlockSand()); //Sand chunk.BiomeId[x*16 + z] = 16; //Beach } } if (chunk.GetBlock(x, y + 1, z) == 0) { if (y < StandardWorldProvider.WaterLevel - 3) { chunk.SetBlock(x, y + 1, z, new BlockFlowingWater()); //Water chunk.BiomeId[x*16 + z] = 0; //Ocean } } } } } } }
public override void Create(ChunkColumn chunk, int x, int y, int z) { var block = chunk.GetBlock(x, y - 1, z); if (block != 2 && block != 3) { return; } var location = new Vector3(x, y, z); if (!ValidLocation(location, _leafRadius)) { return; } var height = Rnd.Next(7, 8); GenerateColumn(chunk, location, height, 17, 1); for (var Y = 1; Y < height; Y++) { if (Y % 2 == 0) { GenerateVanillaCircle(chunk, location + new Vector3(0, Y + 1, 0), _leafRadius - 1, 18, 1); continue; } GenerateVanillaCircle(chunk, location + new Vector3(0, Y + 1, 0), _leafRadius, 18, 1); } GenerateTopper(chunk, location + new Vector3(0, height, 0), 0x1); }
protected void GenerateVanillaCircle(ChunkColumn chunk, Vector3 location, int radius, Block block, double corner = 0) { for (var I = -radius; I <= radius; I = (I + 1)) { for (var J = -radius; J <= radius; J = (J + 1)) { var Max = (int)Math.Sqrt((I * I) + (J * J)); if (Max <= radius) { if (I.Equals(-radius) && J.Equals(-radius) || I.Equals(-radius) && J.Equals(radius) || I.Equals(radius) && J.Equals(-radius) || I.Equals(radius) && J.Equals(radius)) { if (corner + radius * 0.2 < 0.4 || corner + radius * 0.2 > 0.7 || corner.Equals(0)) { continue; } } var X = location.X + I; var Z = location.Z + J; if (chunk.GetBlock((int)X, (int)location.Y, (int)Z).Equals(0)) { chunk.SetBlock((int)X, (int)location.Y, (int)Z, block); } } } } }
private void DecorateTrees(ChunkColumn chunk, BiomeBase biome) { var trees = StandardWorldProvider.GetRandomNumber(biome.MinTrees, biome.MaxTrees); var treeBasePositions = new int[trees, 2]; for (var t = 0; t < trees; t++) { var x = new Random().Next(1, 16); var z = new Random().Next(1, 16); treeBasePositions[t, 0] = x; treeBasePositions[t, 1] = z; } for (var y = StandardWorldProvider.WaterLevel + 2; y < 256; y++) { for (var pos = 0; pos < trees; pos++) { if (treeBasePositions[pos, 0] < 14 && treeBasePositions[pos, 0] > 4 && treeBasePositions[pos, 1] < 14 && treeBasePositions[pos, 1] > 4) { if (chunk.GetBlock(treeBasePositions[pos, 0], y + 1, treeBasePositions[pos, 1]) == biome.TopBlock.Id) { GenerateTree(chunk, treeBasePositions[pos, 0], y + 1, treeBasePositions[pos, 1], biome); } } } } }
public override void Decorate(ChunkColumn chunk, BiomeBase biome) { for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { //var blockbiome = chunk.BiomeId[x*16 + z]; //if (BiomeManager.GetBiomeById(blockbiome).Temperature < 2.0f) //If the temperature is below 2.0F create lakes. //{ //Check for temperature. for (var y = 0; y < NetherWorldProvider.WaterLevel; y++) { //Lake generation if (y < NetherWorldProvider.WaterLevel) { if (chunk.GetBlock(x, y + 1, z) == 0) { if (y < NetherWorldProvider.WaterLevel - 3) { chunk.SetBlock(x, y + 1, z, new BlockStationaryLava()); //Water } } } } } } }
protected void GenerateCircle(ChunkColumn chunk, Vector3 location, int radius, Block block) { for (var I = -radius; I <= radius; I = (I + 1)) { for (var j = -radius; j <= radius; j = (j + 1)) { var max = (int)Math.Sqrt((I * I) + (j * j)); if (max <= radius) { var X = location.X + I; var Z = location.Z + j; if (X < 0 || X >= 16 || Z < 0 || Z >= 256) { continue; } var x = (int)X; var y = (int)location.Y; var z = (int)Z; if (chunk.GetBlock(x, y, z).Equals(0)) { chunk.SetBlock(x, y, z, block); } } } } }
protected void GenerateVanillaCircle(ChunkColumn chunk, Vector3 location, int radius, Block block, double corner = 0) { for (var I = -radius; I <= radius; I = (I + 1)) { for (var j = -radius; j <= radius; j = (j + 1)) { var max = (int)Math.Sqrt((I * I) + (j * j)); if (max <= radius) { if (I.Equals(-radius) && j.Equals(-radius) || I.Equals(-radius) && j.Equals(radius) || I.Equals(radius) && j.Equals(-radius) || I.Equals(radius) && j.Equals(radius)) { if (corner + radius * 0.2 < 0.4 || corner + radius * 0.2 > 0.7 || corner.Equals(0)) { continue; } } var x = location.X + I; var z = location.Z + j; if (chunk.GetBlock((int)x, (int)location.Y, (int)z).Equals(0)) { chunk.SetBlock((int)x, (int)location.Y, (int)z, block); } } } } }
public Block GetConvertedBlock(BlockCoordinates blockCoordinates) { ChunkColumn chunk = GetChunk(blockCoordinates); if (chunk == null) { return new Air() { Coordinates = blockCoordinates, SkyLight = 15 } } ; byte bid = chunk.GetBlock(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); byte metadata = chunk.GetMetadata(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); byte blockLight = chunk.GetBlocklight(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); byte skyLight = chunk.GetSkylight(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); Block block = PCPEConvert.ConvertBlock(bid, metadata); block.Coordinates = blockCoordinates; block.BlockLight = blockLight; block.SkyLight = skyLight; return(block); }
protected void GenerateLeaves(ChunkColumn world, int x, int y, int z, float size, float width, byte leafBlockId, byte leafMeta, byte woodId, byte woodMeta) { float dist; int i, j, k, s = (int)(size - 1f), w = (int)((size - 1f) * width); for (i = -w; i <= w; i++) { for (j = -s; j <= s; j++) { for (k = -w; k <= w; k++) { dist = Math.Abs((float)i / width) + (float)Math.Abs(j) + Math.Abs((float)k / width); if (dist <= size - 0.5f || (dist <= size && Rnd.NextDouble() < 0.5)) { if (dist < 0.6f) { world.SetBlock(x + i, y + j, z + k, woodId); world.SetMetadata(x + i, y + j, z + k, woodMeta); } if (world.GetBlock(x + i, y + j, z + k) == 0) { world.SetBlock(x + i, y + j, z + k, leafBlockId); world.SetMetadata(x + i, y + j, z + k, leafMeta); } } } } } }
public override void Create(ChunkColumn chunk, int x, int y, int z) { var block = chunk.GetBlock(x, y - 1, z); if (block != 2 && block != 3) { return; } BaseSize = 3 + Rnd.Next(2); if (Roots > 0f) { for (int k = 0; k < 3; k++) { GenerateBranch(chunk, x, y + Roots, z, (120 * k) - 40 + Rnd.Next(80), 1.6f + (float)Rnd.NextDouble() * 0.1f, Roots * 1.7f, 1f, 17, 3); } } for (int i = y + Roots; i < y + BaseSize; i++) { chunk.SetBlock(x, i, z, 17); chunk.SetMetadata(x, i, z, 3); } float horDir, verDir; int eX, eY, eZ; for (int j = 0; j < Branches; j++) { horDir = (120 * j) - 60 + Rnd.Next(120); verDir = VerticalStart + (float)Rnd.NextDouble() * VerticalRand; eX = x + (int)(Math.Cos(horDir * Math.PI / 180D) * verDir * BranchLength); eZ = z + (int)(Math.Sin(horDir * Math.PI / 180D) * verDir * BranchLength); eY = y + BaseSize + (int)((1f - verDir) * BranchLength); if (CanGenerateBranch(x, y + BaseSize, z, horDir, verDir, BranchLength, 1f, 4f, 1.5f) && CanGenerateLeaves(eX, eY, eZ, 4f, 1.5f)) { GenerateBranch(chunk, x, y + BaseSize, z, horDir, verDir, BranchLength, 1f, 17, 3); for (int m = 0; m < 1; m++) { GenerateLeaves(chunk, eX, eY, eZ, 4f, 1.5f, 18, 3, 17, 3); } } } /*var location = new Vector3(x, y, z); * if (!ValidLocation(location, 2)) return; * * int height = Math.Max(4, Rnd.Next(MaxHeight)); * * GenerateColumn(chunk, location, height, 17, 3); * Vector3 leafLocation = location + new Vector3(0, height, 0); * GenerateVanillaLeaves(chunk, leafLocation, 2, 18, 3); */ // base.Create(chunk, x, y, z); }
public override void Create(ChunkColumn chunk, int x, int y, int z) { if (x < 6 || x > 10 || z < 6 || z > 10) { return; } var block = chunk.GetBlock(x, y - 1, z); if (block != 2 && block != 3) { return; } BaseSize = 9 + Rnd.Next(5); if (Roots > 0f) { for (int k = 0; k < 3; k++) { GenerateBranch(chunk, x, y + Roots, z, (120 * k) - 40 + Rnd.Next(80), 1.6f + (float)Rnd.NextDouble() * 0.1f, Roots * 1.7f, 1f, 17, 3); //17 = Wood, 3 = Jungle Type } } for (int i = y + Roots; i < y + BaseSize; i++) { chunk.SetBlock(x, i, z, 17); chunk.SetMetadata(x, i, z, 3); } float horDir, verDir; int eX, eY, eZ; for (int j = 0; j < Branches; j++) { horDir = (120 * j) - 60 + Rnd.Next(120); verDir = VerticalStart + (float)Rnd.NextDouble() * VerticalRand; eX = x + (int)(Math.Cos(horDir * Math.PI / 180D) * verDir * BranchLength); eZ = z + (int)(Math.Sin(horDir * Math.PI / 180D) * verDir * BranchLength); eY = y + BaseSize + (int)((1f - verDir) * BranchLength); if (CanGenerateBranch(x, y + BaseSize, z, horDir, verDir, BranchLength, 1f, 4f, 1.5f) && CanGenerateLeaves(eX, eY, eZ, 4f, 1.5f)) { GenerateBranch(chunk, x, y + BaseSize, z, horDir, verDir, BranchLength, 1f, 17, 3); //17 = Wood, 3 = Jungle Type for (int m = 0; m < 1; m++) { GenerateLeaves(chunk, eX, eY, eZ, 4f, 1.5f, 18, 3, //18 = Leaves, 3 = Jungle Type 17, 3); //17 = Wood, 3 = Jungle Type } } } }
public virtual void Create(ChunkColumn chunk, int x, int y, int z) { if (chunk.GetBlock(x, y + Height, z) == 0) { foreach (var b in Blocks) { chunk.SetBlock(x + (int) b.Coordinates.X, y + (int) b.Coordinates.Y, z + (int) b.Coordinates.Z, b); } } }
public virtual void Create(ChunkColumn chunk, int x, int y, int z) { if (chunk.GetBlock(x, y + Height, z) == 0) { foreach (var b in Blocks) { chunk.SetBlock(x + (int)b.Coordinates.X, y + (int)b.Coordinates.Y, z + (int)b.Coordinates.Z, b); } } }
public void Create(ChunkColumn chunk, int x, int y, int z) { if (chunk.GetBlock(x, y + MaxHeight, z) == (byte) Material.Air) { foreach (Block b in Blocks) { chunk.SetBlock(x + b.Coordinates.X, y + b.Coordinates.Y, z + b.Coordinates.Z, b.Id); chunk.SetMetadata(x + b.Coordinates.X, y + b.Coordinates.Y, z + b.Coordinates.Z, b.Metadata); } } }
private static byte GetHeightFix(ChunkColumn chunk, int x, int z) { for (byte y = 255; y > 0; y--) { if (chunk.GetBlock(x, y, z) > 0) { return(y); } } return(1); }
private byte GetHeightFix(ChunkColumn column, int x, int z) { for (byte y = 255; y > 0; y--) { if (column.GetBlock(x, y, z) > 0) { return(y); } } return(0); }
public override void Create(ChunkColumn chunk, int x, int y, int z) { var block = chunk.GetBlock(x, y - 1, z); if (block != 2 && block != 3) { return; } base.Create(chunk, x, y, z); }
public void Create(ChunkColumn chunk, int x, int y, int z) { if (chunk.GetBlock(x, y + MaxHeight, z) == (byte)Material.Air) { foreach (Block b in Blocks) { chunk.SetBlock(x + b.Coordinates.X, y + b.Coordinates.Y, z + b.Coordinates.Z, b.Id); chunk.SetMetadata(x + b.Coordinates.X, y + b.Coordinates.Y, z + b.Coordinates.Z, b.Metadata); } } }
private void DecorateChunk(ChunkColumn chunk, float[] heightMap, float[] thresholdMap, Biome[] biomes, ChunkDecorator[] decorators) { for (int x = 0; x < Width; x++) { for (int z = 0; z < Depth; z++) { var height = chunk.height[(x << 4) + z]; var biome = biomes[(x << 4) + z]; for (int y = 0; y < Height; y++) { bool isSurface = false; if (y <= height) { if (y < 255 && chunk.GetBlock(x, y, z) == 1 && chunk.GetBlock(x, y + 1, z) == 0) { isSurface = true; } if (isSurface) { if (y >= WaterLevel) { chunk.SetBlock(x, y, z, biome.SurfaceBlock); chunk.SetMetadata(x, y, z, biome.SurfaceMetadata); chunk.SetBlock(x, y - 1, z, biome.SoilBlock); chunk.SetMetadata(x, y - 1, z, biome.SoilMetadata); } } } for (int i = 0; i < decorators.Length; i++) { decorators[i].Decorate(chunk, biome, thresholdMap, x, y, z, isSurface, y < height - 1); } } } } }
private bool IsValidSugarCaneLocation(ChunkColumn chunk, int x, int y, int z) { if (y - 1 <= 0) { return(false); } if (x - 1 >= 0 && x + 1 < 16) { if (z - 1 >= 0 && z + 1 < 16) { if (chunk.GetBlock(x + 1, y, z) == 8 || chunk.GetBlock(x - 1, y, z) == 8 || chunk.GetBlock(x, y, z + 1) == 8 || chunk.GetBlock(x, y, z - 1) == 8) { return(true); } } } return(false); }
private bool CheckSafe(ChunkColumn chunk, int x, int y, int z) { if (chunk.GetBlock(x - 1, y, z) != 0) { return(false); } if (chunk.GetBlock(x + 1, y, z) != 0) { return(false); } if (chunk.GetBlock(x, y, z - 1) != 0) { return(false); } if (chunk.GetBlock(x, y, z + 1) != 0) { return(false); } return(true); }
public bool IsAir(BlockCoordinates blockCoordinates) { ChunkColumn chunk = GetChunk(blockCoordinates); if (chunk == null) { return(true); } byte bid = chunk.GetBlock(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); return(bid == 0); }
public override void Decorate(ChunkColumn chunk, BiomeBase biome, int x, int z) { for (var y = StandardWorldProvider.WaterLevel; y < 256; y++) { if (StandardWorldProvider.GetRandomNumber(0, 10) == 5) { if (chunk.GetBlock(x, y, z) == biome.TopBlock.Id) { chunk.SetBlock(x, y + 1, z, new Block(31) {Metadata = 1}); } } } }
public bool IsTransparent(BlockCoordinates blockCoordinates) { ChunkColumn chunk = GetChunk(blockCoordinates); if (chunk == null) { return(true); } byte bid = chunk.GetBlock(blockCoordinates.X & 0x0f, blockCoordinates.Y & 0xff, blockCoordinates.Z & 0x0f); return(PCPEConvert.UnconvertedTransparentBlocks.Contains(bid)); }
public override void Decorate(ChunkColumn chunk, BiomeBase biome) { for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { //Check for temperature. for (var y = 0; y < StandardWorldProvider.WaterLevel; y++) { //Lake generation if (y < StandardWorldProvider.WaterLevel) { if (chunk.GetBlock(x, y, z) == 2 || chunk.GetBlock(x, y, z) == 3) //Grass or Dirt? { if (StandardWorldProvider.GetRandomNumber(1, 40) == 1 && y < StandardWorldProvider.WaterLevel - 4) { chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(82)); //Clay } else { chunk.SetBlock(x, y, z, new BlockSand()); //Sand chunk.BiomeId[x * 16 + z] = 16; //Beach } } if (chunk.GetBlock(x, y + 1, z) == 0) { if (y < StandardWorldProvider.WaterLevel - 3) { chunk.SetBlock(x, y + 1, z, new BlockFlowingWater()); //Water chunk.BiomeId[x * 16 + z] = 0; //Ocean } } } } } } }
public override void Decorate(ChunkColumn chunk, BiomeBase biome, int x, int z) { if (x < 15 && x > 3 && z < 15 && z > 3) { for (var y = StandardWorldProvider.WaterLevel; y < 256; y++) { if (StandardWorldProvider.GetRandomNumber(0, 30) == 5) { if (chunk.GetBlock(x, y + 1, z) == biome.TopBlock.Id) { GenerateTree(chunk, x, y + 1, z, biome); } } } } }
public override void Decorate(ChunkColumn chunk, BiomeBase biome, int x, int z) { if (x < 15 && x > 3 && z < 15 && z > 3) { for (var y = StandardWorldProvider.WaterLevel; y < 256; y++) { if (StandardWorldProvider.GetRandomNumber(0, 13) == 5) { if (chunk.GetBlock(x, y + 1, z) == biome.TopBlock.Id) { GenerateTree(chunk, x, y + 1, z, biome); } } } } }
public override void Decorate(ChunkColumn chunk, BiomeBase biome, int x, int z) { for (var y = StandardWorldProvider.WaterLevel; y < 256; y++) { if (StandardWorldProvider.GetRandomNumber(0, 10) == 5) { if (chunk.GetBlock(x, y, z) == biome.TopBlock.Id) { chunk.SetBlock(x, y + 1, z, new Block(31) { Metadata = 1 }); } } } }
public override void Decorate(ChunkColumn column, Biome biome, float[] thresholdMap, int x, int y, int z, bool surface, bool isBelowMaxHeight) { if (y > OverworldGenerator.WaterLevel && y > 32) { return; } //var density = thresholdMap[x + 16*(y + 256*z)]; /*var bid = column.GetBlock(x, y, z); * if (bid == 0 /* || density < 0) //If this block is supposed to be air. * { * if (surface && biome.Temperature <= 0f) * { * column.SetBlock(x, y, z, 79); * } * else * { * column.SetBlock(x, y, z, 8); * } * } * else if (surface) * { * column.SetBlock(x,y,z, 12); * }*/ // if (y >= SurvivalWorldProvider.WaterLevel) return; var block = column.GetBlock(x, y, z); if (surface) { column.SetBlock(x, y, z, 12); //Sand } else if (y <= OverworldGenerator.WaterLevel && block == 0) { if (biome.Temperature <= 0f && y == OverworldGenerator.WaterLevel - 1) { column.SetBlock(x, y, z, 79); //Ice } else { column.SetBlock(x, y, z, 8); //Water } } }
public override void Decorate(ChunkColumn chunk, BiomeBase biome, int x, int z) { _chunke = chunk; for (var y = 1 /*No need to check first layer :p*/; y < 128 /*Nothing above this*/; y++) { if (chunk.GetBlock(x, y, z) == 1) { if (y < 128) { GenerateCoal(x, y, z); } if (y < 64) { GenerateIron(x, y, z); } if (y < 29) { GenerateGold(x, y, z); } if (y < 23) { GenerateLapis(x, y, z); } if (y < 16) { if (y > 12) { if (StandardWorldProvider.GetRandomNumber(0, 3) == 2) { GenerateDiamond(x, y, z); } } else { GenerateDiamond(x, y, z); } } } } }
public override void Create(ChunkColumn chunk, int x, int y, int z) { if (chunk.GetBlock(x, y - 1, z) != 12) { return; //Not sand, do not generate. } var growth = Rnd.Next(0x1, 0x15); for (int modifiedY = y; modifiedY < y + _height; modifiedY++) { if (!CheckSafe(chunk, x, modifiedY, z)) { break; } chunk.SetBlock(x, modifiedY, z, 81); //Cactus block chunk.SetMetadata(x, modifiedY, z, (byte)growth); } }
public override void Decorate(ChunkColumn chunk, BiomeBase biome) { for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { for (var y = 0; y < LavaLevel; y++) { //Lake generation if (y < LavaLevel) { if (chunk.GetBlock(x, y + 1, z) == 0) { chunk.SetBlock(x, y + 1, z, BlockFactory.GetBlockById(10)); //Lava } } } } } }
public override void Decorate(ChunkColumn chunk, BiomeBase biome, int x, int z) { for (var y = StandardWorldProvider.WaterLevel; y < 256; y++) { if (StandardWorldProvider.GetRandomNumber(0, 15) == 5) { if (chunk.GetBlock(x, y, z) == biome.TopBlock.Id) { //var meta = ExperimentalV2Generator.GetRandomNumber(0, 8); chunk.SetBlock(x, y + 1, z, new Block(175) { Metadata = 0 }); chunk.SetBlock(x, y + 2, z, new Block(175) { Metadata = 1 }); } } } }
public static byte GetBlock(int x, int y, int z) { ColumnCoord colCoord = GetColumnCoord(x, z); try { ChunkColumn chunkCol = null; if (columns.TryGetValue(colCoord, out chunkCol)) { if (chunkCol.hasMapData) { return(chunkCol.GetBlock(x - colCoord.x * ChunkColumn.chunkSize, y, z - colCoord.z * ChunkColumn.chunkSize)); } } } catch (Exception e) { Debug.Log("Chunk error!! " + e); } return(0); }
private void DecorateTrees(ChunkColumn chunk, BiomeBase biome) { for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { for (var y = StandardWorldProvider.WaterLevel; y < 256; y++) { if (StandardWorldProvider.GetRandomNumber(0, 13) == 5) { //The if is so we don't have 'f****d up' trees xD if (x < 15 && x > 3 && z < 15 && z > 3) { if (chunk.GetBlock(x, y + 1, z) == biome.TopBlock.Id) { GenerateTree(chunk, x, y + 1, z, biome); } } } } } } }
public override void Decorate(ChunkColumn chunk, BiomeBase biome) { for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { //Check for temperature. for (var y = 0; y < NetherWorldProvider.WaterLevel; y++) { //Lake generation if (y < NetherWorldProvider.WaterLevel) { if (chunk.GetBlock(x, y + 1, z) == 0) { if (y < NetherWorldProvider.WaterLevel - 3) { chunk.SetBlock(x, y + 1, z, new BlockStationaryLava()); //Water } } } } } } }
private void PopulateChunk(ChunkColumn chunk) { var bottom = new SimplexOctaveGenerator(ServerSettings.Seed.GetHashCode(), 8); var overhang = new SimplexOctaveGenerator(ServerSettings.Seed.GetHashCode(), 8); overhang.SetScale(1/OverhangScale); bottom.SetScale(1/Groundscale); for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { float ox = x + chunk.X*16; float oz = z + chunk.Z*16; var cBiome = _biomeManager.GetBiome((int) ox, (int) oz); chunk.BiomeId[x*16 + z] = cBiome.MinecraftBiomeId; var bottomHeight = (int) ((bottom.Noise(ox, oz, BottomsFrequency, BottomsAmplitude)*BottomsMagnitude) + BottomOffset + cBiome.BaseHeight); var maxHeight = (int) ((overhang.Noise(ox, oz, OverhangFrequency, OverhangAmplitude)*OverhangsMagnitude) + bottomHeight + OverhangOffset); maxHeight = Math.Max(1, maxHeight); for (var y = 0; y < maxHeight && y < 256; y++) { if (y == 0) { chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(7)); continue; } if (y > bottomHeight) { //part where we do the overhangs if (EnableOverhang) { var density = overhang.Noise(ox, y, oz, OverhangFrequency, OverhangAmplitude); if (density > Threshold) chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(1)); } } else { chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(1)); } } //Turn the blocks ontop into the correct material for (var y = 0; y < 256; y++) { if (chunk.GetBlock(x, y + 1, z) == 0 && chunk.GetBlock(x, y, z) == 1) { chunk.SetBlock(x, y, z, cBiome.TopBlock); chunk.SetBlock(x, y - 1, z, cBiome.Filling); chunk.SetBlock(x, y - 2, z, cBiome.Filling); } } foreach (var decorator in cBiome.Decorators) { decorator.Decorate(chunk, cBiome, x, z); } new OreDecorator().Decorate(chunk, cBiome, x, z); //Ores :) new BedrockDecorator().Decorate(chunk, cBiome, x, z); //Random bedrock :) } } new WaterDecorator().Decorate(chunk, new PlainsBiome()); //For now, ALWAYS use the water decorator on all chunks... _cavegen.GenerateCave(chunk); new LavaDecorator().Decorate(chunk, new PlainsBiome()); }
protected void GenerateVanillaCircle(ChunkColumn chunk, Vector3 location, int radius, Block block, double corner = 0) { for (var I = -radius; I <= radius; I = (I + 1)) { for (var j = -radius; j <= radius; j = (j + 1)) { var max = (int) Math.Sqrt((I*I) + (j*j)); if (max <= radius) { if (I.Equals(-radius) && j.Equals(-radius) || I.Equals(-radius) && j.Equals(radius) || I.Equals(radius) && j.Equals(-radius) || I.Equals(radius) && j.Equals(radius)) { if (corner + radius*0.2 < 0.4 || corner + radius*0.2 > 0.7 || corner.Equals(0)) continue; } var x = location.X + I; var z = location.Z + j; if (chunk.GetBlock((int) x, (int) location.Y, (int) z).Equals(0)) { chunk.SetBlock((int) x, (int) location.Y, (int) z, block); } } } } }
private void PopulateChunk(ChunkColumn chunk) { int trees = new Random().Next(0, 10); int[,] treeBasePositions = new int[trees, 2]; for (int t = 0; t < trees; t++) { int x = new Random().Next(1, 16); int z = new Random().Next(1, 16); treeBasePositions[t, 0] = x; treeBasePositions[t, 1] = z; } var bottom = new SimplexOctaveGenerator(_seed.GetHashCode(), 8); var overhang = new SimplexOctaveGenerator(_seed.GetHashCode(), 8); overhang.SetScale(1/64.0); bottom.SetScale(1/128.0); double overhangsMagnitude = 16; double bottomsMagnitude = 32; for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { float ox = x + chunk.x*16; float oz = z + chunk.z*16; int bottomHeight = (int)((bottom.Noise(ox, oz, 0.5, 0.5)*bottomsMagnitude) + 64.0); int maxHeight = (int)((overhang.Noise(ox, oz, 0.5, 0.5)*overhangsMagnitude) + bottomHeight + 32.0); double threshold = 0.0; maxHeight = Math.Max(1, maxHeight); for (int y = 0; y < maxHeight && y < 128; y++) { if (y <= 1) { chunk.SetBlock(x, y, z, 7); continue; } if (y > bottomHeight) { //part where we do the overhangs double density = overhang.Noise(ox, y, oz, 0.5, 0.5); if (density > threshold) chunk.SetBlock(x, y, z, (byte)Material.Stone); } else { chunk.SetBlock(x, y, z, (byte)Material.Stone); } } //turn the tops into grass chunk.SetBlock(x, bottomHeight, z, (byte)Material.Grass); //the top of the base hills chunk.SetBlock(x, bottomHeight - 1, z, (byte)Material.Dirt); chunk.SetBlock(x, bottomHeight - 2, z, (byte)Material.Dirt); for (int y = bottomHeight + 1; y > bottomHeight && y < maxHeight && y < 127; y++) { //the overhang byte thisblock = chunk.GetBlock(x, y, z); byte blockabove = chunk.GetBlock(x, y + 1, z); if (thisblock != (decimal)Material.Air && blockabove == (decimal)Material.Air) { if (chunk.GetBlock(x, y, z) == (byte)Material.Dirt || chunk.GetBlock(x, y, z) == (byte)Material.Air || chunk.GetBlock(x, y, z) == (byte)Material.Stone) chunk.SetBlock(x, y, z, (byte)Material.Grass); if (chunk.GetBlock(x, y - 1, z) != (decimal)Material.Air) chunk.SetBlock(x, y - 1, z, (byte)Material.Dirt); if (chunk.GetBlock(x, y - 2, z) != (decimal)Material.Air) chunk.SetBlock(x, y - 2, z, (byte)Material.Dirt); } } for (int y = 0; y < WaterLevel; y++) { //Lake generation if (y < WaterLevel) { if (chunk.GetBlock(x, y, z) == (decimal)Material.Grass || chunk.GetBlock(x, y, z) == (decimal)Material.Dirt) //Grass or Dirt? { if (GetRandomNumber(1, 40) == 1 && y < WaterLevel - 4) chunk.SetBlock(x, y, z, 82); //Clay else chunk.SetBlock(x, y, z, 12); //Sand } if (chunk.GetBlock(x, y + 1, z) == (decimal)Material.Air) { if (y < WaterLevel - 3) chunk.SetBlock(x, y + 1, z, 8); //FlowingWater } } } for (int y = 0; y < 127; y++) { byte thisblock = chunk.GetBlock(x, y, z); byte blockabove = chunk.GetBlock(x, y + 1, z); if (thisblock == (decimal)Material.Grass && blockabove == (decimal)Material.Air && y > WaterLevel) { //Grass if (GetRandomNumber(0, 5) == 1) { chunk.SetBlock(x, y + 1, z, 31); chunk.SetMetadata(x, y + 1, z, 1); } //Flowers if (GetRandomNumber(0, 65) == 1) { int meta = GetRandomNumber(0, 8); chunk.SetBlock(x, y + 1, z, 38); chunk.SetMetadata(x, y + 1, z, (byte)meta); } //Trees for (int pos = 0; pos < trees; pos++) { if (treeBasePositions[pos, 0] < 14 && treeBasePositions[pos, 0] > 4 && treeBasePositions[pos, 1] < 14 && treeBasePositions[pos, 1] > 4) { if (chunk.GetBlock(treeBasePositions[pos, 0], y + 1, treeBasePositions[pos, 1]) == 2) { if (y >= bottomHeight) GenerateTree(chunk, treeBasePositions[pos, 0], y + 1, treeBasePositions[pos, 1], WoodType.Oak); } } } } } } } }
protected void GenerateCircle(ChunkColumn chunk, Vector3 location, int radius, Block block) { for (var I = -radius; I <= radius; I = (I + 1)) { for (var j = -radius; j <= radius; j = (j + 1)) { var max = (int) Math.Sqrt((I*I) + (j*j)); if (max <= radius) { var X = location.X + I; var Z = location.Z + j; if (X < 0 || X >= 16 || Z < 0 || Z >= 256) continue; var x = (int) X; var y = (int) location.Y; var z = (int) Z; if (chunk.GetBlock(x, y, z).Equals(0)) { chunk.SetBlock(x, y, z, block); } } } } }
private void PopulateChunk(ChunkColumn chunk) { var bottom = new SimplexOctaveGenerator(ServerSettings.Seed.GetHashCode(), 8); var top = new SimplexOctaveGenerator(ServerSettings.Seed.GetHashCode(), 8); bottom.SetScale(1/Groundscale); top.SetScale(1/Topscale); for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { float ox = x + chunk.X*16; float oz = z + chunk.Z*16; var bottomHeight = (int) ((bottom.Noise(ox, oz, BottomsFrequency, BottomsAmplitude)*BottomsMagnitude) + BottomOffset); var topHeight = (int) ((top.Noise(ox, oz, TopFrequency, TopAmplitude)*TopMagnitude) + TopOffset); for (var y = 0; y < 256; y++) { if (y == 0 || y == 255) { chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(7)); continue; } if (y < bottomHeight) { chunk.SetBlock(x, y, z, new BlockNetherrack()); } if (y < topHeight) { chunk.SetBlock(x, 256 - y, z, new BlockNetherrack()); if (GetRandomNumber(1, 50) == 25) { chunk.SetBlock(x, 256 - (y + 1), z, new Block(89)); } } } //Turn the blocks ontop into the correct material for (var y = bottomHeight; y < 254; y++) { if (chunk.GetBlock(x, y + 1, z) == 0 && chunk.GetBlock(x, y, z) == 1) { chunk.SetBlock(x, y, z, new BlockNetherrack()); chunk.SetBlock(x, y - 1, z, new BlockNetherrack()); chunk.SetBlock(x, y - 2, z, new BlockNetherrack()); } } } } new NetherLavaDecorator().Decorate(chunk, new PlainsBiome()); }
private static NbtFile CreateNbtFromChunkColumn(ChunkColumn chunk, int yoffset) { var nbt = new NbtFile(); NbtCompound levelTag = new NbtCompound("Level"); nbt.RootTag.Add(levelTag); levelTag.Add(new NbtInt("xPos", chunk.x)); levelTag.Add(new NbtInt("zPos", chunk.z)); levelTag.Add(new NbtByteArray("Biomes", chunk.biomeId)); NbtList sectionsTag = new NbtList("Sections"); levelTag.Add(sectionsTag); for (int i = 0; i < 8; i++) { NbtCompound sectionTag = new NbtCompound(); sectionsTag.Add(sectionTag); sectionTag.Add(new NbtByte("Y", (byte) i)); int sy = i*16; byte[] blocks = new byte[4096]; byte[] data = new byte[2048]; byte[] blockLight = new byte[2048]; byte[] skyLight = new byte[2048]; for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 0; y < 16; y++) { int yi = sy + y; if (yi < 0 || yi >= 256) continue; // ? int anvilIndex = (y + yoffset)*16*16 + z*16 + x; byte blockId = chunk.GetBlock(x, yi, z); // PE to Anvil friendly converstion if (blockId == 5) blockId = 125; else if (blockId == 158) blockId = 126; else if (blockId == 50) blockId = 75; else if (blockId == 50) blockId = 76; else if (blockId == 89) blockId = 123; else if (blockId == 89) blockId = 124; else if (blockId == 73) blockId = 152; blocks[anvilIndex] = blockId; SetNibble4(data, anvilIndex, chunk.GetMetadata(x, yi, z)); SetNibble4(blockLight, anvilIndex, chunk.GetBlocklight(x, yi, z)); SetNibble4(skyLight, anvilIndex, chunk.GetSkylight(x, yi, z)); } } } sectionTag.Add(new NbtByteArray("Blocks", blocks)); sectionTag.Add(new NbtByteArray("Data", data)); sectionTag.Add(new NbtByteArray("BlockLight", blockLight)); sectionTag.Add(new NbtByteArray("SkyLight", skyLight)); } // TODO: Save entities NbtList entitiesTag = new NbtList("Entities", NbtTagType.Compound); levelTag.Add(entitiesTag); NbtList blockEntitiesTag = new NbtList("TileEntities", NbtTagType.Compound); levelTag.Add(blockEntitiesTag); foreach (NbtCompound blockEntityNbt in chunk.BlockEntities.Values) { NbtCompound nbtClone = (NbtCompound) blockEntityNbt.Clone(); nbtClone.Name = null; blockEntitiesTag.Add(nbtClone); } levelTag.Add(new NbtList("TileTicks", NbtTagType.Compound)); return nbt; }
private void PopulateChunk(ChunkColumn chunk) { int trees = new Random().Next(0, 10); int[,] treeBasePositions = new int[trees, 2]; for (int t = 0; t < trees; t++) { int x = new Random().Next(1, 16); int z = new Random().Next(1, 16); treeBasePositions[t, 0] = x; treeBasePositions[t, 1] = z; } for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { int stoneHeight = (int) Math.Floor(stoneBaseHeight); stoneHeight += GetNoise(chunk.x*16 + x, chunk.z*16 + z, stoneMountainFrequency, (int) Math.Floor(stoneMountainHeight)); if (stoneHeight < stoneMinHeight) stoneHeight = (int) Math.Floor(stoneMinHeight); stoneHeight += GetNoise(chunk.x*16 + x, chunk.z*16 + z, stoneBaseNoise, (int) Math.Floor(stoneBaseNoiseHeight)); int dirtHeight = stoneHeight + (int) Math.Floor(dirtBaseHeight); dirtHeight += GetNoise(chunk.x*16 + x, chunk.z*16 + z, dirtNoise, (int) Math.Floor(dirtNoiseHeight)); for (int y = 0; y < 256; y++) { //float y2 = Get3DNoise(chunk.X*16, y, chunk.Z*16, stoneBaseNoise, (int) Math.Floor(stoneBaseNoiseHeight)); if (y <= stoneHeight) { chunk.SetBlock(x, y, z, 1); //Diamond ore if (GetRandomNumber(0, 2500) < 5) { chunk.SetBlock(x, y, z, 56); } //Coal Ore if (GetRandomNumber(0, 1500) < 50) { chunk.SetBlock(x, y, z, 16); } //Iron Ore if (GetRandomNumber(0, 2500) < 30) { chunk.SetBlock(x, y, z, 15); } //Gold Ore if (GetRandomNumber(0, 2500) < 20) { chunk.SetBlock(x, y, z, 14); } } if (y < waterLevel) //FlowingWater :) { if (chunk.GetBlock(x, y, z) == 2 || chunk.GetBlock(x, y, z) == 3) //Grass or Dirt? { if (GetRandomNumber(1, 40) == 5 && y < waterLevel - 4) chunk.SetBlock(x, y, z, 82); //Clay else chunk.SetBlock(x, y, z, 12); //Sand } if (y < waterLevel - 3) chunk.SetBlock(x, y + 1, z, 8); //FlowingWater } if (y <= dirtHeight && y >= stoneHeight) { chunk.SetBlock(x, y, z, 3); //Dirt chunk.SetBlock(x, y + 1, z, 2); //Grass Block if (y > waterLevel) { //Grass if (GetRandomNumber(0, 5) == 2) { chunk.SetBlock(x, y + 2, z, 31); chunk.SetMetadata(x, y + 2, z, 1); } //flower if (GetRandomNumber(0, 65) == 8) { int meta = GetRandomNumber(0, 8); chunk.SetBlock(x, y + 2, z, 38); chunk.SetMetadata(x, y + 2, z, (byte) meta); } for (int pos = 0; pos < trees; pos++) { if (treeBasePositions[pos, 0] < 14 && treeBasePositions[pos, 0] > 4 && treeBasePositions[pos, 1] < 14 && treeBasePositions[pos, 1] > 4) { if (y < waterLevel + 2) break; if (chunk.GetBlock(treeBasePositions[pos, 0], y + 1, treeBasePositions[pos, 1]) == 2) { if (y == dirtHeight) GenerateTree(chunk, treeBasePositions[pos, 0], y + 1, treeBasePositions[pos, 1]); } } } } } if (y == 0) { chunk.SetBlock(x, y, z, 7); } } } } }
public ChunkColumn GenerateChunkColumn(ChunkCoordinates chunkCoordinates) { lock (_chunkCache) { ChunkColumn cachedChunk; if (_chunkCache.TryGetValue(chunkCoordinates, out cachedChunk)) { return cachedChunk; } ChunkColumn chunk = new ChunkColumn(); chunk.x = chunkCoordinates.X; chunk.z = chunkCoordinates.Z; int h = PopulateChunk(chunk); chunk.SetBlock(0, h + 1, 0, 7); chunk.SetBlock(1, h + 1, 0, 41); chunk.SetBlock(2, h + 1, 0, 41); chunk.SetBlock(3, h + 1, 0, 41); chunk.SetBlock(3, h + 1, 0, 41); //chunk.SetBlock(6, h + 1, 6, 57); chunk.SetBlock(6, h, 9, 63); chunk.SetMetadata(6, h, 9, 12); var blockEntity = GetBlockEntity((chunkCoordinates.X*16) + 6, h, (chunkCoordinates.Z*16) + 9); chunk.SetBlockEntity(blockEntity.Coordinates, blockEntity.GetCompound()); if (chunkCoordinates.X == 1 && chunkCoordinates.Z == 1) { for (int x = 0; x < 10; x++) { for (int z = 0; z < 10; z++) { for (int y = h - 2; y < h; y++) { chunk.SetBlock(x, y, z, 8); } } } } if (chunkCoordinates.X == 3 && chunkCoordinates.Z == 1) { for (int x = 0; x < 10; x++) { for (int z = 0; z < 10; z++) { for (int y = h - 1; y < h; y++) { chunk.SetBlock(x, y, z, 10); } } } } for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { for (int y = 127; y != 0; y--) { if (chunk.GetBlock(x, y, z) == 0x00) { chunk.SetSkylight(x, y, z, 0xff); } else { chunk.SetSkylight(x, y, z, 0x00); } } } } _chunkCache[chunkCoordinates] = chunk; return chunk; } }
private static NbtFile CreateNbtFromChunkColumn(ChunkColumn chunk, int yoffset) { var nbt = new NbtFile(); var levelTag = new NbtCompound("Level"); nbt.RootTag.Add(levelTag); levelTag.Add(new NbtInt("xPos", chunk.X)); levelTag.Add(new NbtInt("zPos", chunk.Z)); levelTag.Add(new NbtByteArray("Biomes", chunk.BiomeId)); var sectionsTag = new NbtList("Sections"); levelTag.Add(sectionsTag); for (var i = 0; i < 8; i++) { var sectionTag = new NbtCompound(); sectionsTag.Add(sectionTag); sectionTag.Add(new NbtByte("Y", (byte) i)); var sy = i*16; var blocks = new byte[4096]; var data = new byte[2048]; var blockLight = new byte[2048]; var skyLight = new byte[2048]; for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { for (var y = 0; y < 16; y++) { var yi = sy + y; if (yi < 0 || yi >= 256) continue; // ? var anvilIndex = (y + yoffset)*16*16 + z*16 + x; var blockId = chunk.GetBlock(x, yi, z); blocks[anvilIndex] = (byte) blockId; SetNibble4(data, anvilIndex, chunk.GetMetadata(x, yi, z)); SetNibble4(blockLight, anvilIndex, chunk.GetBlocklight(x, yi, z)); SetNibble4(skyLight, anvilIndex, chunk.GetSkylight(x, yi, z)); } } } sectionTag.Add(new NbtByteArray("Blocks", blocks)); sectionTag.Add(new NbtByteArray("Data", data)); sectionTag.Add(new NbtByteArray("BlockLight", blockLight)); sectionTag.Add(new NbtByteArray("SkyLight", skyLight)); } levelTag.Add(new NbtList("Entities", NbtTagType.Compound)); levelTag.Add(new NbtList("TileEntities", NbtTagType.Compound)); levelTag.Add(new NbtList("TileTicks", NbtTagType.Compound)); return nbt; }