fix(Renderer/Default): Check asset ID instead of mcver

This is now based on the assetIndex.id that mojangs jsons have. I am
assuming inheritedFrom to always be present, if it isn't it'll treat it
like vanilla but it should still work due to the insertSafety setting
that field

This fixes the code breaking on versions with letters in them

Please finally don't break
This commit is contained in:
alexytomi 2025-07-30 23:55:44 +08:00
parent bafef9ad77
commit 9c9440dfbf
2 changed files with 47 additions and 5 deletions

View File

@ -73,6 +73,8 @@ import org.lwjgl.glfw.CallbackBridge;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
public class MainActivity extends BaseActivity implements ControlButtonMenuListener, EditorExitable, ServiceConnection {
public static volatile ClipboardManager GLOBAL_CLIPBOARD;
public static final String INTENT_MINECRAFT_VERSION = "intent_version";
@ -356,11 +358,50 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe
}
private void runCraft(String versionId, JMinecraftVersionList.Version version) throws Throwable {
if(Tools.LOCAL_RENDERER == null) {
Integer iSelectedMcVer = Tools.mcVersiontoInt(Tools.getSelectedVanillaMcVer());
if (iSelectedMcVer >= 1021005) {
Tools.LOCAL_RENDERER = "opengles_mobileglues";
} else Tools.LOCAL_RENDERER = "opengles2";
// Autoselect renderer
if (Tools.LOCAL_RENDERER == null) {
String assetVersion;
if (version.inheritsFrom != null) { // We are almost definitely modded if this runs
File vanillaJsonFile = new File(Tools.DIR_HOME_VERSION + "/" + version.inheritsFrom + "/" + version.inheritsFrom + ".json");
JMinecraftVersionList.Version vanillaJson;
try { // Get the vanilla json from modded instance
vanillaJson = Tools.GLOBAL_GSON.fromJson(Tools.read(vanillaJsonFile.getAbsolutePath()), JMinecraftVersionList.Version.class);
} catch (IOException ignored) { // Should never happen, we check for this in MinecraftDownloader().start()
throw new RuntimeException(getString(R.string.error_vanilla_json_corrupt));
}
// Something went wrong if this is somehow not the case anymore
if (!Objects.equals(vanillaJson.assets, vanillaJson.assetIndex.id))
Tools.showErrorRemote(new RuntimeException(getString(R.string.error_vanilla_json_corrupt)));
assetVersion = vanillaJson.assets;
} else {
// Else assume we are vanilla
if (!Objects.equals(version.assets, version.assetIndex.id))
Tools.showErrorRemote(new RuntimeException(getString(R.string.error_vanilla_json_corrupt)));
assetVersion = version.assets;
}
// 25w09a is when HolyGL4ES starts showing a black screen upon world load.
// There is no way to consistently check for that without breaking mod loaders
// for old versions like legacy fabric so we start from 25w07a instead
// 25w07a assets and assetIndex.id is set to 23, 25w08a and 25w09a is 24.
// 1.19.3 snapshots and all future versions restarted assets and assetsIndex.id
// to 1 and started counting up from there
// Previous versions had "1.19" and "1.18" and such, with April Fools versions
// being even more inconsistent like "3D Shareware v1.34" for the 2019 April Fools
// or 1.RV-Pre1 for 2016, thankfully now they don't seem to do that anymore and just
// use the incrementing system they now have
// I could probably read the manifest itself then check which position the `id` field is
// and count from there since its ordered latest to oldest but that uses way more code
// for basically 3 peoples benefit
try {
int assetID = Integer.parseInt(assetVersion);
// Check if below 25w08a
Tools.LOCAL_RENDERER = (assetID <= 23) ? "opengles2" : "opengles_mobileglues";
// Then assume 1.19.2 and below
} catch (NumberFormatException e) { Tools.LOCAL_RENDERER = "opengles2"; }
}
if(!Tools.checkRendererCompatible(this, Tools.LOCAL_RENDERER)) {
Tools.RenderersList renderersList = Tools.getCompatibleRenderers(this);

View File

@ -469,4 +469,5 @@
<string name="preference_force_enable_touchcontroller_description">Force enable TouchController integration, even if mod file is not found.</string>
<string name="preference_touchcontroller_vibrate_length_title">TouchController vibrate length</string>
<string name="preference_touchcontroller_vibrate_length_description">Set the length of the vibration when using TouchController.</string>
<string name="error_vanilla_json_corrupt">Vanilla json seems to be corrupt. Please send a bug report on github or discord.</string>
</resources>