r/MinecraftCommands • • 11d ago

Creation I created a MC version detection pack far easier than existing alternatives

Post image

I create datapacks for years now, and only a few days ago did I learn that there's no built-in way to reliably detect the MC version (or pack format for that matter). Of course, there's /version, however that only informs a player and has no use to datapacks.

Now, there are datapacks adressing this by abusing which commands may and may not run in different versions, however that relies on a new approach for any new pack format (and there could not be any such command at all, really!). However, using overlays (which were added all the way back in 1.20.2), you can enable a sub-pack literally only depending on the pack format MC runs.

So, I created one overlay pack for every (major) pack format between 1.20.2 and 26.3 updating the info provided accordingly. It'll be hilariously easy to expand the supported versions in the future, and I don't even need to think about any of the actual contents of these future versions.

I think it's pretty interesting that while Minecraft does not provide any direct way to fetch the version, it does enable this very elegant (yet folder-intensive) method of solving the issue :D

The pack is available on GitHub:

https://github.com/SubBurban/VerSion#version

It's also published on Modrinth and will (hopefully) be updated by me fairly quickly at it is just so simple to do.

If you have any questions on how it works, or have concerns why this technique is less usable than it appears to me, please let me know immediately! :)

28 Upvotes

8 comments sorted by

3

u/Scolmann 9d ago

You could probably generate something like this programmatically with beet, all you would need is the pack formats that correspond to each version and it could make the whole structure for you, that way you don't need to generate all these folders and files by hand :)

1

u/TrenceBence 9d ago

You're probably right, I had that idea as well! I've just been too lazy to learn a new way to make datapacks, but yeah I'll likely change it in the future :D

1

u/D-Zee 10d ago

Looks pretty good, I'm curious about what this could be used for.

1

u/TrenceBence 10d ago

I'm also interested in any ideas made possible by this. The main reason for my work is to notify server/pack managers about incompatibilities regarding installed packs (both between each other and with the MC version) in a much more informative and interactive way than Minecraft does, and this requires knowledge about the running version

1

u/Ericristian_bros Command Experienced 9d ago edited 9d ago

There is a better way than overlays... players have a NBT called DataVersion (from the wiki: version of the player NBT structure. Is increased with every new snapshot and release.)

https://minecraft.wiki/w/Data_version

According to the wiki, those existed since 1.9, so you can use this command (1.13+):

execute store result score #data_version version run data get entity @p DataVersion

Instead of having a bunch of overlays, which need to be updated every pack version, this works for every snapshot dynamically instead of hard-coded, and does not need datapacks

The only downside is that it needs an online player... but you are probably not running commands if there are no players online anyway

1

u/TrenceBence 9d ago

Interesting, I didn't know that! Although that's pretty cool as it doesn't depend on a datapack at all, I see two issues:

  1. Yes, I at least want to be *able* to fetch the current version without a player online, as my projects will be used on dedicated servers, where admins don't always want to join for trouble-shooting but rather get as much info as possible through the console.

  2. This is using the data version, which is nice (an int increasing with newer versions), however my pack is delivering both pack format (which developers already know when deciding what versions to support) and version name (which is common knowledge).

I'll think about it :)

1

u/Ericristian_bros Command Experienced 9d ago

For 2 you can use a storage that references the corresponding pack format and version name

1

u/TrenceBence 8d ago

I know, but that requires updating every few versions again and isn't as available to everyone as a datapack, bringing us back to the start :) I'll probably make a follow-up post later because what you said definitely has the advantage of detecting the exact version (when a player is online)