Reading writing dat files

I’m under the impression that the data api can accomplish this but can’t find much info about the data api outside what’s in the docs. Can anyone give an example?

data api does not give raw access to .dat files.

However it DOES allow read and write to NBT data stores without direct access to minecraft classes.

You can save data to itemstacks, entities, tileentities, and lets you read data from blocksnapshots and events and stuff.

DataContainer is meant to be the abstraction of not only NBT, but also any other object-based storage, like JSON and HOCON.

OK. I have a working solution, just wanted to see if Sponge had something built in.

I mean it does, it’s just not in the form factor that you are requesting i.e. .dat files.

Well I’m toying with the level_sponge.dat for importing non sponge worlds so the form factor is important

While you’ll still have to write the object yourself, SpongeCommon has NbtTranslator while will create NBTTagCompound (the raw MC class) from a DataContainer and vice versa.

I noticed that when I was doing some research last night, but I’m not sure how to access SpongeCommon from my project

You just need to include it as a dependency in gradle/maven instead of SpongeAPI - but be aware this means your plugin would only work with Sponge version that use SpongeCommon (currently, SpongeForge and SpongeVanilla).

Actually that doesn’t work. There is an issue with the maven dependencies.

There is a PR to fix it, but i don’t think it has gone through yet…

What do you mean? Non sponge worlds should import fine into sponge. Sponge just uses mc world format and just adds data. It doesn’t actually change any base minecraft storage…

From my testing, Sponge will not detect worlds unless they a level_sponge.dat file in them.

Is this spongeforge or spongevanilla?

I know in spongeforge, Minecraft Forge is responsible for loading the world, and then sponge just adds its extra metadata. Spongevannilla might behave differently.

This is sounding like a bug more than anything. I would create an issue or make a pull request.

SpongeForge. I haven’t done any testing with SpongeVanilla. I assumed this was just the way it is, and was the reason people were requesting I add import support for my multi world plugin. Please don’t tell me all that work was for nothing

I would try to talk to one of the sponge devs about how world loading works.
Just putting a world into the world folder does not mean it will load. A plugin has to try and actually load it.
However once you load the world, Sponge SHOULD automatically add it’s own data. If it doesn’t, that is a bug.

I see. OK i just attempted the load a world and it did generate the data file and loaded but it didn’t generate a unique dimension id so it ended up unloading the default world due to id conflict.

You know, it would’ve been better to just start from the get go that SpongeForge doesn’t import old worlds if they were in the top directory (like how Bukkit structured worlds). This is an xy problem where you ask how to read/write to level_sponge.dat files, when in reality you just wanted to import old worlds into sponge. Submit the issue on github for SpongeForge and we’ll get to it very very soon.


Yeah probably but I read somewhere that bukkit worlds had to be imported through manual process which is why I didn’t ask. May have been an old thread or something.

I’ll give you a hint, although specific questions are easier to answer, it’s almost always good to just blurt out everything at once. Let the pros do the filtering for you.

Little addition:
A huge load of blurt doesn’t help, but a few sentences on what you’re trying to achieve and some things you already tried usually helps a whole lot.

1 Like