Hi everyone, as announced in my last post here I will write a bit about our recent core system rework, the colony manager.
Until now the colony manager was a singleton which provided the world with a list of colonies and also took care of the persistence of each colony.
To do this the colonies would get marked dirty on changes and the colony manager would detect that regularly and write the colonies to file for persistence. This system had three major flaws.
This made us reconsider and we decided to move the colony manager to a capability-based system.
Capabilities in the context of forge Minecraft mods are certain persistency units which can be appended to world elements as chunks, the world itself, players, etc...
Doing so involved a lot of work as you might imagine since every system which touched the colony manager somewhere would have to be adapted.
First of all, I enriched the IColony interface with the dimension to be able to use this information wherever I might need it.
I then created a new constant class where I'd move all previous colony manager constants.
Then I created the capability.
First by creating the constant in the main class.
Then by registering it on pre-init:
CapabilityManager.INSTANCE.register(IColonyManagerCapability.class, new IColonyManagerCapability.Storage(), IColonyManagerCapability.Impl::new);
And append it to the world.
It would consist of all required methods as creating, deleting and querying colonies.
As well as adding colonies, and getting information about the chunks which are missing to load yet.
Since colonies are now queried by world or dimension I had to adapt all colony manager calls.
Adapt all getColonies() calls to getAllColonies() to get them from multiple worlds.
The implementation would be in the same file and would have the data which previously the colony manager had and implement the methods of the interface.
The persistence would then be handled by the storage itself.
All that would also require a factory which sets these bits and pieces together.
Within the old colony manager, we'd be able to extract this information then and also adapt the methods required to query the colonies.
As getting the colony by world or dimension from the capability.
Or getting all colonies from all possible worlds.
Besides that, I created a new command to be able to load colony backups which was previously only done by using a backed up file and replacing the existing file with it.
It would be the load backup command for OPs only.
Which would get the colony id and the dimension.
And then call the backup handler.
Additionally, I created two new helper classes:
The chunk helper would help to reduce the size and complexity of the colony manager java class and englobe all code related to storing the colony claim within the chunks as well as retrieving it.
The backup handler would get the old backup related code from the colony manager and some new code related to loading the backups.
Where it would start by loading the world save dir to get compound of the file which matches the dimension and colony id.
Then it would check if the colony exists and load its backed up data or if not existing create a new one matching this data.
Finally, I also moved the structure load to init to be world independent.
Besides that, we changed the schematic folder to be world independent but server dependent.
Since players might want to build schematics in all worlds on the server.
https://github.com/ldtteam/minecolonies