Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Charset problem while recreating Minecraft servers.dat file #64

Open
Plugner opened this issue Sep 30, 2021 · 1 comment
Open

Charset problem while recreating Minecraft servers.dat file #64

Plugner opened this issue Sep 30, 2021 · 1 comment

Comments

@Plugner
Copy link

Plugner commented Sep 30, 2021

My code: {servers:[{name:Server,ip:"0.0.0.0"}]}
Minecraft Generated code: {servers:[{name:Servidor,ip:"0.0.0.0"}]}

My tests

        File f = new File("servers.dat");
        System.out.println(SNBTUtil.toSNBT(NBTUtil.read(f).getTag())); // Testing with the original file

        CompoundTag compoundTag = new CompoundTag();
        CompoundTag serversCT = new CompoundTag();

        ListTag<CompoundTag> servers = new ListTag<>(CompoundTag.class);

        CompoundTag server = new CompoundTag();
        server.putString("ip", "0.0.0.0");
        server.putString("name", "Server");

        servers.add(server);

        compoundTag.put("servers", servers);
        System.out.println(SNBTUtil.toSNBT(compoundTag)); // Testing with generated code
        NBTUtil.write(compoundTag, "output.dat");

But the binary is completely different:

MC Generated:
image

Generated by my code:
image

Thanks!

@Dotteex
Copy link

Dotteex commented Dec 27, 2021

I had the same problem as you and I found the solution. On Minecraft Wiki you can found, that servers.dat is stored as an uncompressed NBT file, but this NBT library automatically converts the output file into gzip, so you have to turn off the compression.

The last line should be like this:
NBTUtil.write(compoundTag, "output.dat", false);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants