From e92bc8342daf693b329a2a0f2ea541047347b564 Mon Sep 17 00:00:00 2001 From: IxPrumxI Date: Sun, 25 Jan 2026 22:11:00 +0300 Subject: [PATCH] (Neo)Forge --- .../bukkit/loader/BukkitLoader.java | 2 +- .../bukkit/bootstrap/BukkitBootstrap.java | 2 +- .../bungee/bootstrap/BungeeBootstrap.java | 2 +- forge/build.gradle | 20 +++++ forge/loader/build.gradle | 18 ++++ .../forge/bootstrap/IForgeBootstrap.java | 42 +++++++++ .../forge/loader/ForgeLoader.java | 85 ++++++++++++++++++ .../src/main/resources/META-INF/mods.toml | 2 + .../forge/bootstrap/ForgeBootstrap.java | 69 +++++++++++++++ neoforge/build.gradle | 19 ++++ neoforge/loader/build.gradle | 18 ++++ .../bootstrap/INeoForgeBootstrap.java | 42 +++++++++ .../neoforge/loader/NeoForgeLoader.java | 87 +++++++++++++++++++ .../neoforge/bootstrap/NeoForgeBootstrap.java | 80 +++++++++++++++++ settings.gradle | 5 ++ 15 files changed, 490 insertions(+), 3 deletions(-) create mode 100644 forge/build.gradle create mode 100644 forge/loader/build.gradle create mode 100644 forge/loader/src/main/java/dev/vankka/mcdependencydownload/forge/bootstrap/IForgeBootstrap.java create mode 100644 forge/loader/src/main/java/dev/vankka/mcdependencydownload/forge/loader/ForgeLoader.java create mode 100644 forge/loader/src/main/resources/META-INF/mods.toml create mode 100644 forge/src/main/java/dev/vankka/mcdependencydownload/forge/bootstrap/ForgeBootstrap.java create mode 100644 neoforge/build.gradle create mode 100644 neoforge/loader/build.gradle create mode 100644 neoforge/loader/src/main/java/dev/vankka/mcdependencydownload/neoforge/bootstrap/INeoForgeBootstrap.java create mode 100644 neoforge/loader/src/main/java/dev/vankka/mcdependencydownload/neoforge/loader/NeoForgeLoader.java create mode 100644 neoforge/src/main/java/dev/vankka/mcdependencydownload/neoforge/bootstrap/NeoForgeBootstrap.java diff --git a/bukkit/loader/src/main/java/dev/vankka/mcdependencydownload/bukkit/loader/BukkitLoader.java b/bukkit/loader/src/main/java/dev/vankka/mcdependencydownload/bukkit/loader/BukkitLoader.java index 9d33331..50f41f4 100644 --- a/bukkit/loader/src/main/java/dev/vankka/mcdependencydownload/bukkit/loader/BukkitLoader.java +++ b/bukkit/loader/src/main/java/dev/vankka/mcdependencydownload/bukkit/loader/BukkitLoader.java @@ -35,7 +35,7 @@ import java.util.Optional; /** - * The loader class, the lass that extends this should be the plugin.ymls main property. + * The loader class, the class that extends this should be the plugin.ymls main property. */ @SuppressWarnings("unused") // API public abstract class BukkitLoader extends JavaPlugin implements ILoader { diff --git a/bukkit/src/main/java/dev/vankka/mcdependencydownload/bukkit/bootstrap/BukkitBootstrap.java b/bukkit/src/main/java/dev/vankka/mcdependencydownload/bukkit/bootstrap/BukkitBootstrap.java index c0264b9..3590342 100644 --- a/bukkit/src/main/java/dev/vankka/mcdependencydownload/bukkit/bootstrap/BukkitBootstrap.java +++ b/bukkit/src/main/java/dev/vankka/mcdependencydownload/bukkit/bootstrap/BukkitBootstrap.java @@ -59,7 +59,7 @@ public final JavaPlugin getPlugin() { } /** - * Gets a instance of {@link JarInJarClassLoader} that was created with the {@link JarInJarClassLoader} that loaded this class. + * Gets an instance of {@link JarInJarClassLoader} that was created with the {@link JarInJarClassLoader} that loaded this class. * @return a {@link JarInJarClassLoader} */ public JarInJarClasspathAppender getClasspathAppender() { diff --git a/bungee/src/main/java/dev/vankka/mcdependencydownload/bungee/bootstrap/BungeeBootstrap.java b/bungee/src/main/java/dev/vankka/mcdependencydownload/bungee/bootstrap/BungeeBootstrap.java index 5af9f3f..1f179cf 100644 --- a/bungee/src/main/java/dev/vankka/mcdependencydownload/bungee/bootstrap/BungeeBootstrap.java +++ b/bungee/src/main/java/dev/vankka/mcdependencydownload/bungee/bootstrap/BungeeBootstrap.java @@ -59,7 +59,7 @@ public Plugin getPlugin() { } /** - * Gets a instance of {@link JarInJarClassLoader} that was created with the {@link JarInJarClassLoader} that loaded this class. + * Gets an instance of {@link JarInJarClassLoader} that was created with the {@link JarInJarClassLoader} that loaded this class. * @return a {@link JarInJarClassLoader} */ public JarInJarClasspathAppender getClasspathAppender() { diff --git a/forge/build.gradle b/forge/build.gradle new file mode 100644 index 0000000..44d293a --- /dev/null +++ b/forge/build.gradle @@ -0,0 +1,20 @@ +plugins { + id 'net.minecraftforge.gradle' version '[6.0.36,6.2)' +} + +java { + sourceCompatibility = 21 + targetCompatibility = 21 +} + +minecraft { + mappings channel: 'official', version: '1.21.11' +} + +dependencies { + minecraft "net.minecraftforge:forge:1.21.11-61.0.0" + + api project(':common') + compileOnlyApi project(':forge:forge-loader') + api 'dev.vankka:dependencydownload-jarinjar-bootstrap:' + dependencyDownloadVersion +} \ No newline at end of file diff --git a/forge/loader/build.gradle b/forge/loader/build.gradle new file mode 100644 index 0000000..e233e27 --- /dev/null +++ b/forge/loader/build.gradle @@ -0,0 +1,18 @@ +plugins { + id 'net.minecraftforge.gradle' version '[6.0.36,6.2)' + id 'java-library' +} + +java { + sourceCompatibility = 21 + targetCompatibility = 21 +} + +minecraft { + mappings channel: 'official', version: '1.21.11' +} + +dependencies { + minecraft "net.minecraftforge:forge:1.21.11-61.0.0" + api 'dev.vankka:dependencydownload-jarinjar-loader:' + dependencyDownloadVersion +} \ No newline at end of file diff --git a/forge/loader/src/main/java/dev/vankka/mcdependencydownload/forge/bootstrap/IForgeBootstrap.java b/forge/loader/src/main/java/dev/vankka/mcdependencydownload/forge/bootstrap/IForgeBootstrap.java new file mode 100644 index 0000000..fddc3da --- /dev/null +++ b/forge/loader/src/main/java/dev/vankka/mcdependencydownload/forge/bootstrap/IForgeBootstrap.java @@ -0,0 +1,42 @@ +/* + * MIT License + * + * Copyright (c) 2021-2024 Vankka + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.vankka.mcdependencydownload.forge.bootstrap; + +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; + +/** + * An interface for NeoForge mod bootstraps. + */ +public interface IForgeBootstrap { + + /** + * Called first during the mod loading phase. + * + * @param event Forge's common setup event + */ + @SuppressWarnings("unused") // API + default void onCommonSetup(FMLCommonSetupEvent event) {} + +} diff --git a/forge/loader/src/main/java/dev/vankka/mcdependencydownload/forge/loader/ForgeLoader.java b/forge/loader/src/main/java/dev/vankka/mcdependencydownload/forge/loader/ForgeLoader.java new file mode 100644 index 0000000..e7493c2 --- /dev/null +++ b/forge/loader/src/main/java/dev/vankka/mcdependencydownload/forge/loader/ForgeLoader.java @@ -0,0 +1,85 @@ +/* + * MIT License + * + * Copyright (c) 2021-2024 Vankka + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.vankka.mcdependencydownload.forge.loader; + +import com.mojang.logging.LogUtils; +import dev.vankka.dependencydownload.jarinjar.classloader.JarInJarClassLoader; +import dev.vankka.dependencydownload.jarinjar.loader.ILoader; +import dev.vankka.mcdependencydownload.forge.bootstrap.IForgeBootstrap; +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.util.Optional; + +/** + * A loader for Forge mods. Needs to have @Mod annotation on the class. + */ +@SuppressWarnings("unused") // API +public abstract class ForgeLoader implements ILoader { + + protected final JarInJarClassLoader classLoader; + private final FMLJavaModLoadingContext ctx; + private IForgeBootstrap bootstrap; + + public ForgeLoader(FMLJavaModLoadingContext ctx) { + super(); + this.ctx = ctx; + classLoader = initialize(); + FMLCommonSetupEvent.getBus(ctx.getModBusGroup()).addListener(bootstrap::onCommonSetup); + } + + private Optional bootstrap() { + return Optional.ofNullable(bootstrap); + } + + @SuppressWarnings("NonExtendableApiUsage") // final + @Override + public final JarInJarClassLoader initialize() { + return ILoader.super.initialize(); + } + + @Override + public final void initiateBootstrap(Class bootstrapClass, @NotNull JarInJarClassLoader classLoader) throws ReflectiveOperationException { + Constructor constructor = bootstrapClass.getConstructor(JarInJarClassLoader.class, FMLJavaModLoadingContext.class); + bootstrap = (IForgeBootstrap) constructor.newInstance(classLoader, ctx); + } + + @Override + public final @NotNull ClassLoader getParentClassLoader() { + return getClass().getClassLoader(); + } + + protected void close() { + try { + classLoader.close(); + } catch (IOException e) { + LogUtils.getLogger().error("Failed to close JarInJarClassLoader"); + e.printStackTrace(); + } + } +} diff --git a/forge/loader/src/main/resources/META-INF/mods.toml b/forge/loader/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..52b9016 --- /dev/null +++ b/forge/loader/src/main/resources/META-INF/mods.toml @@ -0,0 +1,2 @@ +modLoader="javafml" +loaderVersion="[41,)" diff --git a/forge/src/main/java/dev/vankka/mcdependencydownload/forge/bootstrap/ForgeBootstrap.java b/forge/src/main/java/dev/vankka/mcdependencydownload/forge/bootstrap/ForgeBootstrap.java new file mode 100644 index 0000000..bf156d6 --- /dev/null +++ b/forge/src/main/java/dev/vankka/mcdependencydownload/forge/bootstrap/ForgeBootstrap.java @@ -0,0 +1,69 @@ +/* + * MIT License + * + * Copyright (c) 2021-2024 Vankka + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.vankka.mcdependencydownload.forge.bootstrap; + +import dev.vankka.dependencydownload.jarinjar.bootstrap.AbstractBootstrap; +import dev.vankka.dependencydownload.jarinjar.bootstrap.classpath.JarInJarClasspathAppender; +import dev.vankka.dependencydownload.jarinjar.classloader.JarInJarClassLoader; +import net.minecraftforge.fml.ModContainer; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; + +/** + * A bootstrap for Forge mods. + */ +@SuppressWarnings("unused") // API +public abstract class ForgeBootstrap extends AbstractBootstrap implements IForgeBootstrap { + + private final JarInJarClasspathAppender classpathAppender; + private final FMLJavaModLoadingContext context; + + /** + * Do not modify the parameters if you're using the ForgeLoader. + * + * @param classLoader the ClassLoader that loaded this class + * @param context the mod container instance + */ + public ForgeBootstrap(JarInJarClassLoader classLoader, FMLJavaModLoadingContext context) { + super(classLoader); + this.context = context; + this.classpathAppender = new JarInJarClasspathAppender(classLoader); + } + + /** + * Gets an instance of {@link JarInJarClassLoader} that was created with the {@link JarInJarClassLoader} that loaded this class. + * @return a {@link JarInJarClassLoader} + */ + public JarInJarClasspathAppender getClasspathAppender() { + return classpathAppender; + } + + /** + * Gets the {@link FMLJavaModLoadingContext} instance. + * @return the {@link FMLJavaModLoadingContext} instance provided by the loader. + */ + public final FMLJavaModLoadingContext getFMLContext() { + return context; + } +} diff --git a/neoforge/build.gradle b/neoforge/build.gradle new file mode 100644 index 0000000..53f97ae --- /dev/null +++ b/neoforge/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'net.neoforged.moddev' version '2.0.134' + id 'java-library' +} + +java { + sourceCompatibility = 21 + targetCompatibility = 21 +} + +dependencies { + api project(':common') + compileOnlyApi project(':neoforge:neoforge-loader') + api 'dev.vankka:dependencydownload-jarinjar-bootstrap:' + dependencyDownloadVersion +} + +neoForge { + version = "21.11.17-beta" +} diff --git a/neoforge/loader/build.gradle b/neoforge/loader/build.gradle new file mode 100644 index 0000000..3e6ea24 --- /dev/null +++ b/neoforge/loader/build.gradle @@ -0,0 +1,18 @@ +plugins { + id 'net.neoforged.moddev' version '2.0.134' + id("java-library") +} + +java { + sourceCompatibility = 21 + targetCompatibility = 21 +} + +dependencies { + api project(':common') + api 'dev.vankka:dependencydownload-jarinjar-loader:' + dependencyDownloadVersion +} + +neoForge { + version = "21.11.17-beta" +} \ No newline at end of file diff --git a/neoforge/loader/src/main/java/dev/vankka/mcdependencydownload/neoforge/bootstrap/INeoForgeBootstrap.java b/neoforge/loader/src/main/java/dev/vankka/mcdependencydownload/neoforge/bootstrap/INeoForgeBootstrap.java new file mode 100644 index 0000000..5a679af --- /dev/null +++ b/neoforge/loader/src/main/java/dev/vankka/mcdependencydownload/neoforge/bootstrap/INeoForgeBootstrap.java @@ -0,0 +1,42 @@ +/* + * MIT License + * + * Copyright (c) 2021-2024 Vankka + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.vankka.mcdependencydownload.neoforge.bootstrap; + +import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; + +/** + * An interface for NeoForge mod bootstraps. + */ +public interface INeoForgeBootstrap { + + /** + * Called first during the mod loading phase. + * + * @param event NeoForge's common setup event + */ + @SuppressWarnings("unused") // API + default void onCommonSetup(FMLCommonSetupEvent event) {} + +} diff --git a/neoforge/loader/src/main/java/dev/vankka/mcdependencydownload/neoforge/loader/NeoForgeLoader.java b/neoforge/loader/src/main/java/dev/vankka/mcdependencydownload/neoforge/loader/NeoForgeLoader.java new file mode 100644 index 0000000..a8d8f3d --- /dev/null +++ b/neoforge/loader/src/main/java/dev/vankka/mcdependencydownload/neoforge/loader/NeoForgeLoader.java @@ -0,0 +1,87 @@ +/* + * MIT License + * + * Copyright (c) 2021-2024 Vankka + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.vankka.mcdependencydownload.neoforge.loader; + +import com.mojang.logging.LogUtils; +import dev.vankka.dependencydownload.jarinjar.classloader.JarInJarClassLoader; +import dev.vankka.dependencydownload.jarinjar.loader.ILoader; +import dev.vankka.mcdependencydownload.neoforge.bootstrap.INeoForgeBootstrap; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.ModContainer; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.util.Optional; + +/** + * A loader for NeoForge mods. Needs to have @Mod annotation on the class. + */ +@SuppressWarnings("unused") // API +public abstract class NeoForgeLoader implements ILoader { + + protected final JarInJarClassLoader classLoader; + private INeoForgeBootstrap bootstrap; + private final ModContainer modContainer; + private final IEventBus eventBus; + + public NeoForgeLoader(IEventBus eventBus, ModContainer modContainer) { + super(); + this.modContainer = modContainer; + this.eventBus = eventBus; + this.classLoader = initialize(); + eventBus.addListener(bootstrap::onCommonSetup); + } + + private Optional bootstrap() { + return Optional.ofNullable(bootstrap); + } + + @SuppressWarnings("NonExtendableApiUsage") // final + @Override + public final JarInJarClassLoader initialize() { + return ILoader.super.initialize(); + } + + @Override + public final void initiateBootstrap(Class bootstrapClass, @NotNull JarInJarClassLoader classLoader) throws ReflectiveOperationException { + Constructor constructor = bootstrapClass.getConstructor(JarInJarClassLoader.class, ModContainer.class, IEventBus.class); + bootstrap = (INeoForgeBootstrap) constructor.newInstance(classLoader, modContainer, eventBus); + } + + @Override + public final @NotNull ClassLoader getParentClassLoader() { + return getClass().getClassLoader(); + } + + protected void close() { + try { + classLoader.close(); + } catch (IOException e) { + LogUtils.getLogger().error("Failed to close JarInJarClassLoader"); + e.printStackTrace(); + } + } +} diff --git a/neoforge/src/main/java/dev/vankka/mcdependencydownload/neoforge/bootstrap/NeoForgeBootstrap.java b/neoforge/src/main/java/dev/vankka/mcdependencydownload/neoforge/bootstrap/NeoForgeBootstrap.java new file mode 100644 index 0000000..66622bd --- /dev/null +++ b/neoforge/src/main/java/dev/vankka/mcdependencydownload/neoforge/bootstrap/NeoForgeBootstrap.java @@ -0,0 +1,80 @@ +/* + * MIT License + * + * Copyright (c) 2021-2024 Vankka + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package dev.vankka.mcdependencydownload.neoforge.bootstrap; + +import dev.vankka.dependencydownload.jarinjar.bootstrap.AbstractBootstrap; +import dev.vankka.dependencydownload.jarinjar.bootstrap.classpath.JarInJarClasspathAppender; +import dev.vankka.dependencydownload.jarinjar.classloader.JarInJarClassLoader; +import net.neoforged.bus.api.IEventBus; +import net.neoforged.fml.ModContainer; + +/** + * A bootstrap for NeoForge mods. + */ +@SuppressWarnings("unused") // API +public abstract class NeoForgeBootstrap extends AbstractBootstrap implements INeoForgeBootstrap { + + private final JarInJarClasspathAppender classpathAppender; + private final ModContainer modContainer; + private final IEventBus eventBus; + + /** + * Do not modify the parameters if you're using the NeoForgeLoader. + * + * @param classLoader the ClassLoader that loaded this class + * @param modContainer the ModContainer of the mod being loaded + * @param eventBus the EventBus of the mod being loaded + */ + public NeoForgeBootstrap(JarInJarClassLoader classLoader, ModContainer modContainer, IEventBus eventBus) { + super(classLoader); + this.classpathAppender = new JarInJarClasspathAppender(classLoader); + this.modContainer = modContainer; + this.eventBus = eventBus; + } + + /** + * Gets an instance of {@link JarInJarClassLoader} that was created with the {@link JarInJarClassLoader} that loaded this class. + * @return a {@link JarInJarClassLoader} + */ + public JarInJarClasspathAppender getClasspathAppender() { + return classpathAppender; + } + + /** + * Gets the ModContainer of the mod being loaded. + * @return the ModContainer of the mod being loaded + */ + public ModContainer getModContainer() { + return modContainer; + } + + /** + * Gets the EventBus of the mod being loaded. + * @return the EventBus of the mod being loaded + */ + public IEventBus getEventBus() { + return eventBus; + } +} diff --git a/settings.gradle b/settings.gradle index db2b693..8544c3a 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,6 +4,9 @@ pluginManagement { maven { url = 'https://maven.fabricmc.net/' } + maven { + url = 'https://maven.minecraftforge.net/' + } } } @@ -14,6 +17,8 @@ rootProject.name = 'MinecraftDependencyDownload' 'bukkit', 'bukkit:loader', 'bungee', 'bungee:loader', 'fabric', + 'forge', 'forge:loader', + 'neoforge', 'neoforge:loader', 'velocity' ].each { include it