Skip to content

Commit

Permalink
Remove Quilt internals
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIllusiveC4 committed Oct 24, 2023
1 parent 587fa6b commit 0ad08e7
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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 <T> void invoke(String name, Class<T> type, BiConsumer<T, ModContainer> invoker) {
invokeContainer(name, type,
container -> invoker.accept(container.getEntrypoint(), container.getProvider()));
}

public static <T> void invokeContainer(String name, Class<T> type,
Consumer<EntrypointContainer<T>> invoker) {
RuntimeException exception = null;
Collection<EntrypointContainer<T>> entrypoints =
QuiltLoader.getEntrypointContainers(name, type);

SpectreConstants.LOG.debug("Iterating over entrypoint '{}'", name);

for (EntrypointContainer<T> 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 extends Throwable> T gatherExceptions(Throwable exc, T prev,
Function<Throwable, T> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -71,6 +71,6 @@ public Path getServerConfigPath(MinecraftServer server) {

@Override
public boolean isDedicatedServer() {
return QuiltLauncherBase.getLauncher().getEnvironmentType() == EnvType.SERVER;
return MinecraftQuiltLoader.getEnvironmentType() == EnvType.SERVER;
}
}

0 comments on commit 0ad08e7

Please sign in to comment.