Skip to content

Commit cd8ed66

Browse files
committed
[FIXME] Half-finished lwjgl3ify support
Only missing popup that installs lwjgl3ify properly if detected in mods
1 parent e6edcd8 commit cd8ed66

13 files changed

Lines changed: 701 additions & 12 deletions

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import net.kdt.pojavlaunch.fragments.SelectAuthFragment;
3737
import net.kdt.pojavlaunch.lifecycle.ContextAwareDoneListener;
3838
import net.kdt.pojavlaunch.lifecycle.ContextExecutor;
39+
import net.kdt.pojavlaunch.modloaders.LWJGL3ifyUtils;
3940
import net.kdt.pojavlaunch.modloaders.modpacks.ModloaderInstallTracker;
4041
import net.kdt.pojavlaunch.modloaders.modpacks.api.CommonApi;
4142
import net.kdt.pojavlaunch.modloaders.modpacks.api.ModLoader;

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,29 @@ private static File getGameDir() {
280280
* @return Whether or not the .jar is found
281281
*/
282282
public static boolean hasMods(String... filenames) {
283+
return !getMods(filenames).isEmpty();
284+
}
285+
286+
/**
287+
* Searches for mod in mods directory of current selected profile
288+
* Not case-sensitive
289+
* @param filenames Filename(s) of the .jar mod(s)
290+
* @return The found mods
291+
*/
292+
public static List<File> getMods(String... filenames) {
283293
File gameDir = getGameDir();
284294
File modsDir = new File(gameDir, "mods");
285-
File[] modFiles = modsDir.listFiles(file -> file.isFile() && file.getName().endsWith(".jar"));
286-
if (modFiles == null) return false;
295+
File[] modFiles = modsDir.listFiles(file -> file.isFile() && file.getName().toLowerCase().endsWith(".jar"));
296+
if (modFiles == null) return new ArrayList<>();
297+
List<File> foundModFiles = new ArrayList<>();
287298
for (File file : modFiles) {
288299
for (String filename : filenames)
289-
if (file.getName().toLowerCase().contains(filename.toLowerCase())) return true;
300+
if (file.getName().toLowerCase().contains(filename.toLowerCase())) {
301+
foundModFiles.add(file);
302+
break;
303+
}
290304
}
291-
return false;
305+
return foundModFiles;
292306
}
293307

294308
/**
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package net.kdt.pojavlaunch.fragments;
2+
3+
import android.content.Context;
4+
import android.view.LayoutInflater;
5+
import android.widget.ExpandableListAdapter;
6+
7+
import androidx.annotation.NonNull;
8+
9+
import net.kdt.pojavlaunch.R;
10+
import net.kdt.pojavlaunch.modloaders.LWJGL3ifyDownloadTask;
11+
import net.kdt.pojavlaunch.modloaders.LWJGL3ifyUtils;
12+
import net.kdt.pojavlaunch.modloaders.LWJGL3ifyVersionListAdapter;
13+
import net.kdt.pojavlaunch.modloaders.ModloaderListenerProxy;
14+
import net.kdt.pojavlaunch.modloaders.modpacks.api.CommonApi;
15+
import net.kdt.pojavlaunch.modloaders.modpacks.api.ModpackApi;
16+
17+
import java.io.File;
18+
import java.io.IOException;
19+
20+
public class LWJGL3ifyInstallFragment extends ModVersionListFragment<LWJGL3ifyUtils.LWJGL3ifyVersionList>{
21+
public static final String TAG = "LWJGL3ifyInstallFragment";
22+
private ModpackApi modpackApi;
23+
24+
@Override
25+
public void onAttach(@NonNull Context context) {
26+
super.onAttach(context);
27+
modpackApi = new CommonApi(context.getString(R.string.curseforge_api_key));
28+
}
29+
public LWJGL3ifyInstallFragment() {
30+
super(TAG);
31+
}
32+
33+
/**
34+
* @return
35+
*/
36+
@Override
37+
public int getTitleText() {
38+
return R.string.select_lwjgl3ify_version;
39+
}
40+
41+
/**
42+
* @return
43+
*/
44+
@Override
45+
public int getNoDataMsg() {
46+
return R.string.modloader_dl_failed_to_load_list;
47+
}
48+
49+
/**
50+
* @return
51+
* @throws IOException
52+
*/
53+
@Override
54+
public LWJGL3ifyUtils.LWJGL3ifyVersionList loadVersionList() throws IOException {
55+
return LWJGL3ifyUtils.getLWJGL3ifyVersionList(modpackApi);
56+
}
57+
58+
/**
59+
* @param versionList
60+
* @param layoutInflater
61+
* @return
62+
*/
63+
@Override
64+
public ExpandableListAdapter createAdapter(LWJGL3ifyUtils.LWJGL3ifyVersionList versionList, LayoutInflater layoutInflater) {
65+
return new LWJGL3ifyVersionListAdapter(versionList, layoutInflater);
66+
}
67+
68+
/**
69+
* @param selectedVersion
70+
* @param listenerProxy
71+
* @return
72+
*/
73+
@Override
74+
public Runnable createDownloadTask(Object selectedVersion, ModloaderListenerProxy listenerProxy) {
75+
return new LWJGL3ifyDownloadTask(listenerProxy, (LWJGL3ifyUtils.LWJGL3ifyMod) selectedVersion, requireActivity());
76+
}
77+
78+
/**
79+
* @param context
80+
* @param downloadedFile
81+
*/
82+
@Override
83+
public void onDownloadFinished(Context context, File downloadedFile) {
84+
// Nothing to do.
85+
}
86+
}

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/MainMenuFragment.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.kdt.pojavlaunch.fragments;
22

33
import static net.kdt.pojavlaunch.Tools.dialogOnUiThread;
4+
import static net.kdt.pojavlaunch.Tools.hasMods;
45
import static net.kdt.pojavlaunch.Tools.hasNoOnlineProfileDialog;
56
import static net.kdt.pojavlaunch.Tools.hasOnlineProfile;
67
import static net.kdt.pojavlaunch.Tools.openPath;
@@ -27,12 +28,14 @@
2728
import net.kdt.pojavlaunch.Tools;
2829
import net.kdt.pojavlaunch.extra.ExtraConstants;
2930
import net.kdt.pojavlaunch.extra.ExtraCore;
31+
import net.kdt.pojavlaunch.modloaders.LWJGL3ifyUtils;
3032
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
3133
import net.kdt.pojavlaunch.progresskeeper.ProgressKeeper;
3234
import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles;
3335
import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile;
3436

3537
import java.io.File;
38+
import java.util.List;
3639

3740
public class MainMenuFragment extends Fragment {
3841
public static final String TAG = "MainMenuFragment";
@@ -80,8 +83,13 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
8083
.create();
8184
sodiumWarningDialog.show();
8285
} else ExtraCore.setValue(ExtraConstants.LAUNCH_GAME, true);
83-
84-
86+
// if (hasMods("lwjgl3ify-3")) {
87+
// Tools.dialogOnUiThread(requireActivity(), "Error!", "This version of LWJGL3ify is unsupported and won't work!");
88+
// }
89+
// List<File> f = Tools.getMods("lwjgl3ify-2");
90+
// if(!f.isEmpty()) {
91+
//
92+
// }
8593
});
8694

8795
mShareLogsButton.setOnClickListener((v) -> shareLog(requireContext()));

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/fragments/ProfileTypeSelectFragment.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
4343
tryInstall(NeoForgeInstallFragment.class, NeoForgeInstallFragment.TAG));
4444
view.findViewById(R.id.modded_profile_modpack).setOnClickListener((v)->
4545
tryInstall(ModpackCreateFragment.class, ModpackCreateFragment.TAG));
46+
view.findViewById(R.id.modded_profile_lwjgl3ify).setOnClickListener((v)->
47+
tryInstall(LWJGL3ifyInstallFragment.class, LWJGL3ifyInstallFragment.TAG));
4648
view.findViewById(R.id.modded_profile_quilt).setOnClickListener((v)->
4749
tryInstall(QuiltInstallFragment.class, QuiltInstallFragment.TAG));
4850
view.findViewById(R.id.modded_profile_bta).setOnClickListener((v)->

0 commit comments

Comments
 (0)