|
| 1 | +plugins { |
| 2 | + id 'java-library' |
| 3 | + id 'maven-publish' |
| 4 | + id 'net.neoforged.gradle.userdev' version '7.0.184' |
| 5 | +} |
| 6 | + |
| 7 | +//tasks.named('wrapper', Wrapper).configure { |
| 8 | +// // Define wrapper values here so as to not have to always do so when updating gradlew.properties. |
| 9 | +// // Switching this to Wrapper.DistributionType.ALL will download the full gradle sources that comes with |
| 10 | +// // documentation attached on cursor hover of gradle classes and methods. However, this comes with increased |
| 11 | +// // file size for Gradle. If you do switch this to ALL, run the Gradle wrapper task twice afterwards. |
| 12 | +// // (Verify by checking gradle/wrapper/gradle-wrapper.properties to see if distributionUrl now points to `-all`) |
| 13 | +// distributionType = Wrapper.DistributionType.BIN |
| 14 | +//} |
| 15 | + |
| 16 | +version = mod_version |
| 17 | +group = mod_group_id |
| 18 | + |
| 19 | +repositories { |
| 20 | + mavenLocal() |
| 21 | +} |
| 22 | + |
| 23 | +base { |
| 24 | + archivesName = mod_id + "-" + minecraft_version |
| 25 | +} |
| 26 | + |
| 27 | +// Mojang ships Java 21 to end users starting in 1.20.5, so mods should target Java 21. |
| 28 | +java.toolchain.languageVersion = JavaLanguageVersion.of(21) |
| 29 | + |
| 30 | +//minecraft.accessTransformers.file rootProject.file('src/main/resources/META-INF/accesstransformer.cfg') |
| 31 | +//minecraft.accessTransformers.entry public net.minecraft.client.Minecraft textureManager # textureManager |
| 32 | +sourceSets { |
| 33 | + main |
| 34 | + datagen |
| 35 | + generated |
| 36 | + gametest |
| 37 | +} |
| 38 | + |
| 39 | +// Default run configurations. |
| 40 | +// These can be tweaked, removed, or duplicated as needed. |
| 41 | +runs { |
| 42 | + // applies to all the run configs below |
| 43 | + configureEach { |
| 44 | + // Recommended logging data for a userdev environment |
| 45 | + // The markers can be added/remove as needed separated by commas. |
| 46 | + // "SCAN": For mods scan. |
| 47 | + // "REGISTRIES": For firing of registry events. |
| 48 | + // "REGISTRYDUMP": For getting the contents of all registries. |
| 49 | + systemProperty 'forge.logging.markers', 'REGISTRIES' |
| 50 | + |
| 51 | + // Recommended logging level for the console |
| 52 | + // You can set various levels here. |
| 53 | + // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels |
| 54 | + systemProperty 'forge.logging.console.level', 'debug' |
| 55 | + |
| 56 | + modSource project.sourceSets.main |
| 57 | + } |
| 58 | + |
| 59 | + client { |
| 60 | + // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. |
| 61 | + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id |
| 62 | + |
| 63 | + } |
| 64 | + |
| 65 | + server { |
| 66 | + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id |
| 67 | + argument '--nogui' |
| 68 | + } |
| 69 | + |
| 70 | + // This run config launches GameTestServer and runs all registered gametests, then exits. |
| 71 | + // By default, the server will crash when no gametests are provided. |
| 72 | + // The gametest system is also enabled by default for other run configs under the /test command. |
| 73 | + gameTestServer { |
| 74 | + systemProperty 'neoforge.enabledGameTestNamespaces', project.mod_id |
| 75 | + } |
| 76 | + |
| 77 | + clientData { |
| 78 | + // example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it |
| 79 | + // workingDirectory project.file('run-data') |
| 80 | + |
| 81 | + // Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. |
| 82 | + arguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() |
| 83 | + modSource project.sourceSets.datagen |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +// Include resources generated by data generators. |
| 88 | +sourceSets.main.resources { srcDir 'src/generated/resources' } |
| 89 | + |
| 90 | +// Sets up a dependency configuration called 'localRuntime'. |
| 91 | +// This configuration should be used instead of 'runtimeOnly' to declare |
| 92 | +// a dependency that will be present for runtime testing but that is |
| 93 | +// "optional", meaning it will not be pulled by dependents of this mod. |
| 94 | +configurations { |
| 95 | + |
| 96 | + datagenCompileClasspath.extendsFrom(compileClasspath) |
| 97 | + datagenRuntimeClasspath.extendsFrom(runtimeClasspath) |
| 98 | + gametestCompileClasspath.extendsFrom(compileClasspath) |
| 99 | + gametestRuntimeClasspath.extendsFrom(runtimeClasspath) |
| 100 | +} |
| 101 | + |
| 102 | +dependencies { |
| 103 | + // Specify the version of Minecraft to use. |
| 104 | + // Depending on the plugin applied there are several options. We will assume you applied the userdev plugin as shown above. |
| 105 | + // The group for userdev is net.neoforged, the module name is neoforge, and the version is the same as the neoforge version. |
| 106 | + // You can however also use the vanilla plugin (net.neoforged.gradle.vanilla) to use a version of Minecraft without the neoforge loader. |
| 107 | + // And its provides the option to then use net.minecraft as the group, and one of; client, server or joined as the module name, plus the game version as version. |
| 108 | + // For all intends and purposes: You can treat this dependency as if it is a normal library you would use. |
| 109 | + implementation "net.neoforged:neoforge:${neo_version}" |
| 110 | + |
| 111 | + datagenImplementation sourceSets.main.output |
| 112 | + |
| 113 | + // Example optional mod dependency with JEI |
| 114 | + // The JEI API is declared for compile time use, while the full JEI artifact is used at runtime |
| 115 | + // compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}" |
| 116 | + // compileOnly "mezz.jei:jei-${mc_version}-neoforge-api:${jei_version}" |
| 117 | + // We add the full version to localRuntime, not runtimeOnly, so that we do not publish a dependency on it |
| 118 | + // localRuntime "mezz.jei:jei-${mc_version}-neoforge:${jei_version}" |
| 119 | + |
| 120 | + // Example mod dependency using a mod jar from ./libs with a flat dir repository |
| 121 | + // This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar |
| 122 | + // The group id is ignored when searching -- in this case, it is "blank" |
| 123 | + // implementation "blank:coolmod-${mc_version}:${coolmod_version}" |
| 124 | + |
| 125 | + // Example mod dependency using a file as dependency |
| 126 | + // implementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar") |
| 127 | + |
| 128 | + // Example project dependency using a sister or child project: |
| 129 | + // implementation project(":myproject") |
| 130 | + |
| 131 | + // For more info: |
| 132 | + // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html |
| 133 | + // http://www.gradle.org/docs/current/userguide/dependency_management.html |
| 134 | +} |
| 135 | + |
| 136 | +// This block of code expands all declared replace properties in the specified resource targets. |
| 137 | +// A missing property will result in an error. Properties are expanded using ${} Groovy notation. |
| 138 | +// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments. |
| 139 | +// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html |
| 140 | +tasks.withType(ProcessResources).configureEach { |
| 141 | + var replaceProperties = [ |
| 142 | + minecraft_version : minecraft_version, |
| 143 | + minecraft_version_range: minecraft_version_range, |
| 144 | + neo_version : neo_version, |
| 145 | + neo_version_range : neo_version_range, |
| 146 | + loader_version_range : loader_version_range, |
| 147 | + mod_id : mod_id, |
| 148 | + mod_name : mod_name, |
| 149 | + mod_license : mod_license, |
| 150 | + mod_version : mod_version, |
| 151 | + mod_authors : mod_authors, |
| 152 | + mod_description : mod_description |
| 153 | + ] |
| 154 | + inputs.properties replaceProperties |
| 155 | + |
| 156 | + filesMatching(['META-INF/neoforge.mods.toml']) { |
| 157 | + expand replaceProperties |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +// Example configuration to allow publishing using the maven-publish plugin |
| 162 | +publishing { |
| 163 | + publications { |
| 164 | + register('mavenJava', MavenPublication) { |
| 165 | + from components.java |
| 166 | + } |
| 167 | + } |
| 168 | + repositories { |
| 169 | + maven { |
| 170 | + url "file://${project.projectDir}/repo" |
| 171 | + } |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | +tasks.withType(JavaCompile).configureEach { |
| 176 | + options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation |
| 177 | +} |
| 178 | + |
| 179 | +// IDEA no longer automatically downloads sources/javadoc jars for dependencies, so we need to explicitly enable the behavior. |
| 180 | +idea { |
| 181 | + module { |
| 182 | + downloadSources = true |
| 183 | + downloadJavadoc = true |
| 184 | + } |
| 185 | +} |
0 commit comments