Offroaders123 / NBTify

A library to read and write NBT files on the web!
http://npm.im/nbtify
MIT License
42 stars 5 forks source link

Modified UTF-8 (MUTF-8) #42

Open Offroaders123 opened 10 months ago

Offroaders123 commented 10 months ago

Tonight, we (Minecraft Manipulator) were discussing the NBT spec's use of the Java version of UTF-8, which is called MUTF-8, or Modified UTF-8. I have been meaning to look into the details about this and how it relates to NBT, so I'm glad that it came up in conversation again!

Found this JS implementation, which I will try to use for inspiration to add support for the format in NBTify, as it is inherent that strings will serialize correctly in the same fashion to how they do in the base game as well.

mutf-8 - GitHub What does it mean to say "Java Modified UTF-8 Encoding"? - Stack Overflow Modified UTF-8 - Wikipedia

Offroaders123 commented 5 months ago

I think we're nearly there! I'm leaning towards getting used to adding dependencies to the project, I haven't done that for modules I share yet. It was new initially to do that with my apps, but now I think I'm going to start doing it with my npm packages too.

Offroaders123 commented 2 months ago

Realized I hadn't closed this, it's now in the stable build on npm (I think it was sometime last week I published it), and the CDN is linked properly. We made it!! 🙂 🚀

Offroaders123 commented 1 month ago

Reopening this, as recently I just found out that exclusively Java Edition NBT uses MUTF-8 encoding for the format, with LCE and Bedrock using plain UTF-8 instead.

This makes things a bit more complex to deduce, especially since Java and LCE both use big endian (endianness is easy to detect because of the errors that occur in trying to read one as the other).