-
Notifications
You must be signed in to change notification settings - Fork 2
Developer API Serializers
ImIllusion edited this page Jul 21, 2023
·
2 revisions
A core feature of Cosmos is its ability to save and paste blocks at scale.
Cosmos does this by using the built-in Serializer system, which allows you implement your own pasting and saving logic, or just hooking into a custom plugin. The serializer is responsible for the serialization, deserialization, importing and pasting process of Templated Areas.
By default, Cosmos uses WorldEdit as its default serializer.
You can fetch, register and list serializers through the serializer registry:
CosmosPlugin cosmos = ...;
CosmosSerializerRegistry serializerRegistry = cosmos.getSerializerRegistry();
CosmosSerializer serializer = serializerRegistry.get("worldedit");
Assuming you have the dimensions and location of the area, you can use the CosmosSerializer#createArea
method:
CosmosSerializer serializer = ...;
Location center = ...;
int radius = 10;
Cuboid cuboid = new Cuboid(center, radius); // There are many constructors, use the one that's appropriate to your situation
serializer.createArea(cuboid, center).thenAccept(area -> { // This might be async
...
});
Making a serializer requires the creation of a few classes:
- The serializer class (Example)
- The templated area instance that's returned by the serializer (Example)
- The pasted area class that extends the TemplatedArea class, containing methods to reverse the pasting process (Example)
Once that's done, just register it.