Skip to content

Commit 900faf2

Browse files
committed
feat: add sections on world loading
1 parent 232e9e3 commit 900faf2

File tree

5 files changed

+122
-24
lines changed

5 files changed

+122
-24
lines changed

.vitepress/config.mts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,18 @@ export default defineConfig({
7878
text: "World",
7979
items: [
8080
{ text: "Instances", link: "/docs/world/instances" },
81+
{
82+
text: "Loading",
83+
link: "/docs/world/loading",
84+
items: [
85+
{ text: "Anvil", link: "/docs/world/loading/anvil" },
86+
{ text: "Polar", link: "/docs/world/loading/polar" },
87+
],
88+
},
8189
{
8290
text: "Chunk Management",
8391
link: "/docs/world/chunk-management",
8492
items: [
85-
{ text: "Anvil Loader", link: "/docs/world/anvilloader" },
8693
{ text: "Lighting", link: "/docs/world/lightloader" },
8794
],
8895
},

docs/world/anvilloader.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

docs/world/loading.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# World Loading
2+
3+
In order to load or save an [`Instance`](https://javadoc.minestom.net/net/minestom/server/instance/Instance.html), you must provide an [`IChunkLoader`](https://javadoc.minestom.net/net/minestom/server/instance/IChunkLoader.html) that Minestom will use to read and write chunk data to and from.
4+
5+
When creating your instance, you can provide the loader in multiple ways:
6+
* [`InstanceManager#createInstanceContainer(@Nullable IChunkLoader)`](https://javadoc.minestom.net/net/minestom/server/instance/InstanceManager.html#createInstanceContainer(net.minestom.server.instance.IChunkLoader))
7+
* [`InstanceManager#createInstanceContainer(RegistryKey<DimensionType>, @Nullable IChunkLoader)`](https://javadoc.minestom.net/net/minestom/server/instance/InstanceManager.html#createInstanceContainer(net.minestom.server.instance.IChunkLoader))
8+
* [`InstanceContainer#setChunkLoader(IChunkLoader)`](https://javadoc.minestom.net/net/minestom/server/instance/InstanceContainer.html#setChunkLoader(net.minestom.server.instance.IChunkLoader))
9+
10+
Minestom will automatically load chunks from the loader once provided.
11+
12+
## Saving
13+
14+
Saving must be done in two steps:
15+
1. [`Instance#saveChunksToStorage`](https://javadoc.minestom.net/net/minestom/server/instance/Instance.html#saveChunksToStorage())
16+
2. [`Instance#saveInstance`](https://javadoc.minestom.net/net/minestom/server/instance/Instance.html#saveInstance())
17+
18+
```java
19+
MinecraftServer.getSchedulerManager().buildShutdownTask(() -> {
20+
this.instance.saveChunksToStorage();
21+
this.instance.saveInstance();
22+
});
23+
```
24+
25+
## Loaders
26+
27+
* [No-op](https://javadoc.minestom.net/net/minestom/server/instance/IChunkLoader.html#noop())
28+
* [Anvil](/docs/world/loading/anvil.md)
29+
* [Polar](/docs/world/loading/polar.md)

docs/world/loading/anvil.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Anvil Loader
2+
3+
Anvil is the format made by Mojang for vanilla. Minestom provides this format and it is chosen **by default** on newly created instances. Anvil is a multi-file world format, so must be provided with a directory to store world data. The anvil loader also supports reading light data from the worlds, this is enabled by default.
4+
5+
## Requirements
6+
7+
Worlds to be used with [`AnvilLoader`](https://javadoc.minestom.net/net/minestom/server/instance/anvil/AnvilLoader.html) only need to contain the `region` directory, which is where the chunk data comes from. Chunk loaders do not read entity data.
8+
9+
## Usage
10+
11+
To use a world from the **runtime file system**, you can do something like the following code snippet, which constructs the loader using [`AnvilLoader#<init>(Path)`](https://javadoc.minestom.net/net/minestom/server/instance/anvil/AnvilLoader.html#%3Cinit%3E(java.nio.file.Path)).
12+
13+
```java
14+
final Path directory = this.worlds.join("world");
15+
final AnvilLoader loader = new AnvilLoader(directory);
16+
final InstanceContainer instance = MinecraftServer.getInstanceManager().createInstanceContainer(loader);
17+
```
18+
19+
Remember, however, that this **does not** read from the jar resources. Other war crimes must be committed for this to happen.

docs/world/loading/polar.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)