Instances are what replace "worlds" from Minecraft vanilla, those are lightweight and should offer similar properties. There are multiple instances implementation, currently
SharedInstance(both are explained below)
All instances can be accessed by using the InstanceManager or by getting an entity instance
InstanceManager instanceManager = MinecraftServer.getInstanceManager()
Internally, the default Instance class have its own sets to store the entities in it, but all chunk based methods are abstract and meant to be implemented by a sub-class
"Container" here means that this is an instance that can store chunks. And as every instance, have its own sets of entities
You can create an
InstanceContainer instanceContainer = instanceManager.createInstanceContainer();
In order to have a valid world generation, you need to specify which
ChunkGeneratorthe instance should use, without it no chunk can be generated. (check here to make your own)
SharedInstanceneeds to have an
InstanceContainerlinked to it. The "Shared" means that this is an instance that takes all of its chunks from its parent instance container
What does it mean? That if you break or place a block to the instance container, the shared instance will also reflect the change (same if you place a block using the shared instance methods, changes will be reflected in the instance container and all of its shared instances)
You can create a
SharedInstance sharedInstance = instanceManager.createSharedInstance(instanceContainer);
You are able to create your own class extending
Instanceand add entities to it.
In this case, the only thing you need to be aware of is that all instances need to be registered manually in the instance manager.
This method is ONLY required if you instantiate your instance object manually,
InstanceManager#createSharedInstancealready register the instance internally.
It is also essential to notice that, by default, the chunks of the instance are only stored in memory. In order to have them stored in a persistent way, you need to serialize and deserialize them. Please check the Chunks management page for further information.
Minestom uses Anvil as its default world format, conveniently located in the
AnvilLoaderclass. Just put your world in the
worldfolder, and see it work :)
var instance = instanceManager.createInstanceContainer();
// Save all currently loaded chunks to the IChunkLoader