Skip to content

Commit f38fd16

Browse files
committed
chore: drop dead code/versions for older neoforge
sadly it's not possible to keep neoforge compat between 1.21.1-8 and 1.21.9+ due to huge changes at the internals that are used to run the mod super early
1 parent f7c374e commit f38fd16

File tree

5 files changed

+7
-54
lines changed

5 files changed

+7
-54
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ modmenu_version=16.0.0-rc.1
3434

3535
# NeoForge
3636
neoforge_version=21.10.48-beta
37-
minecraft_version_range_neoforge=[1.21,)
37+
minecraft_version_range_neoforge=[1.21.9,)
3838
neoforge_loader_version_range=[4,)
3939

4040
## This is the version of minecraft that the 'common' project uses, you can find a list of all versions here

neoforge/src/main/java/io/github/thebossmagnus/mods/config_manager/neoforge/NeoPlatformHelper.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,6 @@ public class NeoPlatformHelper implements IPlatformHelper {
1010

1111
@Override
1212
public Path getGameDir() {
13-
// Hacky reflection to keep everything in a single jar
14-
// 1.21.9+: FMLLoader.getCurrent().getGameDir()
15-
// older version: FMLLoader.getGamePath()
16-
try {
17-
18-
Object loader = FMLLoader.class.getMethod("getCurrent").invoke(null);
19-
return (Path) loader.getClass().getMethod("getGameDir").invoke(loader);
20-
} catch (NoSuchMethodException e) {
21-
// Fallback to the older method if new one doesn't exist
22-
try {
23-
return (Path) FMLLoader.class.getMethod("getGamePath").invoke(null);
24-
} catch (ReflectiveOperationException ex) {
25-
throw new RuntimeException("Unable to obtain game directory from FMLLoader", ex);
26-
}
27-
} catch (ReflectiveOperationException e) {
28-
throw new RuntimeException("Unable to obtain game directory from FMLLoader", e);
29-
}
13+
return FMLLoader.getCurrent().getGameDir();
3014
}
3115
}

neoforge_coremod/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ sourceSets.main.resources { srcDir 'src/generated/resources' }
8080

8181
unifiedPublishing {
8282
project {
83-
gameVersions = ["1.21", "1.21.1", "1.21.2", "1.21.3", "1.21.4","1.21.5","1.21.6","1.21.7","1.21.8"]
83+
gameVersions = ["1.21.9","1.21.10"]
8484
gameLoaders = ["neoforge"]
8585

8686

neoforge_coremod/src/main/java/io/github/thebossmagnus/mods/config_manager/core_mod/services/ConfigManagerDependencyLocator.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,13 @@ public void scanMods(List<IModFile> loadedMods, IDiscoveryPipeline pipeline) {
6363
}
6464

6565
// Use reflection to access the private loadModFileFrom method
66-
Method loadModFileFromMethod = JarInJarDependencyLocator.class.getDeclaredMethod(
67-
"loadModFileFrom",
68-
IModFile.class,
69-
String.class,
70-
IDiscoveryPipeline.class,
71-
Map.class
72-
);
66+
Method loadModFileFromMethod = JarInJarDependencyLocator.class.getDeclaredMethod("loadModFileFrom", IModFile.class, String.class, IDiscoveryPipeline.class, Map.class);
7367
loadModFileFromMethod.setAccessible(true);
7468

7569
// Create a raw HashMap since we can't access EmbeddedJarKey
76-
@SuppressWarnings({"rawtypes"})
77-
Map createdModFiles = new HashMap<>();
70+
@SuppressWarnings({"rawtypes"}) Map createdModFiles = new HashMap<>();
7871

79-
@SuppressWarnings("unchecked")
80-
Optional<IModFile> neoForgeMod = (Optional<IModFile>) loadModFileFromMethod.invoke(
81-
this,
82-
modFile,
83-
"META-INF/jarjar/config_manager-neoforge.jar",
84-
pipeline,
85-
createdModFiles
86-
);
72+
@SuppressWarnings("unchecked") Optional<IModFile> neoForgeMod = (Optional<IModFile>) loadModFileFromMethod.invoke(this, modFile, "META-INF/jarjar/config_manager-neoforge.jar", pipeline, createdModFiles);
8773

8874
pipeline.addModFile(neoForgeMod.get());
8975
} catch (Exception e) {

neoforge_coremod/src/main/java/io/github/thebossmagnus/mods/config_manager/core_mod/services/ConfigManagerEarlyEntrypoint.java

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,7 @@ public class ConfigManagerEarlyEntrypoint implements GraphicsBootstrapper {
2222

2323

2424
public ConfigManagerEarlyEntrypoint() {
25-
Path gameDir;
26-
// Hacky reflection to keep everything in a single jar
27-
// 1.21.9+: FMLLoader.getCurrent().getGameDir()
28-
// older version: FMLLoader.getGamePath()
29-
try {
30-
31-
Object loader = FMLLoader.class.getMethod("getCurrent").invoke(null);
32-
gameDir = (Path) loader.getClass().getMethod("getGameDir").invoke(loader);
33-
} catch (NoSuchMethodException e) {
34-
// Fallback to the older method if new one doesn't exist
35-
try {
36-
gameDir = (Path) FMLLoader.class.getMethod("getGamePath").invoke(null);
37-
} catch (ReflectiveOperationException ex) {
38-
throw new RuntimeException("Unable to obtain game directory from FMLLoader", ex);
39-
}
40-
} catch (ReflectiveOperationException e) {
41-
throw new RuntimeException("Unable to obtain game directory from FMLLoader", e);
42-
}
25+
Path gameDir = FMLLoader.getCurrent().getGameDir();
4326
ConfigManagerStartup.run(gameDir);
4427

4528
}

0 commit comments

Comments
 (0)