Skip to content

Support for re-creating persistent worlds #33

@LCLPYT

Description

@LCLPYT

The problem

Currently, if you want to load a previously created persistent world, you have to use Fantasy::getOrOpenPersistentWorld.
The method obviously requires you to pass a dimension type and chunk generator via a RuntimeWorldConfig.
If you created the world with a custom generator, you will have to memorize it somehow.
That creates an unnecessary overhead for the developer IMO.

Use case

I personally create worlds for minigames in single player.
Often, I change the generator options, such as the dimension type or the chunk generator in the level.dat.

On my minigame server, I copy the level save into the dimensions directory, every time the game starts.
I would like to load the map as dimension using the fantasy library.
Then, I have to re-create the generator options by hand in Java, for each individual map.
In my case, an API would surely be helpful.

Potential solution

I think there should be an API method on the Fantasy class, such as openPersistentWorld(Identifier) in order to open worlds inside the dimensions/ directory of the currently loaded save.
The method needs to somehow re-construct the RuntimeWorldConfig, the world was created with.

For this to work, fantasy would also need to save the config/the generator data to disk on persistent world creation.

Implementation details

My proposal would be to check whether there is a level.dat file in the directory of the dimension that should be loaded.
If it exists, the code from net.minecraft.world.level.storage.LevelStorage#createLevelDataParser can be used to parse it.

This way, users could also put worlds they created in singleplayer / another world into the dimensions folder of the desired save (my use case).

As for writing the level.dat, one could use net.minecraft.world.level.storage.LevelStorage.Session#backupLevelDataFile().

Maybe there are even better ways to save and load the world data, I am not sure...

Sample implementation

I implemented the level.dat parsing and config re-creation as proof of concept in one of my libraries.
If you like the approach, I would be happy to create a pull request providing the feature to fantasy.
Please let me know, if the concept / the implementation is to your liking.

I am still working on the leve.dat creation when creating a persistent world. So it can only be tested with other saves ATM.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions