Unfortunately I have not been able to replicate it again and even if I did I am not sure if it would do much good. Instead I have just stopped using optifine and the problem was solved. I think that chunk loading with optifine is messed up and I was flying into unloaded chunks because when I broke a flower the item would not drop. Thank you anyway.
I now have a similar issue in my single player survival world, I get stuck in flying mode and then when I try to relog, I get stuck in the saving world screen
I just replicated the problem, it was even in the same general area that it happened before, I was flying to my base to pick some stuff up and hit the ground in flying mode then bounced up and got stuck in fly mode. Then I logged out and Minecraft is now stuck yet again on the "Saving world" screen and like before I cannot close out of the application.
I ended up restarting the computer. This seems to have solved the problem temporarily and all progress was saved up until the last auto-save. If anyone else has a similar problem I would only use this as a last resort.
If I do manage to replicate it though, I will try getting screenshots.