Beispiel #1
0
        private static int GetHigestSurrounding(int x, int z, ChunkColumn chunk, World level)
        {
            int h = chunk.GetHeight(x, z);

            if (h == 127)
            {
                return(h);
            }

            if (x == 0 || x == 15 || z == 0 || z == 15)
            {
                var coords = new BlockCoordinates(x + (chunk.x * 16), h, z + (chunk.z * 16));

                h = Math.Max(h, level.GetHeight(coords + BlockCoordinates.Up));
                h = Math.Max(h, level.GetHeight(coords + BlockCoordinates.West));
                h = Math.Max(h, level.GetHeight(coords + BlockCoordinates.East));
                h = Math.Max(h, level.GetHeight(coords + BlockCoordinates.North));
                h = Math.Max(h, level.GetHeight(coords + BlockCoordinates.South));
                if (h > 127)
                {
                    h = 127;
                }
                if (h < 0)
                {
                    h = 0;
                }
                return(h);
            }

            //if (z < 15) h = Math.Max(h, chunk.GetHeight(x, z + 1));
            //if (z > 0) h = Math.Max(h, chunk.GetHeight(x, z - 1));
            //if (x < 15) h = Math.Max(h, chunk.GetHeight(x + 1, z));
            //if (x < 15 && z > 0) h = Math.Max(h, chunk.GetHeight(x + 1, z - 1));
            //if (x < 15 && z < 15) h = Math.Max(h, chunk.GetHeight(x + 1, z + 1));
            //if (x > 0) h = Math.Max(h, chunk.GetHeight(x - 1, z));
            //if (x > 0 && z > 0) h = Math.Max(h, chunk.GetHeight(x - 1, z - 1));
            //if (x > 0 && z < 15) h = Math.Max(h, chunk.GetHeight(x - 1, z + 1));

            h = Math.Max(h, chunk.GetHeight(x, z + 1));
            h = Math.Max(h, chunk.GetHeight(x, z - 1));
            h = Math.Max(h, chunk.GetHeight(x + 1, z));
            h = Math.Max(h, chunk.GetHeight(x + 1, z - 1));
            h = Math.Max(h, chunk.GetHeight(x + 1, z + 1));
            h = Math.Max(h, chunk.GetHeight(x - 1, z));
            h = Math.Max(h, chunk.GetHeight(x - 1, z - 1));
            h = Math.Max(h, chunk.GetHeight(x - 1, z + 1));

            return(h);
        }
Beispiel #2
0
        public int GetHeight(BlockCoordinates coordinates)
        {
            ChunkColumn chunk = GetChunk(coordinates, true);

            if (chunk == null)
            {
                return(_heightForUnloadedChunk);
            }

            return(chunk.GetHeight(coordinates.X & 0x0f, coordinates.Z & 0x0f));
        }
Beispiel #3
0
        public int GetHeight(BlockCoordinates blockCoordinates)
        {
            ChunkColumn chunk = GetChunk(blockCoordinates);

            if (chunk == null)
            {
                return(256);
            }

            return(chunk.GetHeight(blockCoordinates.X & 0x0f, blockCoordinates.Z & 0x0f));
        }
        private static Task GenerateHeightmap(ChunkColumn[] columns, int chunks, bool chunkHeight)
        {
            return(Task.Run(() =>
            {
                Bitmap bitmap = new Bitmap(chunks * 16, chunks * 16);
                for (int x = 0; x < chunks; x++)
                {
                    for (int z = 0; z < chunks; z++)
                    {
                        ChunkColumn column = columns[(x * chunks) + z];
                        for (int cx = 0; cx < 16; cx++)
                        {
                            var rx = (x * 16) + cx;
                            for (int cz = 0; cz < 16; cz++)
                            {
                                var rz = (z * 16) + cz;

                                //  var height = column.GetHeight(cx, cz);
                                //  var temp = (int) Math.Max((byte)0,
                                //     Math.Min((byte)255, height));

                                var height = 0;

                                if (!chunkHeight)
                                {
                                    height = column.GetHeight(cx, cz);
                                }
                                else
                                {
                                    var biome = BiomeUtils.GetBiomeById(column.GetBiome(cx, cz));
                                    height = (int)Math.Max(0,
                                                           Math.Min(255, (255 * MathUtils.ConvertRange(-2f, 2f, 0f, 1f, ((biome.MinHeight + biome.MaxHeight) / 2f)))));
                                }

                                bitmap.SetPixel(rx, rz, Color.FromArgb(height, height, height));
                            }
                        }
                    }
                }

                bitmap.Save(chunkHeight ? "chunkHeight.png" : "height.png", ImageFormat.Png);
            }));
        }
        public void Calculate(ChunkColumn chunk, ChunkCoordinates chunkCoordinates)
        {
            var cx = (chunkCoordinates.X << 4);
            var cz = (chunkCoordinates.Z << 4);

            for (int x = 0; x < 16; x++)
            {
                var rx = cx + x;
                for (int z = 0; z < 16; z++)
                {
                    var rz     = cz + z;
                    int height = chunk.GetHeight(x, z);

                    for (int y = height; y < 255; y++)
                    {
                        Process(chunk, rx, height, rz);
                        //Process(chunk, x, y, z);
                    }
                }
            }
        }
Beispiel #6
0
        private BlockColumnMeta GetColumnMeta(ChunkColumn chunk, int x, int z)
        {
            var pos = new BlockPosition((chunk.x << 4) + x, (chunk.z << 4) + z);

            var y = chunk.GetHeight(x, z);
            //var highestBlock = Level.GetBlock(pos.X, y, pos.Z);
            var highestBlock = GetHighestBlock(pos.X, pos.Z);

            if (highestBlock == null)
            {
                return(new BlockColumnMeta()
                {
                    Position = pos,
                    Height = 0,
                    BiomeId = 0,
                    BlockId = 0,
                    LightLevel = 0
                });
            }

            //_skyLightCalculations.Calculate(Level, highestBlock);

            //if (highestBlock.LightLevel > 0)
            //{
            //    BlockLightCalculations.Calculate(Level, highestBlock);
            //}

            return(new BlockColumnMeta()
            {
                Position = pos,
                Height = (byte)highestBlock.Coordinates.Y,
                BiomeId = highestBlock.BiomeId,
                BlockId = highestBlock.Id,
                LightLevel = chunk.GetSkylight(x, y, z)
            });
        }
Beispiel #7
0
        public static void ResetBlocks(Level level, BoundingBox bbox, bool repopulate = false)
        {
            bbox = bbox.GetAdjustedBoundingBox();
            ChunkColumn chunk = null;
            Dictionary <ChunkCoordinates, ChunkColumn> chunks = new Dictionary <ChunkCoordinates, ChunkColumn>();

            for (int x = (int)bbox.Min.X; x < (int)bbox.Max.X + 1; x++)
            {
                for (int z = (int)bbox.Min.Z; z < (int)bbox.Max.Z + 1; z++)
                {
                    var blockCoord = new BlockCoordinates(x, 0, z);
                    ChunkCoordinates chunkCoordinates = (ChunkCoordinates)blockCoord;
                    if (chunk == null || chunk.X != chunkCoordinates.X || chunk.Z != chunkCoordinates.Z)
                    {
                        if (!chunks.TryGetValue(chunkCoordinates, out chunk))
                        {
                            chunk = level.GetChunk(chunkCoordinates, true);
                            chunks[chunkCoordinates] = chunk;
                        }
                    }

                    level.SetBiomeId(blockCoord, 1);
                    int height = 255;
                    if (chunk != null)
                    {
                        height = chunk.GetHeight(blockCoord.X & 0x0f, blockCoord.Z & 0x0f);
                    }

                    for (int y = 0; y < 256; y++)
                    {
                        if (y == 0)
                        {
                            var block = new Bedrock {
                                Coordinates = new BlockCoordinates(x, y, z)
                            };
                            level.SetBlock(block, applyPhysics: false, calculateLight: false, possibleChunk: chunk);                             // Bedrock
                        }
                        else if (repopulate && y == PlotHeight)
                        {
                            var block = PlotPattern.Next(new BlockCoordinates(x, PlotHeight, z));
                            level.SetBlock(block, applyPhysics: false, calculateLight: false, possibleChunk: chunk);                             // grass
                        }
                        else if (y >= PlotHeight)
                        {
                            if (y <= height || !level.IsAir(new BlockCoordinates(x, y, z)))
                            {
                                var block = new Air {
                                    Coordinates = new BlockCoordinates(x, y, z)
                                };
                                level.SetBlock(block, applyPhysics: false, calculateLight: false, possibleChunk: chunk);                                 // air
                            }
                        }
                        else if (y == PlotHeight - 1)
                        {
                            var block = new Grass {
                                Coordinates = new BlockCoordinates(x, y, z)
                            };
                            level.SetBlock(block, applyPhysics: false, calculateLight: false, possibleChunk: chunk);                             // grass
                        }
                        else if (y > PlotHeight - 4)
                        {
                            var block = new Dirt {
                                Coordinates = new BlockCoordinates(x, y, z)
                            };
                            level.SetBlock(block, applyPhysics: false, calculateLight: false, possibleChunk: chunk);                             // dirt
                        }
                        else
                        {
                            var block = new Stone {
                                Coordinates = new BlockCoordinates(x, y, z)
                            };
                            level.SetBlock(block, applyPhysics: false, calculateLight: false, possibleChunk: chunk);                             // stone
                        }
                    }
                }
            }
        }