Posts: 26
Threads: 8
Joined: Jun 2013
Thanks: 27
Given 3 thank(s) in 3 post(s)
07-06-2014, 02:22 AM
(This post was last modified: 01-02-2017, 08:55 PM by jimmis98.)
So...
When the season changes, the plugin will first change the biomes around all players in a radius, according to viewdistance. Then, using HOOK_CHUNK_AVAILABLE, it will change each chunk as it loads.
Just FYI, the biome changes are so that the client will show, for example, the grass differently, or it will snow, etc. I dont get why it will have to trigger chunk regeneration, though...
I am thinking of making it so that animals will have more chances not spawn, and so that monsters will have a chance to "double spawn".
Thank you all for your time. Beware, I am a noob, so it shall take some time to make it...
Again, thanks
Posts: 952
Threads: 16
Joined: May 2013
Thanks: 66
Given 105 thank(s) in 89 post(s)
Okay, it should be do-able once we get a function that enumerates through all available chunks that are already loaded.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
You cannot change the entire world at once, because the server would have to load all the chunks for the world and re-save them with the new biomes. You need to follow a different approach, you've already mentioned that - first change all the chunks around players and then change each chunk as soon as it gets loaded or generated by the server. Note that you can already keep track of the loaded chunks for each world, simply by using the chunk unloading and loading hooks to store the chunk coords in a table.
There will probably never be a proper API function to enumerate all the loaded chunks, because as soon as such a function call would return, the data could be invalid - another thread may unload the chunk or load another chunk. We could use callback-based API so that you can execute code for each chunk loaded, but in this plugin's case it could be too much of a performance hit.
Posts: 952
Threads: 16
Joined: May 2013
Thanks: 66
Given 105 thank(s) in 89 post(s)
Then how can one reliably get all currently loaded chunks? Will calculations based off the player's viewdistance work?
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1075 thank(s) in 852 post(s)
You cannot reliably get all loaded chunks. You either want the chunks loaded, and use the cWorld:ChunkStay() function to make sure they are loaded, or keep track of the chunks using the loading and unloading hooks - those are serialized so you're guaranteed that the chunks that you have in your list are loaded. This won't work well with plugin reloads, though.
Alright, making a callback to enumerate all loaded chunks sounds like a good idea in this context.