Jump to content

[1.8 - 1.10.2] Reliable way to get the launched Minecraft Version


Semx11

Recommended Posts

Hello,

 

I am using analytics for a mod of mine, and I need to get launched Minecraft version (e.g. "1.8", "1.10.2").

 

When using

Minecraft.getMinecraft().getVersion()

, it returns (in the case of Forge) for example

1.10.2-forge1.10.2-[forge_version]

. This is useful, as I can extract the version number out of this using Regex or equivalent.

 

However, there are modloaders, such as MultiMC5. When playing Minecraft via MultiMC5, it sets the Minecraft version to "MultiMC5", and you can't extract data out of that.

 

There is another way, and that is using either

MinecraftForge.MC_VERSION

or

Loader.MC_VERSION

(they are the same thing).

 

But here is the problem, this variable is not present at the

FMLInitializationEvent

That variable is present, but incorrect. Read "EDIT 2", and I need this variable to be set/accessible when it is initializing. Due to other reasons, (EDIT 2) the detection has to be done before messages can be send to the player.

 

Is there another way to get the launched Minecraft version? Or is there another event that happens between the initialization and the player joining a server/world? I tried to use FMLPostInitializationEvent, but that crashed the entire client for some reason. Read "EDIT 2".

 

Thanks in advance,

 

Semx

 

EDIT

This also happens when I am in-game:

b3b73bf08852434bbb9fb7fb68eab930.png

 

EDIT 2

Might as well add the (most likely) reason why this happens:

I am trying to make a universal mod, so one that supports 1.8 to 1.10.2. Some classes and functions change with the Minecraft Forge version, but I got that covered using reflection. When it fails to detect what version it is, it breaks down.

 

EDIT 3

I am positive that there is a way to get the Minecraft version. Even the debug menu has it right:

c0814d25865144698acbb23566b989ff.png

Keep in mind that this is the same version/instance as the screenshot above.

Link to comment
Share on other sites

Be careful however: as this is a true constant the compiler will inline this field into your code, so your code will continue to run with the value that was there when you built your mod. If you e.g. compile your mod with 1.9.4 and then run it on 1.10.2 (yes, that works most of the time) your mod will still see 1.9.4 as the value for that field.

You have to resort to reading the value via reflection (or a classfile written by something other than javac) if you want the true runtime value.

In what class can I find the 'true runtime value'? I'm not sure where to look, and I can use reflection.

 

EDIT:

I found the

GuiOverlayDebug.class

in

net.minecraft.client.gui

, and it looks like such:

f062bc0fe19f4948a31cbc8c2e92308e.png

This means that in the Minecraft version, the version is hardcoded.

This should not be a problem, as I can use Reflection to call this protected

call()

method.

Is this the right way to do it, or might there be an easier way? Thanks in advance.

 

EDIT 2:

I don't have any experience with creating core-mods, so how can I find out what the

call()

method gets mapped to? Any tutorial?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.