diff --git a/build.gradle b/build.gradle index b3412d3..6c7b530 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,8 @@ plugins { id 'eclipse' id 'idea' id 'maven-publish' - id 'net.minecraftforge.gradle' version '[6.0,6.2)' + id 'java-library' + id 'net.neoforged.moddev' version '2.0.141' } version = mod_version @@ -12,116 +13,56 @@ base { archivesName = mod_id } -// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. -java.toolchain.languageVersion = JavaLanguageVersion.of(17) - -println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" -minecraft { - // The mappings can be changed at any time and must be in the following format. - // Channel: Version: - // official MCVersion Official field/method names from Mojang mapping files - // parchment YYYY.MM.DD-MCVersion Open community-sourced parameter names and javadocs layered on top of official - // - // You must be aware of the Mojang license when using the 'official' or 'parchment' mappings. - // See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md - // - // Parchment is an unofficial project maintained by ParchmentMC, separate from MinecraftForge - // Additional setup is needed to use their mappings: https://github.com/ParchmentMC/Parchment/wiki/Getting-Started - // - // Use non-default mappings at your own risk. They may not always work. - // Simply re-run your setup task after changing the mappings to update your workspace. - mappings channel: mapping_channel, version: mapping_version - - // When true, this property will have all Eclipse/IntelliJ IDEA run configurations run the "prepareX" task for the given run configuration before launching the game. - // In most cases, it is not necessary to enable. - // enableEclipsePrepareRuns = true - // enableIdeaPrepareRuns = true - - // This property allows configuring Gradle's ProcessResources task(s) to run on IDE output locations before launching the game. - // It is REQUIRED to be set to true for this template to function. - // See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html - copyIdeResources = true - - // When true, this property will add the folder name of all declared run configurations to generated IDE run configurations. - // The folder name can be set on a run configuration using the "folderName" property. - // By default, the folder name of a run configuration is the name of the Gradle project containing it. - // generateRunFolders = true - - // This property enables access transformers for use in development. - // They will be applied to the Minecraft artifact. - // The access transformer file can be anywhere in the project. - // However, it must be at "META-INF/accesstransformer.cfg" in the final mod jar to be loaded by Forge. - // This default location is a best practice to automatically put the file in the right place in the final jar. - // See https://docs.minecraftforge.net/en/latest/advanced/accesstransformers/ for more information. - // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') - - // Default run configurations. - // These can be tweaked, removed, or duplicated as needed. - runs { - // applies to all the run configs below - configureEach { - workingDirectory project.file('run') - - // Recommended logging data for a userdev environment - // The markers can be added/remove as needed separated by commas. - // "SCAN": For mods scan. - // "REGISTRIES": For firing of registry events. - // "REGISTRYDUMP": For getting the contents of all registries. - property 'forge.logging.markers', 'REGISTRIES' - - // Recommended logging level for the console - // You can set various levels here. - // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels - property 'forge.logging.console.level', 'debug' - - // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. - property 'forge.enabledGameTestNamespaces', mod_id - - mods { - "${mod_id}" { - source sourceSets.main - } - } - } +sourceSets.main.resources { + srcDir 'src/generated/resources' +} +// Mojang ships Java 21 to end users in 1.21.1, so your mod should target Java 21. +java.toolchain.languageVersion = JavaLanguageVersion.of(21) + +neoForge { + version = project.neo_version + + runs { client { - // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. - property 'forge.enabledGameTestNamespaces', mod_id + client() + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id } server { - property 'forge.enabledGameTestNamespaces', mod_id - args '--nogui' + server() + programArgument '--nogui' + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id } - // This run config launches GameTestServer and runs all registered gametests, then exits. - // By default, the server will crash when no gametests are provided. - // The gametest system is also enabled by default for other run configs under the /test command. gameTestServer { - property 'forge.enabledGameTestNamespaces', mod_id + type = "gameTestServer" + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id } data { - // example of overriding the workingDirectory set in configureEach above - workingDirectory project.file('run-data') + data() + programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() + } - // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. - args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') + configureEach { + systemProperty 'forge.logging.markers', 'REGISTRIES' + logLevel = org.slf4j.event.Level.DEBUG + } + } + + mods { + "${mod_id}" { + sourceSet(sourceSets.main) } } } -// Include resources generated by data generators. -sourceSets.main.resources { srcDir 'src/generated/resources' } +configurations { + runtimeClasspath.extendsFrom localRuntime +} repositories { - // Put repositories for dependencies here - // ForgeGradle automatically adds the Forge maven and Maven Central for you - - // If you have mod jar dependencies in ./libs, you can declare them as a repository like so: - // flatDir { - // dir 'libs' - // } maven { name = "Kalculos" url = "https://repo.sfclub.cc/snapshots" @@ -129,74 +70,46 @@ repositories { } dependencies { - // Specify the version of Minecraft to use. - // Any artifact can be supplied so long as it has a "userdev" classifier artifact and is a compatible patcher artifact. - // The "userdev" classifier will be requested and setup by ForgeGradle. - // If the group id is "net.minecraft" and the artifact id is one of ["client", "server", "joined"], - // then special handling is done to allow a setup of a vanilla dependency without the use of an external repository. - minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" - - // Real mod deobf dependency examples - these get remapped to your current mappings - // compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency - // runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}") // Adds the full JEI mod as a runtime dependency - // implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency - - // Example mod dependency using a mod jar from ./libs with a flat dir repository - // This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar - // The group id is ignored when searching -- in this case, it is "blank" - // implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}") - - // For more info: - // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html - // http://www.gradle.org/docs/current/userguide/dependency_management.html } -// This block of code expands all declared replace properties in the specified resource targets. -// A missing property will result in an error. Properties are expanded using ${} Groovy notation. -// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments. -// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html -tasks.named('processResources', ProcessResources).configure { +tasks.withType(ProcessResources).configureEach { var replaceProperties = [ - minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range, - forge_version : forge_version, forge_version_range: forge_version_range, - loader_version_range: loader_version_range, - mod_id : mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version, - mod_authors : mod_authors, mod_description: mod_description, + minecraft_version : minecraft_version, + minecraft_version_range: minecraft_version_range, + neo_version : neo_version, + loader_version_range : loader_version_range, + mod_id : mod_id, + mod_name : mod_name, + mod_license : mod_license, + mod_version : mod_version, + mod_authors : mod_authors, + mod_description : mod_description, ] inputs.properties replaceProperties - filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) { + filesMatching(['META-INF/neoforge.mods.toml', 'pack.mcmeta']) { expand replaceProperties + [project: project] } } -// Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, - 'Specification-Version' : '1', // We are version 1 of ourselves + 'Specification-Version' : '1', 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ") ]) } - - // This is the preferred method to reobfuscate your jar file - finalizedBy 'reobfJar' } -// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing: -// tasks.named('publish').configure { -// dependsOn 'reobfJar' -// } - publishing { publications { register('mavenJava', MavenPublication) { - artifact jar + from components.java } } repositories { @@ -207,5 +120,5 @@ publishing { } tasks.withType(JavaCompile).configureEach { - options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation + options.encoding = 'UTF-8' } diff --git a/gradle.properties b/gradle.properties index bc6b1f6..04fb70d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,18 +6,16 @@ org.gradle.daemon=false ## Environment Properties -# The Minecraft version must agree with the Forge version to get a valid artifact -minecraft_version=1.19.2 +# The Minecraft version must agree with the NeoForge version to get a valid artifact +minecraft_version=1.21.1 # The Minecraft version range can use any release version of Minecraft as bounds. # Snapshots, pre-releases, and release candidates are not guaranteed to sort properly # as they do not follow standard versioning conventions. -minecraft_version_range=[1.19.2,1.20) -# The Forge version must agree with the Minecraft version to get a valid artifact -forge_version=43.5.0 -# The Forge version range can use any version of Forge as bounds or match the loader version range -forge_version_range=[43,) -# The loader version range can only use the major version of Forge/FML as bounds -loader_version_range=[43,) +minecraft_version_range=[1.21.1] +# The NeoForge version must agree with the Minecraft version to get a valid artifact +neo_version=21.1.229 +# The loader version range can only use the major version of FML as bounds +loader_version_range=[1,) # The mapping channel to use for mappings. # The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"]. # Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin. @@ -35,7 +33,7 @@ loader_version_range=[43,) mapping_channel=official # The mapping version to query from the mapping channel. # This must match the format required by the mapping channel. -mapping_version=1.19.2 +mapping_version=1.21.1 ## Mod Properties diff --git a/settings.gradle b/settings.gradle index 0077fa7..7a488e3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,13 +1,9 @@ pluginManagement { repositories { gradlePluginPortal() - maven { - name = 'MinecraftForge' - url = 'https://maven.minecraftforge.net/' - } } } plugins { - id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0' + id 'org.gradle.toolchains.foojay-resolver-convention' version '1.0.0' } diff --git a/src/main/java/io/ib67/packsync/PackSync.java b/src/main/java/io/ib67/packsync/PackSync.java index 7beedc9..559326b 100644 --- a/src/main/java/io/ib67/packsync/PackSync.java +++ b/src/main/java/io/ib67/packsync/PackSync.java @@ -8,7 +8,6 @@ import io.ib67.packsync.data.adapter.InstantAdapter; import io.ib67.packsync.util.BiGenerator; import io.ib67.packsync.util.CompletableFutureRoller; -import net.minecraftforge.fml.StartupMessageManager; import javax.annotation.Nullable; import java.io.IOException; @@ -188,7 +187,7 @@ private void attemptUpdateSingle(Path destination, CaddyFileObject caddyFileObje } public static void log(String message) { - StartupMessageManager.addModMessage("[PackSync] " + message); + System.out.println("[PackSync] " + message); } // This method asserts the file exists. diff --git a/src/main/java/io/ib67/packsync/PackSyncMod.java b/src/main/java/io/ib67/packsync/PackSyncMod.java index 3b7fd01..725d75b 100644 --- a/src/main/java/io/ib67/packsync/PackSyncMod.java +++ b/src/main/java/io/ib67/packsync/PackSyncMod.java @@ -1,12 +1,11 @@ package io.ib67.packsync; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.neoforged.fml.common.Mod; @Mod(PackSyncMod.MODID) public class PackSyncMod { public static final String MODID = "packsync"; - public PackSyncMod(FMLJavaModLoadingContext context) { + public PackSyncMod() { } } diff --git a/src/main/java/io/ib67/packsync/loading/PackSyncModLocator.java b/src/main/java/io/ib67/packsync/loading/PackSyncModLocator.java index a9153a3..f4203ba 100644 --- a/src/main/java/io/ib67/packsync/loading/PackSyncModLocator.java +++ b/src/main/java/io/ib67/packsync/loading/PackSyncModLocator.java @@ -3,60 +3,82 @@ import io.ib67.packsync.PackSync; import io.ib67.packsync.UpdateEvent; import io.ib67.packsync.data.SyncConfig; -import io.ib67.packsync.util.Proxies; -import net.minecraftforge.fml.loading.FMLPaths; -import net.minecraftforge.fml.loading.moddiscovery.AbstractJarFileModProvider; -import net.minecraftforge.forgespi.locating.IModLocator; +import net.neoforged.fml.loading.FMLPaths; +import net.neoforged.neoforgespi.ILaunchContext; +import net.neoforged.neoforgespi.locating.IDiscoveryPipeline; +import net.neoforged.neoforgespi.locating.IModFileCandidateLocator; +import net.neoforged.neoforgespi.locating.IncompatibleFileReporting; +import net.neoforged.neoforgespi.locating.ModFileDiscoveryAttributes; import java.awt.*; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; -import java.util.List; -import java.util.Map; import static io.ib67.packsync.PackSync.log; -public class PackSyncModLocator extends AbstractJarFileModProvider implements IModLocator { +public class PackSyncModLocator implements IModFileCandidateLocator { private static final boolean CAN_SHOW_DIALOG = !GraphicsEnvironment.isHeadless() || Boolean.getBoolean("packsync.allowDialogs"); - private PackSync packSync; + private final Object initLock = new Object(); + private volatile PackSync packSync; @Override - public String name() { - return "packsync managed mods locator"; - } - - @Override - public void initArguments(Map arguments) { - var gameDir = FMLPaths.GAMEDIR.get(); - var syncConfig = loadSyncConfig(gameDir); - PackSyncGui gui = null; - if (CAN_SHOW_DIALOG) { - gui = new PackSyncGui(); - gui.setVisible(true); + public void findCandidates(ILaunchContext context, IDiscoveryPipeline pipeline) { + var currentPackSync = initializePackSync(); + if (currentPackSync == null) { + return; } - packSync = new PackSync(gameDir, syncConfig, gui); - try { - Files.createDirectories(packSync.managedModsDir()); - Files.createDirectories(packSync.stateDir()); - } catch (Exception e) { - log("PackSync will not load because an error occurred"); + try (var list = Files.list(currentPackSync.managedModsDir())) { + list.filter(Files::isRegularFile) + .forEach(path -> pipeline.addPath(path, ModFileDiscoveryAttributes.DEFAULT.withLocator(this), + IncompatibleFileReporting.WARN_ALWAYS)); + } catch (IOException e) { + log("Error occurred while attempting to scan mods"); e.printStackTrace(); - return; } + } - try { - var newManifest = packSync.performSync(); - if (newManifest == null) { - return; + private PackSync initializePackSync() { + if (packSync != null) { + return packSync; + } + synchronized (initLock) { + if (packSync != null) { + return packSync; } - log("Update completed. Saving manifest cache..."); - packSync.saveLocalManifest(newManifest); - } catch (Exception e) { - log("Error occurred during update"); - e.printStackTrace(); - if (gui != null) gui.accept(new UpdateEvent.SyncError(e.getMessage(), e)); + var gameDir = FMLPaths.GAMEDIR.get(); + var syncConfig = loadSyncConfig(gameDir); + PackSyncGui gui = null; + if (CAN_SHOW_DIALOG) { + gui = new PackSyncGui(); + gui.setVisible(true); + } + var currentPackSync = new PackSync(gameDir, syncConfig, gui); + try { + Files.createDirectories(currentPackSync.managedModsDir()); + Files.createDirectories(currentPackSync.stateDir()); + } catch (Exception e) { + log("PackSync will not load because an error occurred"); + e.printStackTrace(); + return null; + } + + try { + var newManifest = currentPackSync.performSync(); + if (newManifest != null) { + log("Update completed. Saving manifest cache..."); + currentPackSync.saveLocalManifest(newManifest); + } + } catch (Exception e) { + log("Error occurred during update"); + e.printStackTrace(); + if (gui != null) { + gui.accept(new UpdateEvent.SyncError(e.getMessage(), e)); + } + } + packSync = currentPackSync; + return currentPackSync; } } @@ -80,15 +102,7 @@ private static SyncConfig loadSyncConfig(Path gameDir) { } @Override - public List scanMods() { - try (var list = Files.list(packSync.managedModsDir())) { - return list.map(this::createMod) - .map(it -> it.file() == null ? it : new ModFileOrException(Proxies.wrapPrioritized(it.file()), it.ex())) - .toList(); - } catch (IOException e) { - log("Error occurred while attempting to scan mods: "); - e.printStackTrace(); - } - return List.of(); + public String toString() { + return "{packsync managed mods locator}"; } } diff --git a/src/main/java/io/ib67/packsync/util/CompletableFutureRoller.java b/src/main/java/io/ib67/packsync/util/CompletableFutureRoller.java index f05111d..bff8dcd 100644 --- a/src/main/java/io/ib67/packsync/util/CompletableFutureRoller.java +++ b/src/main/java/io/ib67/packsync/util/CompletableFutureRoller.java @@ -1,7 +1,5 @@ package io.ib67.packsync.util; -import net.minecraftforge.fml.StartupMessageManager; - import java.util.ArrayDeque; import java.util.Deque; import java.util.List; @@ -20,10 +18,10 @@ public CompletableFutureRoller(List listOfFutures, Function apply(Throwable throwable) { - StartupMessageManager.addModMessage("Task failed: "+throwable.getMessage()); + System.out.println("[PackSync] Task failed: " + throwable.getMessage()); if(listOfFutures.isEmpty()) return CompletableFuture.failedFuture(throwable); var target = listOfFutures.pop(); - StartupMessageManager.addModMessage("Retrying with "+target); + System.out.println("[PackSync] Retrying with " + target); return mapper.apply(target).exceptionallyCompose(this); } } diff --git a/src/main/java/io/ib67/packsync/util/Proxies.java b/src/main/java/io/ib67/packsync/util/Proxies.java index 2944aa8..29d98a6 100644 --- a/src/main/java/io/ib67/packsync/util/Proxies.java +++ b/src/main/java/io/ib67/packsync/util/Proxies.java @@ -1,7 +1,7 @@ package io.ib67.packsync.util; -import net.minecraftforge.forgespi.language.IModInfo; -import net.minecraftforge.forgespi.locating.IModFile; +import net.neoforged.neoforgespi.language.IModInfo; +import net.neoforged.neoforgespi.locating.IModFile; import org.apache.maven.artifact.versioning.ArtifactVersion; import java.lang.reflect.Proxy; diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/neoforge.mods.toml similarity index 83% rename from src/main/resources/META-INF/mods.toml rename to src/main/resources/META-INF/neoforge.mods.toml index a09c1e6..1d5fadc 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/neoforge.mods.toml @@ -11,15 +11,15 @@ authors="${mod_authors}" description='''${mod_description}''' [[dependencies.${mod_id}]] -modId="forge" -mandatory=true -versionRange="${forge_version_range}" +modId="neoforge" +type="required" +versionRange="[${neo_version},)" ordering="NONE" side="BOTH" [[dependencies.${mod_id}]] modId="minecraft" -mandatory=true +type="required" versionRange="${minecraft_version_range}" ordering="NONE" side="BOTH" diff --git a/src/main/resources/META-INF/services/net.minecraftforge.forgespi.locating.IModLocator b/src/main/resources/META-INF/services/net.minecraftforge.forgespi.locating.IModLocator deleted file mode 100644 index e8d7a6e..0000000 --- a/src/main/resources/META-INF/services/net.minecraftforge.forgespi.locating.IModLocator +++ /dev/null @@ -1 +0,0 @@ -io.ib67.packsync.loading.PackSyncModLocator diff --git a/src/main/resources/META-INF/services/net.neoforged.neoforgespi.locating.IModFileCandidateLocator b/src/main/resources/META-INF/services/net.neoforged.neoforgespi.locating.IModFileCandidateLocator new file mode 100644 index 0000000..ca69704 --- /dev/null +++ b/src/main/resources/META-INF/services/net.neoforged.neoforgespi.locating.IModFileCandidateLocator @@ -0,0 +1 @@ +io.ib67.packsync.loading.PackSyncModLocator \ No newline at end of file