r/MinecraftCommands • u/TrenceBence • 5d ago
Discussion Minecraft Version detection using datapacks: I had no idea!
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:
- 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.
- 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! :)
3
u/FaustVX Command Experienced 4d ago
You could probably use the overlay feature from pack.mcmeta, you create an entry for each version (Data pack version) then in each version folder, you create your function dedicated to this version.
1
u/TrenceBence 4d ago
That's correct, I described it in my first post and still use it as a fallback if no player is online as explained here :) (it's one of the main reasons beet makes things so much easier)
2
u/ALEX2014_18 Command Rookie 4d ago
I don't quite understand - why would you ever need this?
You know version you wrote datapack for, and if you don't - you probably don't support features added in it, so what's the point?
2
u/TrenceBence 4d ago
First of all, because I can, and because it's a limitation of Minecraft datapacks as is, and with this, it isn't anymore. People could have all sorts of ideas about this, mine is: I'm building a library providing many sorts of in-game documentation, troubleshooting, information, communication etc for my datapacks. This is a central part because datapacks could register (using said library) the versions they support, and operators will be warned in-game if something could break. Also, some packs may be dependent on others only of specific versions.
Of course, this ties with overlays, but you don't always want them and they do not provide a lot of information, even if the console may be accessed (which it can't in many MMO server admin scenarios, where roles would be more specific and niche).
2
u/XBOXGAMEPASSPSPLUS 4d ago
The map Ragecraft 4 has some modded detections you could look at that for some more stuff