Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
20 changes: 20 additions & 0 deletions forge/build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
18 changes: 18 additions & 0 deletions forge/loader/build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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) {}

}
Original file line number Diff line number Diff line change
@@ -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<IForgeBootstrap> 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();
}
}
}
2 changes: 2 additions & 0 deletions forge/loader/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
modLoader="javafml"
loaderVersion="[41,)"
Original file line number Diff line number Diff line change
@@ -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;
}
}
19 changes: 19 additions & 0 deletions neoforge/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
18 changes: 18 additions & 0 deletions neoforge/loader/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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) {}

}
Loading