public void GenerateCoal(int x, int y, int z) { if (StandardWorldProvider.GetRandomNumber(0, 35) == 1) { _chunke.SetBlock(x, y, z, BlockFactory.GetBlockById(16)); } }
private void CreateTerrainShape(ChunkColumn chunk, float[] heightMap, float[] thresholdMap, Biome[] biomes) { for (int x = 0; x < Width; x++) { for (int z = 0; z < Depth; z++) { var idx = (x << 4) + z; Biome biome = biomes[idx]; chunk.biomeId[idx] = (byte)biome.Id; // SetBiome(x, z, (byte)biome.Id); float stoneHeight = heightMap[idx]; /* if (stoneHeight > 200 || stoneHeight < 0) * { * Debug.WriteLine("MaxHeight: " + stoneHeight); * }*/ var maxY = 0; for (int y = 0; y < stoneHeight && y < 255; y++) { float density = thresholdMap[x + ((y + (z << 8)) << 4)]; if (y < WaterLevel || (density > Threshold && y >= WaterLevel)) { chunk.SetBlock(x, y, z, 1); maxY = y; } } chunk.SetBlock(x, 0, z, 7); //Bedrock heightMap[idx] = maxY; chunk.height[idx] = (short)maxY; //chunk.SetHeight(x, z, (byte)maxY); } } }
protected void GenerateLeaves(ChunkColumn chunk, 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) { //blocks[OverworldGenerator.GetIndex(x + i, y + j, z + k)] = woodId; //metadata[OverworldGenerator.GetIndex(x + i, y + j, z + k)] = woodMeta; chunk.SetBlock(x + i, y + j, z + k, woodId); //world.SetMetadata(x + i, y + j, z + k, woodMeta); } //if (blocks[OverworldGenerator.GetIndex(x + i, y + j, z + k)] == 0) { //blocks[OverworldGenerator.GetIndex(x + i, y + j, z + k)] = leafBlockId; //metadata[OverworldGenerator.GetIndex(x + i, y + j, z + k)] = leafMeta; chunk.SetBlock(x + i, y + j, z + k, leafBlockId); //world.SetMetadata(x + i, y + j, z + k, leafMeta); } } } } } }
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) { 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 < 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, BlockFactory.GetBlockById(12)); //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, BlockFactory.GetBlockById(8)); //Water chunk.BiomeId[x * 16 + z] = 0; //Ocean } } } } //} /*else //Fill up with sand * { * for (var y = 0; y < ExperimentalV2Generator.WaterLevel; y++) * { * if (y < ExperimentalV2Generator.WaterLevel) * { * if (chunk.GetBlock(x, y, z) == 2 || chunk.GetBlock(x, y, z) == 3 || chunk.GetBlock(x,y,z) == 0) //Grass or Dirt? * { * chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(12)); //Sand * //chunk.BiomeId[x * 16 + z] = 16; //Beach * } * } * } * }*/ } } }
private void GenerateTerrain(ChunkColumn column, float[] noise) { var heightMap = noise; for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { /* var biome = biomes[NoiseMap.GetIndex(x, z)]; * * byte biomeId = (byte) biome.Id; * if (ApplyBlocks) * {*/ var h = (int)heightMap[NoiseMap.GetIndex(x, z)]; var height = h; for (int y = 0; (y <= height || y <= Preset.SeaLevel) && y < 255; y++) { if (y > height) { if (y < Preset.SeaLevel) { column.SetBlock(x, y, z, new Water()); } else { column.SetBlock(x, y, z, new Air()); } } else if (y == height) { column.SetBlock(x, y, z, new Stone()); // column.SetBlock(x, y, z, BlockFactory.GetBlockById(biome.SurfaceBlock)); //column.SetMetadata(x, y, z, biome.SurfaceMetadata); // column.SetBlock(x, y - 1, z, BlockFactory.GetBlockById(biome.SoilBlock)); //column.SetMetadata(x, y -1, z, biome.SoilMetadata); } else if (y < height) { column.SetBlock(x, y, z, new Stone()); } } column.SetHeight(x, z, (short)height); //} //column.SetBiome(x, z, biomeId); } } }
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) { chunk.SetBlock(x, y + 1, z, new Block(175) {Metadata = 0}); chunk.SetBlock(x, y + 2, z, new Block(175) {Metadata = 1}); } } } }
public void PopulateChunk(ChunkColumn chunk) { for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { chunk.SetBlock(x, 1, z, 7); // Bedrock chunk.SetBlock(x, 2, z, 3); // Dirt chunk.SetBlock(x, 3, z, 3); // Dirt chunk.SetBlock(x, 4, z, 2); // Grass chunk.SetHeight(x, z, 4); } } }
public void PaintTerrain(ChunkColumn column, int i, int j, int x, int z, int depth, OverworldGeneratorV2 generator, float[] noise, float river, BiomeBase[] biomes) { float c = TerrainBase.CalcCliff(x, z, noise); bool cliff = c > 1.4f; for (int k = 255; k > -1; k--) { Block b = column.GetBlockObject(x, k, z); if (b is Air) { depth = -1; } else if (b is Stone) { depth++; if (cliff) { if (depth > -1 && depth < 2) { if (_rnd.Next(3) == 0) { column.SetBlock(x, k, z, CliffCobbleBlock); } else { column.SetBlock(x, k, z, CliffStoneBlock); } } else if (depth < 10) { column.SetBlock(x, k, z, CliffStoneBlock); } } else { if (depth == 0 && k > 61) { column.SetBlock(x, k, z, TopBlock); } else if (depth < 4) { column.SetBlock(x, k, z, FillerBlock); } } } } }
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); } } } } }
protected void GenerateBranch(ChunkColumn chunk, float x, float y, float z, double horDir, float verDir, float length, float speed, byte blockId, byte meta) { if (verDir < 0f) { verDir = -verDir; } float c = 0f; float velY = 1f - verDir; if (verDir > 1f) { verDir = 1f - (verDir - 1f); } float velX = (float)Math.Cos(horDir * Math.PI / 180D) * verDir; float velZ = (float)Math.Sin(horDir * Math.PI / 180D) * verDir; while (c < length) { //blocks[OverworldGenerator.GetIndex((int)x, (int)y, (int)z)] = blockId;//); //metadata[OverworldGenerator.GetIndex((int) x, (int) y, (int) z)] = meta; //world.SetMetadata((int)x, (int)y, (int)z, meta); chunk.SetBlock((int)x, (int)y, (int)z, blockId); x += velX; y += velY; z += velZ; c += speed; } }
protected void GenerateCircle(ChunkColumn chunk, Vector3 location, int radius, byte id, byte meta) { 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 (blocks[OverworldGenerator.GetIndex(x, y, z)].Equals(0)) { //blocks[OverworldGenerator.GetIndex(x, y, z)] = id; //metadata[OverworldGenerator.GetIndex(x, y, z)] = meta; chunk.SetBlock(x, y, z, id); //chunk.SetMetadata(x, y, z, meta); } } } } }
public static void SetBlock(int x, int y, int z, byte blockID) { ColumnCoord colCoord = GetColumnCoord(x, z); try { ChunkColumn chunkCol = null; if (columns.TryGetValue(colCoord, out chunkCol)) { if (chunkCol.hasMapData) { chunkCol.SetBlock(x - colCoord.x * ChunkColumn.chunkSize, y, z - colCoord.z * ChunkColumn.chunkSize, blockID); } else { Debug.LogError("Block set on chunk without data"); } } else { Debug.LogError("Block set on non existing chunk"); } } catch (Exception e) { Debug.Log("Set Block chunk error " + e); } }
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 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 GenerateTopper(ChunkColumn chunk, Vector3 location, byte type = 0x0) { var sectionRadius = 1; GenerateCircle(chunk, location, sectionRadius, new Block(18) { Metadata = 1 }); var top = location + new Vector3(0, 1, 0); var x = (int)location.X; var y = (int)location.Y + 1; var z = (int)location.Z; chunk.SetBlock(x, y, z, new Block(18) { Metadata = 1 }); if (type == 0x1 && y < 256) { GenerateVanillaCircle(chunk, new Vector3(x, y, z), sectionRadius, new Block(18) { Metadata = 1 }); } }
public void SetBlock(Block block) { ChunkColumn chunk = GetChunk(block.Coordinates); chunk.SetBlock(block.Coordinates.X & 0x0f, block.Coordinates.Y & 0xff, block.Coordinates.Z & 0x0f, block.Id); chunk.SetMetadata(block.Coordinates.X & 0x0f, block.Coordinates.Y & 0xff, block.Coordinates.Z & 0x0f, block.Metadata); }
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 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 int PopulateChunk(ChunkColumn chunk) { for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { for (var y = 0; y < 4; y++) { if (y == 0) { chunk.SetBlock(x, y, z, new BlockBedrock()); } if (y == 1 || y == 2) { chunk.SetBlock(x, y, z, new Block(3)); } if (y == 3) { chunk.SetBlock(x, y, z, new BlockGrass()); } if (chunk.X == 1 && chunk.Z == 1) { if (y == 1 || y == 2 || y == 3) { chunk.SetBlock(x, y, z, new BlockFlowingLava()); } } if (chunk.X == 3 && chunk.Z == 1) { if (y == 3) { chunk.SetBlock(x, y, z, new BlockFlowingWater()); } } } } } return(4); }
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 static void GenerateColumn(ChunkColumn chunk, Vector3 location, int height, Block block) { for (var o = 0; o < height; o++) { var x = (int) location.X; var y = (int) location.Y + o; var z = (int) location.Z; chunk.SetBlock(x, y, z, block); } }
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); } } }
private void PopulateChunk(ChunkColumn chunk) { var bottom = new SimplexOctaveGenerator(Globals.Seed.GetHashCode(), 8); var top = new SimplexOctaveGenerator(Globals.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()); }
public void Create(ChunkColumn chunk, int x, int y, int z) { if (chunk.GetBlockId(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); } } }
public override void Decorate(ChunkColumn chunk, BiomeBase biome, int x, int z) { for (var y = 1; y < 6; y++) { if (StandardWorldProvider.GetRandomNumber(0, 5) == 1) { chunk.SetBlock(x, y, z, BlockFactory.GetBlockById(7)); } } }
public static void GenerateColumn(ChunkColumn chunk, Vector3 location, int height, Block block) { for (var o = 0; o < height; o++) { var x = (int)location.X; var y = (int)location.Y + o; var z = (int)location.Z; chunk.SetBlock(x, y, z, block); } }
public override ChunkColumn GenerateChunkColumn(Vector2 chunkCoordinates) { if (ChunkCache.ContainsKey(new Tuple <int, int>(chunkCoordinates.X, chunkCoordinates.Z))) { ChunkColumn c; if (ChunkCache.TryGetValue(new Tuple <int, int>(chunkCoordinates.X, chunkCoordinates.Z), out c)) { Debug.WriteLine("Chunk " + chunkCoordinates.X + ":" + chunkCoordinates.Z + " was already generated!"); return(c); } } if (File.Exists((_folder + "/" + chunkCoordinates.X + "." + chunkCoordinates.Z + ".cfile"))) { var cd = LoadChunk(chunkCoordinates.X, chunkCoordinates.Z); if (!ChunkCache.ContainsKey(new Tuple <int, int>(cd.X, cd.Z))) { ChunkCache.Add(new Tuple <int, int>(cd.X, cd.Z), cd); } return(cd); } Debug.WriteLine("ChunkFile not found, generating..."); var chunk = new ChunkColumn { X = chunkCoordinates.X, Z = chunkCoordinates.Z }; var h = PopulateChunk(chunk); chunk.SetBlock(0, h + 1, 0, new Block(7)); chunk.SetBlock(1, h + 1, 0, new Block(41)); chunk.SetBlock(2, h + 1, 0, new Block(41)); chunk.SetBlock(3, h + 1, 0, new Block(41)); chunk.SetBlock(3, h + 1, 0, new Block(41)); if (!ChunkCache.ContainsKey(new Tuple <int, int>(chunkCoordinates.X, chunkCoordinates.Z))) { ChunkCache.Add(new Tuple <int, int>(chunkCoordinates.X, chunkCoordinates.Z), chunk); } return(chunk); }
public static void GenerateColumn(ChunkColumn chunk, Vector3 location, int height, byte id, byte meta) { for (var o = 0; o < height; o++) { var x = (int)location.X; var y = (int)location.Y + o; var z = (int)location.Z; chunk.SetBlock(x, y, z, id); chunk.SetMetadata(x, y, z, meta); } }
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) { chunk.SetBlock(x, y + 1, z, new Block(175) { Metadata = 0 }); chunk.SetBlock(x, y + 2, z, new Block(175) { Metadata = 1 }); } } } }
public virtual void Create(ChunkColumn chunk, int x, int y, int z) { if (chunk.GetBlock(x, y + MaxHeight, z) == (byte)0) { 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); } } }
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); } } } } }
public void GenerateCave(ChunkColumn chunk) { _gcRandom = new GcRandom(chunk, _seedi); for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { for (var y = 50; y >= 6; y--) { if (_gcRandom.IsInCave(x, y, z)) { chunk.SetBlock(x, y, z, new BlockAir()); } } } } }
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) { 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 } } } } } } }
public override ChunkColumn GenerateChunkColumn(Vector2 chunkCoordinates) { if (ChunkCache.ContainsKey(new Tuple<int, int>(chunkCoordinates.X, chunkCoordinates.Z))) { ChunkColumn c; if (ChunkCache.TryGetValue(new Tuple<int, int>(chunkCoordinates.X, chunkCoordinates.Z), out c)) { Debug.WriteLine("Chunk " + chunkCoordinates.X + ":" + chunkCoordinates.Z + " was already generated!"); return c; } } if (File.Exists((_folder + "/" + chunkCoordinates.X + "." + chunkCoordinates.Z + ".cfile"))) { var cd = LoadChunk(chunkCoordinates.X, chunkCoordinates.Z); if (!ChunkCache.ContainsKey(new Tuple<int, int>(cd.X, cd.Z))) ChunkCache.Add(new Tuple<int, int>(cd.X, cd.Z), cd); return cd; } Debug.WriteLine("ChunkFile not found, generating..."); var chunk = new ChunkColumn {X = chunkCoordinates.X, Z = chunkCoordinates.Z}; var h = PopulateChunk(chunk); chunk.SetBlock(0, h + 1, 0, new Block(7)); chunk.SetBlock(1, h + 1, 0, new Block(41)); chunk.SetBlock(2, h + 1, 0, new Block(41)); chunk.SetBlock(3, h + 1, 0, new Block(41)); chunk.SetBlock(3, h + 1, 0, new Block(41)); if (!ChunkCache.ContainsKey(new Tuple<int, int>(chunkCoordinates.X, chunkCoordinates.Z))) ChunkCache.Add(new Tuple<int, int>(chunkCoordinates.X, chunkCoordinates.Z), chunk); return chunk; }
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) { 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); } } } } } } } }
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()); }
public static ChunkColumn GetChunk(ChunkCoordinates coordinates, string basePath, IWorldProvider generator, int yoffset) { int width = 32; int depth = 32; int rx = coordinates.X >> 5; int rz = coordinates.Z >> 5; string filePath = Path.Combine(basePath, string.Format(@"region\r.{0}.{1}.mca", rx, rz)); if (!File.Exists(filePath)) return generator.GenerateChunkColumn(coordinates); using (var regionFile = File.OpenRead(filePath)) { byte[] buffer = new byte[8192]; regionFile.Read(buffer, 0, 8192); int xi = (coordinates.X%width); if (xi < 0) xi += 32; int zi = (coordinates.Z%depth); if (zi < 0) zi += 32; int tableOffset = (xi + zi*width)*4; regionFile.Seek(tableOffset, SeekOrigin.Begin); byte[] offsetBuffer = new byte[4]; regionFile.Read(offsetBuffer, 0, 3); Array.Reverse(offsetBuffer); int offset = BitConverter.ToInt32(offsetBuffer, 0) << 4; int length = regionFile.ReadByte(); if (offset == 0 || length == 0) { return generator.GenerateChunkColumn(coordinates); } regionFile.Seek(offset, SeekOrigin.Begin); byte[] waste = new byte[4]; regionFile.Read(waste, 0, 4); int compressionMode = regionFile.ReadByte(); var nbt = new NbtFile(); nbt.LoadFromStream(regionFile, NbtCompression.ZLib); NbtTag dataTag = nbt.RootTag["Level"]; NbtList sections = dataTag["Sections"] as NbtList; ChunkColumn chunk = new ChunkColumn { x = coordinates.X, z = coordinates.Z, biomeId = dataTag["Biomes"].ByteArrayValue }; for (int i = 0; i < chunk.biomeId.Length; i++) { if (chunk.biomeId[i] > 22) chunk.biomeId[i] = 0; } if (chunk.biomeId.Length > 256) throw new Exception(); // This will turn into a full chunk column foreach (NbtTag sectionTag in sections) { int sy = sectionTag["Y"].ByteValue*16; byte[] blocks = sectionTag["Blocks"].ByteArrayValue; byte[] data = sectionTag["Data"].ByteArrayValue; NbtTag addTag = sectionTag["Add"]; byte[] adddata = new byte[2048]; if (addTag != null) adddata = addTag.ByteArrayValue; byte[] blockLight = sectionTag["BlockLight"].ByteArrayValue; byte[] skyLight = sectionTag["SkyLight"].ByteArrayValue; 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 - yoffset; if (yi < 0 || yi >= 128) continue; int anvilIndex = y*16*16 + z*16 + x; int blockId = blocks[anvilIndex] + (Nibble4(adddata, anvilIndex) << 8); // Anvil to PE friendly converstion if (blockId == 125) blockId = 5; else if (blockId == 126) blockId = 158; else if (blockId == 75) blockId = 50; else if (blockId == 76) blockId = 50; else if (blockId == 123) blockId = 89; else if (blockId == 124) blockId = 89; else if (blockId == 152) blockId = 73; else if (_ignore.BinarySearch(blockId) >= 0) blockId = 0; else if (_gaps.BinarySearch(blockId) >= 0) { Debug.WriteLine("Missing material: " + blockId); blockId = 133; } if (blockId > 255) blockId = 41; if (yi == 127 && blockId != 0) blockId = 30; if (yi == 0 && (blockId == 8 || blockId == 9 /*|| blockId == 0*/)) blockId = 7; //if (blockId != 0) blockId = 41; chunk.SetBlock(x, yi, z, (byte) blockId); chunk.SetMetadata(x, yi, z, Nibble4(data, anvilIndex)); chunk.SetBlocklight(x, yi, z, Nibble4(blockLight, anvilIndex)); chunk.SetSkylight(x, yi, z, Nibble4(skyLight, anvilIndex)); } } } } NbtList entities = dataTag["Entities"] as NbtList; NbtList blockEntities = dataTag["TileEntities"] as NbtList; if (blockEntities != null) { foreach (var nbtTag in blockEntities) { var blockEntityTag = (NbtCompound) nbtTag; string entityId = blockEntityTag["id"].StringValue; int x = blockEntityTag["x"].IntValue; int y = blockEntityTag["y"].IntValue - yoffset; int z = blockEntityTag["z"].IntValue; blockEntityTag["y"] = new NbtInt("y", y); BlockEntity blockEntity = BlockEntityFactory.GetBlockEntityById(entityId); if (blockEntity != null) { blockEntityTag.Name = string.Empty; chunk.SetBlockEntity(new BlockCoordinates(x, y, z), blockEntityTag); } } } NbtList tileTicks = dataTag["TileTicks"] as NbtList; chunk.isDirty = false; return chunk; } }
private void GenerateTree(ChunkColumn chunk, int x, int treebase, int z) { int treeheight = GetRandomNumber(4, 5); chunk.SetBlock(x, treebase + treeheight + 2, z, 18); //Top leave chunk.SetBlock(x, treebase + treeheight + 1, z + 1, 18); chunk.SetBlock(x, treebase + treeheight + 1, z - 1, 18); chunk.SetBlock(x + 1, treebase + treeheight + 1, z, 18); chunk.SetBlock(x - 1, treebase + treeheight + 1, z, 18); chunk.SetBlock(x, treebase + treeheight, z + 1, 18); chunk.SetBlock(x, treebase + treeheight, z - 1, 18); chunk.SetBlock(x + 1, treebase + treeheight, z, 18); chunk.SetBlock(x - 1, treebase + treeheight, z, 18); chunk.SetBlock(x + 1, treebase + treeheight, z + 1, 18); chunk.SetBlock(x - 1, treebase + treeheight, z - 1, 18); chunk.SetBlock(x + 1, treebase + treeheight, z - 1, 18); chunk.SetBlock(x - 1, treebase + treeheight, z + 1, 18); for (int i = 0; i <= treeheight; i++) { chunk.SetBlock(x, treebase + i, z, 17); } }
public int PopulateChunk(ChunkColumn chunk) { for (var x = 0; x < 16; x++) { for (var z = 0; z < 16; z++) { for (var y = 0; y < 4; y++) { if (y == 0) { chunk.SetBlock(x, y, z, new BlockBedrock()); } if (y == 1 || y == 2) { chunk.SetBlock(x, y, z, new Block(3)); } if (y == 3) { chunk.SetBlock(x, y, z, new BlockGrass()); } if (chunk.X == 1 && chunk.Z == 1) { if (y == 1 || y == 2 || y == 3) { chunk.SetBlock(x, y, z, new BlockFlowingLava()); } } if (chunk.X == 3 && chunk.Z == 1) { if (y == 3) { chunk.SetBlock(x, y, z, new BlockFlowingWater()); } } } } } return 4; }
public ChunkColumn GetChunk(int X, int Z) { var width = 32; var depth = 32; var rx = X >> 5; var rz = Z >> 5; var filePath = Path.Combine(_basePath, string.Format(@"region\r.{0}.{1}.mca", rx, rz)); if (!File.Exists(filePath)) return _backEndGenerator.GenerateChunkColumn(new Vector2(X, Z)); using (var regionFile = File.OpenRead(filePath)) { var buffer = new byte[8192]; regionFile.Read(buffer, 0, 8192); var xi = (X%width); if (xi < 0) xi += 32; var zi = (Z%depth); if (zi < 0) zi += 32; var tableOffset = (xi + zi*width)*4; regionFile.Seek(tableOffset, SeekOrigin.Begin); var offsetBuffer = new byte[4]; regionFile.Read(offsetBuffer, 0, 3); Array.Reverse(offsetBuffer); var offset = BitConverter.ToInt32(offsetBuffer, 0) << 4; var length = regionFile.ReadByte(); //if (offset == 0 || length == 0) return _backEndGenerator.GenerateChunkColumn(new Vector2(X, Z)); if (offset == 0 || length == 0) { return _backEndGenerator.GenerateChunkColumn(new Vector2(X,Z)); } regionFile.Seek(offset, SeekOrigin.Begin); var waste = new byte[4]; regionFile.Read(waste, 0, 4); var compressionMode = regionFile.ReadByte(); var nbt = new NbtFile(); nbt.LoadFromStream(regionFile, NbtCompression.ZLib); var dataTag = nbt.RootTag["Level"]; var sections = dataTag["Sections"] as NbtList; var chunk = new ChunkColumn { X = X, Z = Z, BiomeId = dataTag["Biomes"].ByteArrayValue }; for (var i = 0; i < chunk.BiomeId.Length; i++) { if (chunk.BiomeId[i] > 22) chunk.BiomeId[i] = 0; } if (chunk.BiomeId.Length > 256) throw new Exception(); // This will turn into a full chunk column foreach (var sectionTag in sections) { var sy = sectionTag["Y"].ByteValue*16; var blocks = sectionTag["Blocks"].ByteArrayValue; var data = sectionTag["Data"].ByteArrayValue; var addTag = sectionTag["Add"]; var adddata = new byte[2048]; if (addTag != null) adddata = addTag.ByteArrayValue; var blockLight = sectionTag["BlockLight"].ByteArrayValue; var skyLight = sectionTag["SkyLight"].ByteArrayValue; 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 - _waterOffsetY; if (yi < 0 || yi >= 256) continue; var anvilIndex = y*16*16 + z*16 + x; var blockId = blocks[anvilIndex] + (Nibble4(adddata, anvilIndex) << 8); var b = BlockFactory.GetBlockById((ushort) blockId); b.Metadata = Nibble4(data, anvilIndex); chunk.SetBlock(x, yi, z, b); chunk.SetBlocklight(x, yi, z, Nibble4(blockLight, anvilIndex)); chunk.SetSkylight(x, yi, z, Nibble4(skyLight, anvilIndex)); } } } } var entities = dataTag["Entities"] as NbtList; var tileEntities = dataTag["TileEntities"] as NbtList; if (tileEntities != null) { foreach (var nbtTag in tileEntities) { var blockEntityTag = (NbtCompound)nbtTag; string entityId = blockEntityTag["id"].StringValue; int x = blockEntityTag["x"].IntValue; int y = blockEntityTag["y"].IntValue - _waterOffsetY; int z = blockEntityTag["z"].IntValue; blockEntityTag["y"] = new NbtInt("y", y); TileEntity blockEntity = TileEntityFactory.GetBlockEntityById(entityId); if (blockEntity != null) { blockEntityTag.Name = string.Empty; chunk.SetBlockEntity(new Vector3(x, y, z), blockEntityTag); } } } var tileTicks = dataTag["TileTicks"] as NbtList; chunk.IsDirty = false; return chunk; } }
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 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()); }
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); } } } } }
protected void GenerateTopper(ChunkColumn chunk, Vector3 location, byte type = 0x0) { var sectionRadius = 1; GenerateCircle(chunk, location, sectionRadius, new Block(18) {Metadata = 1}); var top = location + new Vector3(0, 1, 0); var x = (int) location.X; var y = (int) location.Y + 1; var z = (int) location.Z; chunk.SetBlock(x, y, z, new Block(18) {Metadata = 1}); if (type == 0x1 && y < 256) GenerateVanillaCircle(chunk, new Vector3(x, y, z), sectionRadius, new Block(18) {Metadata = 1}); }
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); } } } } }