Hi,
the mod I am working on downloads textures at runtime (used for Screen, not Items/Blocks ofc). This must be done in seperate threads, as otherwise the game freezes for the duration. Now, I have some experience with Multithreading, I know how to make things thread safe and all the basics you need to know for that. My goal is to use a Thread Pools like implementation, as there are multiple tasks todo (Download, Resize, Modify image entirely ...), and sometimes they need to be done in a specific order.
The main question would be: What to do when Minecraft shuts down. All the tasks are short, so ideally I would like to wait for them to finish, the task queue can just be discarded in that case. There are some tasks which I do not want to see interrupted in some circumstances (eg. while writing to a file). I dont know of any MC functionality that I can use to ensure that.
So I did some research and might go for a Shutdown Hook. This leads me to my 2nd question: Would it be bad practice in this specific scenario to have the shutdown hook thread just wait for the worker threads to finish (with a max wait time ofc)?
If there are better ways of accomplishing what I am trying to do, please let me know
Thanks!