Skip to content

Commit d577392

Browse files
committed
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
1 parent 877bf44 commit d577392

1 file changed

Lines changed: 45 additions & 12 deletions

File tree

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import java.io.File;
7575
import java.io.IOException;
7676
import java.text.ParseException;
77+
import java.util.Objects;
7778

7879
public class MainActivity extends BaseActivity implements ControlButtonMenuListener, EditorExitable, ServiceConnection {
7980
public static volatile ClipboardManager GLOBAL_CLIPBOARD;
@@ -186,7 +187,7 @@ protected void initLayout(int resId) {
186187
String version = getIntent().getStringExtra(INTENT_MINECRAFT_VERSION);
187188
version = version == null ? minecraftProfile.lastVersionId : version;
188189

189-
JMinecraftVersionList.Version mVersionInfo = Tools.getVersionInfo(version);
190+
JMinecraftVersionList.Version mVersionInfo = Tools.getVersionInfo(version, false);
190191
isInputStackCall = mVersionInfo.arguments != null;
191192
CallbackBridge.nativeSetUseInputStackQueue(isInputStackCall);
192193

@@ -358,18 +359,50 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
358359
}
359360

360361
private void runCraft(String versionId, JMinecraftVersionList.Version version) throws Throwable {
361-
if(Tools.LOCAL_RENDERER == null) {
362-
try {
363-
// 25w09a is when HolyGL4ES starts showing a black screen upon world load.
364-
boolean isBefore25w09a = DateUtils.dateBefore(DateUtils.parseReleaseDate(version.releaseTime), 2025, 2, 26);
365-
if (isBefore25w09a) {
366-
Tools.LOCAL_RENDERER = "opengles2";
367-
} else Tools.LOCAL_RENDERER = "opengles_mobileglues";
368-
} catch (ParseException e) {
369-
// If this gets triggered, it's probably because this is a modded version, we aren't sure
370-
// which Minecraft version its based on so use Zink just to be safe
371-
Tools.LOCAL_RENDERER = "vulkan_zink";
362+
// Autoselect renderer
363+
if (Tools.LOCAL_RENDERER == null) {
364+
String assetVersion;
365+
if (version.inheritsFrom != null) { // We are almost definitely modded if this runs
366+
File vanillaJsonFile = new File(Tools.DIR_HOME_VERSION + "/" + version.inheritsFrom + "/" + version.inheritsFrom + ".json");
367+
JMinecraftVersionList.Version vanillaJson;
368+
try {
369+
vanillaJson = Tools.GLOBAL_GSON.fromJson(Tools.read(vanillaJsonFile.getAbsolutePath()), JMinecraftVersionList.Version.class);
370+
} catch (IOException ignored) { // Should never happen, we check for this in MinecraftDownloader().start()
371+
throw new RuntimeException("Problem parsing vanilla.json. This should never happen, please send a bug report on github or discord.");
372+
}
373+
// Something went wrong if this is somehow not the case anymore
374+
if (!Objects.equals(vanillaJson.assets, vanillaJson.assetIndex.id))
375+
Tools.showErrorRemote(new RuntimeException("Vanilla json seems to be corrupt. Please send a bug report on github or discord."));
376+
assetVersion = vanillaJson.assets;
377+
} else {
378+
// Else assume we are vanilla
379+
if (!Objects.equals(version.assets, version.assetIndex.id))
380+
Tools.showErrorRemote(new RuntimeException("Vanilla json seems to be corrupt. Please send a bug report on github or discord."));
381+
assetVersion = version.assets;
372382
}
383+
// 25w09a is when HolyGL4ES starts showing a black screen upon world load.
384+
// There is no way to consistently check for that without breaking mod loaders
385+
// for old versions like legacy fabric so we start from 25w07a instead
386+
387+
// 25w07a assets and assetIndex.id is set to 23, 25w08a and 25w09a is 24.
388+
389+
// 1.19.3 snapshots and all future versions restarted assets and assetsIndex.id
390+
// to 1 and started counting up from there
391+
392+
// Previous versions had "1.19" and "1.18" and such, with April Fools versions
393+
// being even more inconsistent like "3D Shareware v1.34" for the 2019 April Fools
394+
// or 1.RV-Pre1 for 2016, thankfully now they don't seem to do that anymore and just
395+
// use the incrementing system they now have
396+
397+
// I could probably read the manifest itself then check which position the `id` field is
398+
// and count from there since its ordered latest to oldest but that uses way more code
399+
// for basically 3 peoples benefit
400+
try {
401+
int assetID = Integer.parseInt(assetVersion);
402+
// Check if below 25w08a
403+
Tools.LOCAL_RENDERER = (assetID <= 23) ? "opengles2" : "opengles_mobileglues";
404+
// Then assume 1.19.2 and below
405+
} catch (NumberFormatException e) { Tools.LOCAL_RENDERER = "opengles2"; }
373406
}
374407

375408
if(!Tools.checkRendererCompatible(this, Tools.LOCAL_RENDERER)) {

0 commit comments

Comments
 (0)