Fact: In the Goodfellas, the scene was never meant to be in the actual film. Joe Pesci acted out the scene to Martin Scorsese. The line was based off of real-life events.
The Goodfellas 1990 is regarded as one of the best mobster movies of all time. It contained some of the best actors including Robert De Niro, Joe Pesci, Ray Liotta, Paul Sorvino, and Frank Vincent. The film was based off of the real-life portrayal of Henry Hill. Henry Hill was an FBI informant whose life was immortalized by the movie (he idolized local mafiosos, such as Paul Vario, a capo in the Luchesse crime family). Hill stated that Joe Pesci’s portrayal of Tommy DeSimone was 90-99% accurate, with one notable exception; ‘the real Tommy DeSimone was a massively built, strapping man.’
The “You Think I’m Funny?” scene was based off of Joe Pesci’s real life when he worked in a restaurant as a young man. Pesci told a mobster that he was funny. From the quote, the mobster wasn’t very happy and became angry. When asked at the 25th Anniversary Tribeca Film Festival, Ray Liotta recalled how the scene arose:
“And Joe was telling me a story about what happened to him in Queens or wherever it was and he said to some guy … the guy said something who happened to be a connected guy and he said ‘Well … you think I’m funny?'” – Business Insider
That is how that quote came about. While Pesci isn’t associated with the mafia himself, he was heavily influenced in his life. Scorsese loved the story so much, he added it to the script. In shooting the scene to which the line would carry life, Scorsese allowed Pesci and Ray Liotta to improvise the scene. He did not tell the other actors in the scene what would happen because he wanted their genuine surprised reactions (IMDB). Scorsese was so anal about the actor’s wardrobe that he tied Ray Liotta’s tie himself to make sure it was accurate for the film’s setting.
When asked about how the improvisation acted out, Pesci was very succinct about what was meant by improvisation and acting:
“You don’t improvise on camera when we’re shooting, they all think that Marty [Scorsese] doesn’t do anything, that he lets the actors say ‘Okay, go ahead’ and enjoys it. It’s not true. It’s crazy to think you can go in there and make a movie like that. It has to be structured.”
During around the time of shooting this scene, Ray Liotta’s mother passes away of cancer. Liotta explains that he uses the anger over losing his mother in specific scenes, like the pistol-whipping scene.