Minecolonies & Colonymanager rework

in #utopian-io6 years ago (edited)

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.

  • If the world would crash a colony could be written only partially to file which would make it fail to load on reading.
  • Regularly writing all colonies to file comes with a huge overhead.
  • Due to the centralization of this system, it would be difficult to maintain different colonies in different dimensions in a world.

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...

The Capability:

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.

In the old colony manager:

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.

New Command:

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:

  • Chunk helper
  • Backup helper

New Chunk Helper:

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:

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.

Extras:

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.

Repository:

https://github.com/ldtteam/minecolonies

Pull Requests:

https://github.com/ldtteam/minecolonies/pull/2900

Sort:  
  • I really like how your contributions posts read like a story, it's also very educational for me as we get to see your thought process going trough the rework.
  • Many changes of function names, they were everywhere!
  • Is this a legit comment from the codacy-bot?

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thanks for the review. While yes it is not threadsafe we do not access it from different threads since Minecraft is single threaded anyway.

Thank you for your review, @helo!

So far this week you've reviewed 1 contributions. Keep up the good work!

Hi @raycoms!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
Feel free to join our @steem-ua Discord server

Hi, @raycoms!

You just got a 36.51% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

Hey, @raycoms!

Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Get higher incentives and support Utopian.io!
Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via SteemPlus or Steeditor).

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.25
TRX 0.11
JST 0.032
BTC 62710.59
ETH 3048.49
USDT 1.00
SBD 3.77