Minecolonies & Chunkloading
utopian-io·@raycoms·
0.000 HBDMinecolonies & Chunkloading
Current Situation: --- In a previous update a few months ago we changed round colonies to square colonies. We changed this since round colonies were difficult to calculate (since in Minecraft everything is blocky) and it required us to run through the list of all colonies to find the colony a certain block belongs to. In the approach we had developed we added a Capability (Extra Storage) to a Chunk (16x16 blocks). This capability would tell a player on a chunk to which colony the chunk belongs and if the chunk is proper to create a colony. There is only one downside to this approach: - We have to load all chunks of a colony to add the data to then. Which can put a lot of load on the server (A colony can easily span over a few thousand chunks), therefore, we created a file-system which holds all chunkdata and which we were able to query if we have the correct identifier. > Which was like x_y_dimension.nbt While this worked out, it created a decent amount of IO load and wasn't really secure. Therefore, We adapted this system in the current pull request. New Approach: --- We now create a capability on the World (meaning each dimension). To do this we need to: 1) Attach it to the world:  2) Register it at the right place: ``` @Mod.EventHandler public void preInit(@NotNull final FMLPreInitializationEvent event) { CapabilityManager.INSTANCE.register(IChunkmanagerCapability.class, new IChunkmanagerCapability.Storage(), IChunkmanagerCapability.Impl::new); } ``` 3) Make it mod wide available:  4) Create an interface, implementation, and storage.  We create an interface which has the possibility to query the map, add a storage object and get a storage object. Then, in the inner class, we defined the implementation  Which holds the map of ChunkPos and ChunkLoadStorage (the colony info).  And, finally, we added an inner storage class which takes care of serializing and deserializing from and to NBT for persistence. (If you heck out the registering you'll be able to see that we define all three locations on registering). 5) And finally we create a provider which defines which methods are responsible for what:  How we use it: --- Now, when we load a chunk we get the world capability,  then, we ask it if it has the chunkData, and if so, we apply it to the chunk.  Also, when we want to get the colony info of a specific chunk, we should check also if the world storage has info about it.  Which, happens rarely, since we preload the chunks on loading, but, in some rare occasions players could try to build things in unloaded chunks to grief others, that's why I added it. Also, to load the data in, I created a method which goes through the existing files, parses them, adds them to the capability and then deletes them.  > The bit-shifting was required since we stored the position only in the name of in a long (two ints can be hidden in a long). But, extracting it from the long was more efficient. Additional fix: --- Additionally, previously when placing a colony all chunks were loaded already, so players had to walk into the chunks to load the data (which caused quite some confusion). That's why we preload the data of 5 chunks now.  Basically, we check if the block is loaded, we get the chunk, we get the capability of the chunk, and then we add the capability to the chunk and notify the client (We have to differentiate between adding and deleting). This was something I wanted to do for quite a while now and which also, in the end, delayed the release of higher level releases (beta and releases) since we were only releasing alphas for the last months due to this. I hope this will improve the performance and the stability of the mod further and I'll see you the next time. Pull Request: https://github.com/ldtteam/minecolonies/pull/2583
👍 ubg, faisalrizal2018, reggaemuffin, share4every1, taukproung85, tpvoter1, steemitstats, helo, zcool, razzel, clemys, steembusiness, furious-one, derasmo, r351574nc3, ruel.cedeno, loshcat, greenorange, fuzzythumb, liberviarum, kujou, ratticus, davinci.times, alexzicky, doughtaker, jrawsthorne, techtek, achiron, amosbastian, electronicsworld, tdre, pataty69, fplacido, micaelacf, duarte9sousa, isabelpereira, aniellopas, utopian-io, gamersservice, azulear, alex-steem-it, fireruner, reno7, rahmanshaikat, sucemabite, poustackiev,