From 0ad08e7c56f0a7c97dc23693988ee9946a0de3a0 Mon Sep 17 00:00:00 2001 From: C4 <29991504+TheIllusiveC4@users.noreply.github.com> Date: Tue, 24 Oct 2023 01:52:56 -0700 Subject: [PATCH] Remove Quilt internals --- gradle.properties | 2 +- .../spectrelib/EntrypointUtils.java | 78 +++++++++++++++++++ .../spectrelib/SpectreClientQuiltMod.java | 1 - .../spectrelib/SpectrePreLaunchQuiltMod.java | 1 - .../platform/QuiltConfigHelper.java | 4 +- 5 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 quilt/src/main/java/com/illusivesoulworks/spectrelib/EntrypointUtils.java diff --git a/gradle.properties b/gradle.properties index 3d4d778..f7de2fb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Project -version=0.12.6+1.19.2 +version=0.12.7+1.19.2 group=com.illusivesoulworks.spectrelib license=LGPL-2.1-only diff --git a/quilt/src/main/java/com/illusivesoulworks/spectrelib/EntrypointUtils.java b/quilt/src/main/java/com/illusivesoulworks/spectrelib/EntrypointUtils.java new file mode 100644 index 0000000..74592c1 --- /dev/null +++ b/quilt/src/main/java/com/illusivesoulworks/spectrelib/EntrypointUtils.java @@ -0,0 +1,78 @@ +package com.illusivesoulworks.spectrelib; + +import java.io.UncheckedIOException; +import java.util.Collection; +import java.util.concurrent.CompletionException; +import java.util.concurrent.ExecutionException; +import java.util.function.BiConsumer; +import java.util.function.Consumer; +import java.util.function.Function; +import org.quiltmc.loader.api.ModContainer; +import org.quiltmc.loader.api.QuiltLoader; +import org.quiltmc.loader.api.entrypoint.EntrypointContainer; + +public class EntrypointUtils { + + public static void invoke(String name, Class type, BiConsumer invoker) { + invokeContainer(name, type, + container -> invoker.accept(container.getEntrypoint(), container.getProvider())); + } + + public static void invokeContainer(String name, Class type, + Consumer> invoker) { + RuntimeException exception = null; + Collection> entrypoints = + QuiltLoader.getEntrypointContainers(name, type); + + SpectreConstants.LOG.debug("Iterating over entrypoint '{}'", name); + + for (EntrypointContainer container : entrypoints) { + try { + invoker.accept(container); + } catch (Throwable t) { + exception = gatherExceptions(t, + exception, + exc -> new RuntimeException(String.format( + "Could not execute entrypoint stage '%s' due to errors, provided by '%s'!", + name, container.getProvider().metadata().id()), + exc)); + } + } + + if (exception != null) { + throw exception; + } + } + + public static T gatherExceptions(Throwable exc, T prev, + Function mainExcFactory) { + exc = unwrap(exc); + + if (prev == null) { + return mainExcFactory.apply(exc); + } else if (exc != prev) { + + for (Throwable t : prev.getSuppressed()) { + + if (exc.equals(t)) { + return prev; + } + } + prev.addSuppressed(exc); + } + return prev; + } + + private static Throwable unwrap(Throwable exc) { + + if (exc instanceof UncheckedIOException || exc instanceof ExecutionException || + exc instanceof CompletionException) { + Throwable ret = exc.getCause(); + + if (ret != null) { + return unwrap(ret); + } + } + return exc; + } +} diff --git a/quilt/src/main/java/com/illusivesoulworks/spectrelib/SpectreClientQuiltMod.java b/quilt/src/main/java/com/illusivesoulworks/spectrelib/SpectreClientQuiltMod.java index ddfbfe2..96f175f 100644 --- a/quilt/src/main/java/com/illusivesoulworks/spectrelib/SpectreClientQuiltMod.java +++ b/quilt/src/main/java/com/illusivesoulworks/spectrelib/SpectreClientQuiltMod.java @@ -24,7 +24,6 @@ import java.io.File; import net.minecraft.client.main.GameConfig; import org.quiltmc.loader.api.ModContainer; -import org.quiltmc.loader.impl.entrypoint.EntrypointUtils; import org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer; import org.quiltmc.qsl.networking.api.client.ClientPlayConnectionEvents; import org.quiltmc.qsl.networking.api.client.ClientPlayNetworking; diff --git a/quilt/src/main/java/com/illusivesoulworks/spectrelib/SpectrePreLaunchQuiltMod.java b/quilt/src/main/java/com/illusivesoulworks/spectrelib/SpectrePreLaunchQuiltMod.java index 68e14a0..8e6c5e6 100644 --- a/quilt/src/main/java/com/illusivesoulworks/spectrelib/SpectrePreLaunchQuiltMod.java +++ b/quilt/src/main/java/com/illusivesoulworks/spectrelib/SpectrePreLaunchQuiltMod.java @@ -23,7 +23,6 @@ import org.quiltmc.loader.api.ModContainer; import org.quiltmc.loader.api.entrypoint.PreLaunchEntrypoint; import org.quiltmc.loader.api.minecraft.MinecraftQuiltLoader; -import org.quiltmc.loader.impl.entrypoint.EntrypointUtils; public class SpectrePreLaunchQuiltMod implements PreLaunchEntrypoint { diff --git a/quilt/src/main/java/com/illusivesoulworks/spectrelib/platform/QuiltConfigHelper.java b/quilt/src/main/java/com/illusivesoulworks/spectrelib/platform/QuiltConfigHelper.java index bb7acef..e5d8743 100644 --- a/quilt/src/main/java/com/illusivesoulworks/spectrelib/platform/QuiltConfigHelper.java +++ b/quilt/src/main/java/com/illusivesoulworks/spectrelib/platform/QuiltConfigHelper.java @@ -27,7 +27,7 @@ import net.fabricmc.api.EnvType; import net.minecraft.server.MinecraftServer; import net.minecraft.world.level.storage.LevelResource; -import org.quiltmc.loader.impl.launch.common.QuiltLauncherBase; +import org.quiltmc.loader.api.minecraft.MinecraftQuiltLoader; public class QuiltConfigHelper implements IConfigHelper { @@ -71,6 +71,6 @@ public Path getServerConfigPath(MinecraftServer server) { @Override public boolean isDedicatedServer() { - return QuiltLauncherBase.getLauncher().getEnvironmentType() == EnvType.SERVER; + return MinecraftQuiltLoader.getEnvironmentType() == EnvType.SERVER; } }