|
| 1 | +# Polar Loader |
| 2 | + |
| 3 | +::: warning |
| 4 | +Polar is an external library made by [Hollow Cube](https://github.com/hollow-cube/). External libraries have no obligation to be updated alongside Minestom and may go stale in the future. |
| 5 | +::: |
| 6 | + |
| 7 | +[Polar](https://github.com/hollow-cube/polar) is a format made by Hollow Cube, designed to store large amounts of user-generated instances. Polar has numerous benefits over Anvil, like being stored in a single file and supporting zstd compression. However, it is not the best option in many use cases. |
| 8 | + |
| 9 | +Custom data provided by the server can also be stored in Polar files alongside chunk data, more information about this can be found in the [README](https://github.com/hollow-cube/polar/tree/main?tab=readme-ov-file#user-data--callbacks). |
| 10 | + |
| 11 | +## Requirements |
| 12 | + |
| 13 | +Polar requires a world in the Polar format, of course. The library ships with an Anvil conversion utility found in the `AnvilPolar` class. You may also opt to create your worlds using Minestom to be saved straight into Polar. |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +Polar can be found on Maven Central, so no repositories are required on top of Minestom's. |
| 18 | + |
| 19 | +:::tabs |
| 20 | +== Gradle (Groovy) |
| 21 | + |
| 22 | +```groovy-vue |
| 23 | +dependencies { |
| 24 | + implementation 'dev.hollowcube:polar:<see releases>' |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +== Gradle (Kotlin) |
| 29 | + |
| 30 | +```kotlin-vue |
| 31 | +dependencies { |
| 32 | + implementation("dev.hollowcube:polar:<see releases>") |
| 33 | +} |
| 34 | +``` |
| 35 | + |
| 36 | +== Maven |
| 37 | + |
| 38 | +```xml-vue |
| 39 | +<dependencies> |
| 40 | + <dependency> |
| 41 | + <groupId>dev.hollowcube</groupId> |
| 42 | + <artifactId>polar</artifactId> |
| 43 | + <version>see releases</version> |
| 44 | + </dependency> |
| 45 | +</dependencies> |
| 46 | +``` |
| 47 | +::: |
| 48 | + |
| 49 | +### Direct |
| 50 | + |
| 51 | +```java |
| 52 | +final Path file = this.worlds.join("world.polar"); |
| 53 | +final PolarLoader loader = new PolarLoader(file); // can also take an InputStream |
| 54 | +final InstanceContainer instance = MinecraftServer.getInstanceManager().createInstanceContainer(loader); |
| 55 | +``` |
| 56 | + |
| 57 | +### Streaming |
| 58 | + |
| 59 | +Loads a polar world into an instance in a streaming manner. This method significantly reduces the memory overhead of loading a world and should generally be preferrable. |
| 60 | + |
| 61 | +```java |
| 62 | +final Path file = this.worlds.join("world.polar"); |
| 63 | +final FileChannel channel = FileChannel.open(file, StandardOpenOption.READ); |
| 64 | +final InstanceContainer instance = MinecraftServer.getInstanceManager().createInstanceContainer(); |
| 65 | +final CompletableFuture<Void> future = PolarLoader.streamLoad(instance, channel, channel.size(), null, null, true); |
| 66 | +``` |
0 commit comments