Skip to content

Commit

Permalink
Workaround for Quilt's EntrypointExceptions not being converted to Fa…
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaming32 committed Sep 18, 2023
1 parent 8b17c28 commit 00d764c
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.gaming32.modloadingscreen.api;

import net.fabricmc.loader.api.EntrypointException;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.Version;
import net.fabricmc.loader.api.VersionParsingException;
Expand Down Expand Up @@ -171,14 +172,32 @@ public static boolean hasFeatures(long requestedFeatures) {
* Invokes an entrypoint with a clean API. If Mod Loading Screen is available, its progress will show up in the
* loading screen. If you are developing a Quilt mod, you should use {@code EntrypointUtil} instead.
*
* @throws net.fabricmc.loader.api.EntrypointException If any entrypoints threw an exception
* @throws EntrypointException If any entrypoints threw an exception
*
* @apiNote This feature is <i>always</i> available, regardless of the return value of {@link #getFeatures}.
* Calling this without Mod Loading Screen will work always, but just won't show up in the (non-existent) loading
* screen.
*/
public static <T> void invokeEntrypoint(String name, Class<T> type, Consumer<? super T> invoker) {
EntrypointUtils.invoke(name, type, invoker);
public static <T> void invokeEntrypoint(String name, Class<T> type, Consumer<? super T> invoker) throws EntrypointException {
try {
EntrypointUtils.invoke(name, type, invoker);
} catch (RuntimeException e) {
// Quilt bug! Quilt's EntrypointExceptions are never converted to Fabric's!
// https://github.com/QuiltMC/quilt-loader/issues/366
Class<?> clazz = e.getClass();
while (clazz != null) {
if (clazz.getName().equals("org.quiltmc.loader.api.entrypoint.EntrypointException")) {
try {
throw new EntrypointException((String)clazz.getDeclaredMethod("getKey").invoke(e), e);
} catch (ReflectiveOperationException ex) {
e.addSuppressed(ex);
throw e;
}
}
clazz = clazz.getSuperclass();
}
throw e;
}
}

/**
Expand Down

0 comments on commit 00d764c

Please sign in to comment.