fCraft.Firework.PerformInternal C# (CSharp) Method

PerformInternal() protected method

protected PerformInternal ( ) : int
return int
        protected override int PerformInternal()
        {
            lock ( _world.SyncRoot ) {
                if ( _world.fireworkPhysics ) {
                    if ( _world.Map.GetBlock( _pos.X, _pos.Y, _z ) != Block.Air || _count >= _height ) {
                        _world.Map.QueueUpdate( new BlockUpdate( null, ( short )_pos.X, ( short )_pos.Y, ( short )( _z - 1 ), Block.Air ) );
                        if ( _world.Map.GetBlock( _pos.X, _pos.Y, _z - 2 ) == Block.Lava ) {
                            _world.Map.QueueUpdate( new BlockUpdate( null, ( short )_pos.X, ( short )_pos.Y, ( short )( _z - 2 ), Block.Air ) );
                        }

                        Random rand = new Random();
                        int blockId = new Random().Next( 1, 9 );
                        Block fBlock = new Block();
                        if ( blockId <= 6 ) {
                            fBlock = ( Block )rand.Next( 21, 33 );
                        }
                        for ( int X2 = _pos.X - 5; X2 <= _pos.X + 5; X2++ ) {
                            for ( int Y2 = ( _pos.Y - 5 ); Y2 <= ( _pos.Y + 5 ); Y2++ ) {
                                for ( int Z2 = ( _z - 5 ); Z2 <= ( _z + 5 ); Z2++ ) {
                                    if ( blockId >= 7 ) {
                                        fBlock = ( Block )rand.Next( 21, 33 );
                                    }
                                    if ( rand.Next( 1, 50 ) < 3 ) {
                                        _world.AddPhysicsTask( new FireworkParticle( _world, new Vector3I( X2, Y2, Z2 ), fBlock ), rand.Next( 1, 100 ) );
                                    }
                                }
                            }
                        }
                        _world.FireworkCount--;
                        return 0;
                    }
                    if ( _notSent ) {
                        if ( _world.Map.GetBlock( _pos ) != Block.Gold ) {
                            _world.FireworkCount--;
                            return 0;
                        }
                    }
                    _notSent = false;
                    _world.Map.QueueUpdate( new BlockUpdate( null, ( short )_pos.X, ( short )_pos.Y, ( short )_z, Block.Gold ) );
                    _world.Map.QueueUpdate( new BlockUpdate( null, ( short )_pos.X, ( short )_pos.Y, ( short )( _z - 1 ), Block.Lava ) );
                    if ( _world.Map.GetBlock( _pos.X, _pos.Y, _z - 2 ) == Block.Lava ) {
                        _world.Map.QueueUpdate( new BlockUpdate( null, ( short )_pos.X, ( short )_pos.Y, ( short )( _z - 2 ), Block.Air ) );
                    }
                    _z++;
                    _count++;
                    return Delay;
                }
            }
            _world.FireworkCount--;
            return 0;
        }