Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
There is no explicit chunk cache in MCS, because the entire cWorld is in fact a chunk cache.
If I were to write a plugin like this, I'd go about it this way:
- Install a post-generator hook that saves the entire chunk somewhere, and then processes it so that all the invisible blocks are ores.
- Install a player-digging hook that checks if the visibility has changed, and if so, restores the needed blocks from the "backup".
- In order to speed things up, I'd keep backups of the four chunks closest to the player loaded, so that the restoration process takes as little time as possible.
This will not be perfect, however, because the obfuscation cannot really process blocks on the chunk's edge - there is no neighbor data while generating. This could be worked around, if needed.
Posts: 681
Threads: 26
Joined: May 2014
Thanks: 112
Given 48 thank(s) in 37 post(s)
Okay, you need to explain this a little bit more in detail:
- Are all these hooks available or do I have to create one of them
- Where should I save the data to? in a file or in a variable
- What kind of IDE do you prefer for lua?
Posts: 681
Threads: 26
Joined: May 2014
Thanks: 112
Given 48 thank(s) in 37 post(s)
Why shouldn't I use HOOK_CHUNK_AVAILABLE? If I do so, the plugin can be also used on an existing server.
Also, is there a nice way of writing into a .schematic? What dataformat does it have?
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
You can use that hook, but you need to remember if the chunk has already been modified or not, otherwise you'll save the obfuscated chunk and re-obfuscate it, thus losing all its data.
Posts: 681
Threads: 26
Joined: May 2014
Thanks: 112
Given 48 thank(s) in 37 post(s)
Do you have an example of how I can convert multiple chunks into a cBlockArea object? And how can I calculate the global coordinate of a block using the chunks coords and the relx, rely of the block inside?
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
Why would you need multiple chunks? Store just one - after all, only one chunk comes through the generator / loader hook at a time. Use the incoming cChunkDesc, it has a ReadBlockArea function that can read a cBlockArea from that description, and cBlockArea has a direct function to write the contents to a .schematic file.
The Rel coords are just that - relative to the chunk. So AbsoluteX = ChunkX * 16 + RelX etc. Going the other way round is a bit more difficult, you need to use math.floor() for the division, otherwise the calculation is wrong for the negative coords.
Posts: 681
Threads: 26
Joined: May 2014
Thanks: 112
Given 48 thank(s) in 37 post(s)
Okay. This is exactly what I did. But at what time should I initialize the obfuscator? It keeps hanging up if I do it inside of the hook.
Posts: 6,485
Threads: 176
Joined: Jan 2012
Thanks: 131
Given 1074 thank(s) in 852 post(s)
What's "initialize the obfuscator"?
You should initialize the plugin normally - when it's loaded and its Initialize function called. And then you should obfuscate the chunk directly in cChunkDesc while processing the HOOK_CHUNK_GENERATED hook. You might need to optimize the obfuscating code, otherwise it might get slow and seem to have hanged.