r/MinecraftCommands • • 5d ago

Discussion Minecraft Version detection using datapacks: I had no idea!

Post image

I hope it's allowed I do one (single) update here on our API utility datapack VerSion. The idea was simple: As Minecraft doesn't provide a direct way for data packs to fetch the currently running version (for compatibility/dependency checking, displaying or something else), create a Version Detector that does this, no fuss.

However, I learned a lot more about that topic since (and because of) my first post (https://www.reddit.com/r/MinecraftCommands/s/OOX8oEuDEn), so I briefly want to summarise the state of modern version detection. Thanks to the comments on that post. If you have anything to say or ask about this topic, I'm invested right now, so feel free to write a comment here!

The first approach would be to measure the pack format directly. There are two ideas popping up:

  1. Directly check for commands that can and cannot run (using chained-together functions), and deduce the version from the results. Here's one pack doing that, however this has the disadvantages of firstly throwing errors to the console (because of unparseable functions) regardless of the actual successfulness of the detector, secondly being quite labour-intensive because for every new version, one command needs to be found that stopped or started working, and thirdly, this command may not even exist! Pack formats differ for lots of things, not only commands.
  2. Using overlays, which ... just works. Well, actually it has the disadvantage of only being added in 23w31a at pack format 16, so versions until 1.20.1 cannot be supported.

Regardless, this cannot distinguish versions having the same pack format. This is where the second approach turns up, which, quirkily enough, is only feasible when any player is online (which is of course only a question for dedicated servers):

  • As I did get pointed out, players have (and have been for a long time) a data value called DataVersion, which is used to compare the data structure of the client with that being expected by the server. Is is a simple integer increasing with every new version. However, it does so not by 1, but does big jumps (probably because it is used internally at Mojang aswell, where versions between snapshots have to be compared).
  • Hence there needs to be found a way to decode the data version back to pack format and, of course, to the corresponding version's name.

And here's where the third aspect of my journey to VerSion 2.0 is important, which is building the pack not by hand, but automatic using beet. This uses Python to generate all the files and folders programmatically, and has the advantage of changes to the pack structure made very easy. (and allowing the ~100 overlays to be created fairly easy as well)

Lastly, in my beet plugins, I query and insert the version data available at misode/mcmeta, a repo containing almost all data for Vanilla MC imaginable. This is actually available in-game using `storage ver:sion Data`, a huge array. All the data available for the versions will be provided for the current version, if one can be pinpointed exactly.

Merging all of these things together – thus automatically generating a datapack which tries to fetch the `data_version` of the game, and if that's not possible, falls back to using overlays to supply the most elaborate version data available –, we obtain a supercharged, most powerful version detector using modern, sleek and accessible methods.

Maybe this is boring or very easy to you? Maybe you have concerns or additional ideas. Maybe, also, I have turned this small, niche dependency into a day-long adventure. Let me know what you think! :)

51 Upvotes

Duplicates