OpenMinecraft.InfdevHandler.AddLightSourceAt C# (CSharp) Method

AddLightSourceAt() private method

private AddLightSourceAt ( int _x, int _y, int _z, int strength ) : void
_x int
_y int
_z int
strength int
return void
        private void AddLightSourceAt(int _x, int _y, int _z, int strength)
        {
            Console.WriteLine("AddLightSourceAt(x={0},y={1},z={2},strength={3});", _x, _y, _z, strength);
            int written = 0;
            // 15 light
            // Loss of 1 light per block + STOP value
            // 15.5 block radius = 31 block diameter = 31 block bounding box
            for (int x = 0; x < (strength * 2) + 1; ++x)
            {
                for (int y = 0; y < (strength * 2) + 1; ++y)
                {
                    for (int z = 0; z < (strength * 2) + 1; ++z)
                    {
                        int absolute_x=x+strength+_x-1;
                        int absolute_y=y+strength+_y-1;
                        int absolute_z=z+strength+_z-1;

                        if (absolute_z < 0 || absolute_z > 128)
                            continue;

                        int d = Vector3i.Distance(new Vector3i(_x, _y, _z),new Vector3i(absolute_x, absolute_y, absolute_z));

                        byte block = GetBlockAt(absolute_x, absolute_y, absolute_z);
                        Block b = Blocks.Get(block);

                        int light = strength - d - b.Stop;
                        if (light < 0) light = 0;

                        // If we're not adding anything, go see if there's any blocks that will.
                        if (light == 0) continue;
                        
                        // If the current light value in this block is brighter than what we're putting in, don't bother.
                        byte blight = GetBlockLightAt(absolute_x, absolute_y, absolute_z);
                        if (blight >= light) continue;

                        // Yay, add shit.
                        SetBlockLightAt(absolute_x, absolute_y, absolute_z, (byte)light);
                        written++;
                    }
                }
            }
            //SaveAll();
            Console.WriteLine("{0} blocks lighted.", written);
        }