Exemple #1
0
        public ChunkData Load(int x, int y)
        {
            var rand = new Random(seed + x + y * 1024);
            var chunk = new ChunkData(x, y, new byte[16 * 16 * 128]);
            for (int tx = 0; tx < 16; tx++) {
                for (int tz = 0; tz < 16; tz++) {
                    for (int ty = 0; ty < 1; ty++) {
                        chunk.SetBlock(tx, ty, tz, 1);
                    }
                    for (int ty = 1; ty < 3; ty++) {
                        if (rand.Next(10) <= 7) {
                            chunk.SetBlock(tx, ty, tz, 10);
                        } else {
                            chunk.SetBlock(tx, ty, tz, 1);
                        }
                    }

                    if (rand.Next(20) < 1) {
                        for (int ty = 0; ty < 128; ty++) {
                            chunk.SetBlock(tx, ty, tz, 8);
                        }
                    } else {
                        for (int ty = 64; ty < 100; ty++) {
                            chunk.SetBlock(tx, ty, tz, 8);
                        }
                    }

                    for (int ty = 100; ty < 101; ty++) {
                        if (rand.Next(10) <= 7)
                            chunk.SetBlock(tx, ty, tz, 2);
                    }

                    for (int ty = 0; ty < 128; ty++) {
                        var t = chunk.GetBlock(tx, ty, tz);
                        if (t == 0 || t == 10 || t == 8)
                            chunk.SkyLight.SetValue(tx, ty, tz, 15);
                        if (t == 10)
                            chunk.BlockLight.SetValue(tx, ty, tz, 15);
                    }
                }
            }
            return chunk;
        }
Exemple #2
0
        protected void DoSkyLight(ChunkData chunk, int x, int ystart, int z)
        {
            var tileX = chunk.X * 16 + x;
            var tileZ = chunk.Y * 16 + z;

            var height = chunk.GetHeight(x, z);

            // From where should we start calculating
            int newHeight = Math.Max(height, ystart);

            // We need to cast light through transparent blocks
            while (newHeight > 0 && Block.LightAbsorbs[chunk.GetBlock(x, newHeight - 1, z)] == 0)
                newHeight--;

            // Nothing changed, we don't need to calculate
            if (newHeight == height)
                return;

            chunk.SetHeight(x, z, newHeight);

            /* The new height is lower than the last, that means all the tiles
             * above are fully lit */
            if (newHeight < height) {
                for (int y = newHeight; y < height; y++) {
                    chunk.SkyLight.SetValue(x, y, z, 15);
                }
            } else if (newHeight > height) {
                ScheduleUpdate(LightType.Sky, new Box(tileX, height, tileZ, tileX, newHeight, tileZ));
                for (int y = height; y < newHeight; y++) {
                    chunk.SkyLight.SetValue(x, y, z, 0);
                }
            }
        }