fix NeoForge for 1.20.5/6

This commit is contained in:
12emin34
2024-05-15 12:06:07 +02:00
parent e7a0b72bfb
commit d1df2e4d9b
7 changed files with 50 additions and 42 deletions

View File

@@ -1,10 +1,15 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.1.2"
id 'com.github.johnrengelman.shadow'
}
repositories{
maven {url "https://maven.neoforged.net/releases"}
repositories {
maven {
name = 'NeoForged'
url = 'https://maven.neoforged.net/releases'
}
}
architectury {
platformSetupLoomIde()
neoForge()
@@ -15,41 +20,44 @@ loom {
}
configurations {
common
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
common {
canBeResolved = true
canBeConsumed = false
}
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentForge.extendsFrom common
archivesBaseName = rootProject.archives_base_name + "-neoforge"
developmentNeoForge.extendsFrom common
// Files in this configuration will be bundled into your mod using the Shadow plugin.
// Don't use the `shadow` configuration from the plugin itself as it's meant for excluding files.
shadowBundle {
canBeResolved = true
canBeConsumed = false
}
}
dependencies {
neoForge "net.neoforged:neoforge:${rootProject.neoforge_version}"
neoForge "net.neoforged:neoforge:$rootProject.neoforge_version"
common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionNeoForge")) { transitive = false }
common(project(path: ':common', configuration: 'namedElements')) { transitive false }
shadowBundle project(path: ':common', configuration: 'transformProductionNeoForge')
}
processResources {
inputs.property "version", project.version
inputs.property 'version', project.version
filesMatching("META-INF/mods.toml") {
expand "version": project.version
filesMatching('META-INF/neoforge.mods.toml') {
expand version: project.version
}
}
shadowJar {
exclude "fabric.mod.json"
exclude "architectury.common.json"
configurations = [project.configurations.shadowCommon]
archiveClassifier = "dev-shadow"
configurations = [project.configurations.shadowBundle]
archiveClassifier = 'dev-shadow'
}
remapJar {
atAccessWideners.add('midnightlib.accesswidener')
input.set shadowJar.archiveFile
dependsOn shadowJar
}
sourcesJar {

View File

@@ -2,48 +2,43 @@ package eu.midnightdust.neoforge;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import eu.midnightdust.core.MidnightLib;
import eu.midnightdust.core.screen.MidnightConfigOverviewScreen;
import eu.midnightdust.lib.config.AutoCommand;
import eu.midnightdust.lib.config.MidnightConfig;
import net.minecraft.server.command.ServerCommandSource;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.IExtensionPoint;
import net.neoforged.fml.ModList;
import net.neoforged.fml.ModLoadingContext;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.neoforge.client.ConfigScreenHandler;
import net.neoforged.neoforge.client.event.ScreenEvent;
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
import net.neoforged.neoforge.event.RegisterCommandsEvent;
import static net.neoforged.fml.IExtensionPoint.DisplayTest.IGNORESERVERONLY;
@Mod("midnightlib")
public class MidnightLibNeoForge {
public MidnightLibNeoForge() {
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> IGNORESERVERONLY, (remote, server) -> true));
if (FMLEnvironment.dist == Dist.CLIENT) MidnightLib.onInitializeClient(); else MidnightLib.onInitializeServer();
if (FMLEnvironment.dist == Dist.CLIENT) MidnightLib.onInitializeClient();
else MidnightLib.onInitializeServer();
}
@Mod.EventBusSubscriber(modid = "midnightlib", bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
@EventBusSubscriber(modid = "midnightlib", bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public static class MidnightLibBusEvents {
@SubscribeEvent
public static void onPostInit(FMLClientSetupEvent event) {
ModList.get().forEachModContainer((modid, modContainer) -> {
if (MidnightConfig.configClass.containsKey(modid)) {
modContainer.registerExtensionPoint(ConfigScreenHandler.ConfigScreenFactory.class, () ->
new ConfigScreenHandler.ConfigScreenFactory((client, parent) -> MidnightConfig.getScreen(parent, modid)));
modContainer.registerExtensionPoint(IConfigScreenFactory.class, (minecraftClient, screen) -> MidnightConfig.getScreen(screen, modid));
}
});
}
}
@Mod.EventBusSubscriber(modid = "midnightlib", value = Dist.DEDICATED_SERVER)
@EventBusSubscriber(modid = "midnightlib", value = Dist.DEDICATED_SERVER)
public static class MidnightLibServerEvents {
@SubscribeEvent
public static void registerCommands(RegisterCommandsEvent event) {
for (LiteralArgumentBuilder<ServerCommandSource> command : AutoCommand.commands){
for (LiteralArgumentBuilder<ServerCommandSource> command : AutoCommand.commands) {
event.getDispatcher().register(command);
}
}

View File

@@ -1,5 +1,5 @@
modLoader = "javafml"
loaderVersion = "[1,)"
loaderVersion = "[2,)"
#issueTrackerURL = ""
license = "MIT License"
@@ -17,13 +17,13 @@ Common Library for Team MidnightDust's mods.
[[dependencies.midnightlib]]
modId = "neoforge"
mandatory = true
versionRange = "[20.3,)"
versionRange = "[20.5,)"
ordering = "NONE"
side = "BOTH"
[[dependencies.midnightlib]]
modId = "minecraft"
mandatory = true
versionRange = "[1.20.3,)"
versionRange = "[1.20.5,)"
ordering = "NONE"
side = "BOTH"