Skip to content

Commit

Permalink
Updated everything except packets, or so I think!
Browse files Browse the repository at this point in the history
  • Loading branch information
Direwolf20-MC committed Feb 15, 2024
1 parent 7edae79 commit 595795a
Show file tree
Hide file tree
Showing 64 changed files with 1,359 additions and 1,308 deletions.
331 changes: 146 additions & 185 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,103 +1,137 @@
import groovy.json.JsonSlurper
import groovy.json.JsonOutput

plugins {
id 'java-library'
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.neoforged.gradle' version '[6.0.18,6.2)'
id "me.modmuss50.mod-publish-plugin" version "0.3.5"
}

apply {
// Fixes m1 macs having build time errors (#forgeplzfix)
// from "https://raw.githubusercontent.com/mezz/JustEnoughItems/1.18/Forge/buildtools/AppleSiliconSupport.gradle"
id 'net.neoforged.gradle.userdev' version '7.0.80'
}

version = "${mod_version}"
group = 'com.direwolf20.mininggadgets' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'mininggadgets'
group = mod_group_id

java.toolchain.languageVersion = JavaLanguageVersion.of(17)
// All jar files from this folder will be added automatically as runtime mod dependencies
def extraModsDir = "extra-mods"
def extraAPIDir = "extra-api"

minecraft {
mappings channel: 'official', version: "${mc_version}"
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
repositories {
mavenLocal()

runs {
client {
workingDirectory project.file('run')
flatDir {
name "extra-mods"
dir file(extraModsDir)
}

property 'forge.logging.markers', 'SCAN,REGISTRIES'
property 'forge.logging.console.level', 'debug'
flatDir {
name "extra-api"
dir file(extraAPIDir)
}

mods {
mininggadgets {
source sourceSets.main
}
}
maven { //Patchouli && JEI
url 'https://maven.blamejared.com'
content {
includeGroup "vazkii.patchouli"
includeGroup "mezz.jei"
}
}

server {
workingDirectory project.file('run')

property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug'

mods {
mininggadgets {
source sourceSets.main
}
}
maven { //Curios
url = "https://maven.theillusivec4.top/"
content {
includeGroup "top.theillusivec4.curios"
}
}

data {
workingDirectory project.file('run')

property 'forge.logging.markers', 'SCAN,REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug'

args '--mod', 'mininggadgets', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
mods {
mininggadgets {
source sourceSets.main
}
}
maven { // mek
url = 'https://modmaven.dev/'
content {
includeGroup "mekanism"
includeGroup "appeng"
}
}

maven { url = "https://www.cursemaven.com" } // curse mods
}

sourceSets.main.resources { srcDir 'src/generated/resources' }
base {
archivesName = mod_id
}

// All jar files from this folder will be added automatically as runtime mod dependencies
def extraModsDir = "extra-mods"
// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
java.toolchain.languageVersion = JavaLanguageVersion.of(17)

repositories {
flatDir {
name "extra-mods"
dir file(extraModsDir)
//minecraft.accessTransformers.entry public net.minecraft.client.Minecraft textureManager # textureManager

// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
// applies to all the run configs below
configureEach {
// 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.
systemProperty '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
systemProperty 'forge.logging.console.level', 'debug'

modSource project.sourceSets.main
}

maven {
name "ModMaven"
url "https://modmaven.k-4u.nl"
content {
includeGroup("mezz.jei")
}
client {
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
}

maven { url = "https://maven.architectury.dev" }
server {
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
programArgument '--nogui'
}

maven {
url "https://www.cursemaven.com"
content {
includeGroup "curse.maven"
}
// 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 {
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
}

data {
// example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it
// workingDirectory project.file('run-data')

// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
}
}

// Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' }

dependencies {
minecraft "net.neoforged:forge:${mc_version}-${forge_version}"
// Specify the version of Minecraft to use.
// Depending on the plugin applied there are several options. We will assume you applied the userdev plugin as shown above.
// The group for userdev is net.neoforged, the module name is neoforge, and the version is the same as the neoforge version.
// You can however also use the vanilla plugin (net.neoforged.gradle.vanilla) to use a version of Minecraft without the neoforge loader.
// 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.
// For all intends and purposes: You can treat this dependency as if it is a normal library you would use.
implementation "net.neoforged:neoforge:${neo_version}"

//AE2
//compileOnly "appeng:appliedenergistics2-neoforge:${ae2_version}:api"
//runtimeOnly "appeng:appliedenergistics2-neoforge:${ae2_version}"

//Curios
//runtimeOnly "top.theillusivec4.curios:curios-neoforge:${curios_version}"
//compileOnly "top.theillusivec4.curios:curios-neoforge:${curios_version}:api"

// Example mod dependency with JEI
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
compileOnly "mezz.jei:jei-${minecraft_version}-common-api:${jei_version}"
compileOnly "mezz.jei:jei-${minecraft_version}-forge-api:${jei_version}"
runtimeOnly "mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}"

// Locally sourced extra mods for runtime (i.e. testing)
for (extraModJar in fileTree(dir: extraModsDir, include: '*.jar')) {
Expand All @@ -106,139 +140,66 @@ dependencies {
assert versionSep != -1
def artifactId = basename.substring(0, versionSep)
def version = basename.substring(versionSep + 1)
runtimeOnly fg.deobf("extra-mods:$artifactId:$version")
runtimeOnly "extra-mods:$artifactId:$version"
}

//JEI
// compile against the JEI API but do not include it at runtime
compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}")
compileOnly fg.deobf("mezz.jei:jei-${mc_version}-forge-api:${jei_version}")
// at runtime, use the full JEI jar
runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}-forge:${jei_version}")

// runtimeOnly fg.deobf("curse.maven:inventory-tweaks-renewed:3102237")
// runtimeOnly fg.deobf("curse.maven:lollipop-347954:3232534")
// runtimeOnly fg.deobf("curse.maven:mekanism-268560:268560")

runtimeOnly fg.deobf("curse.maven:charging-gadgets-399757:4617304")
}
// Locally sourced extra mods for compiling (i.e. API)
for (extraModJar in fileTree(dir: extraAPIDir, include: '*.jar')) {
def basename = extraModJar.name.substring(0, extraModJar.name.length() - ".jar".length())
def versionSep = basename.lastIndexOf('-')
assert versionSep != -1
def artifactId = basename.substring(0, versionSep)
def version = basename.substring(versionSep + 1)
compileOnly "extra-api:$artifactId:$version"
}

processResources {
duplicatesStrategy = DuplicatesStrategy.INHERIT
// 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 "blank:coolmod-${mc_version}:${coolmod_version}"

inputs.property "version", project.version
// Example mod dependency using a file as dependency
// implementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar")

filesMatching("META-INF/mods.toml") {
expand "version": project.version,
"mcversion": project.mc_version,
"forgeversion": project.forge_version,
"forgeshortversion": project.forge_version.split('\\.')[0],
"forge_acceptable_range": project.forge_acceptable_range
}
// Example project dependency using a sister or child project:
// implementation project(":myproject")

doLast {
def jsonMinifyStart = System.currentTimeMillis()
def jsonMinified = 0
def jsonBytesSaved = 0

fileTree(dir: outputs.files.asPath, include: '**/*.json').each {
File file = it
jsonMinified++
def oldLength = file.length()
try {
file.text = JsonOutput.toJson(new JsonSlurper().parse(file))
jsonBytesSaved += oldLength - file.length()
} catch (Exception e) {
println('Failed to minify ' + it + ' ' + e)
}
}

println('Minified ' + jsonMinified + ' json files. Saved ' + jsonBytesSaved + ' bytes. Took ' + (System.currentTimeMillis() - jsonMinifyStart) + 'ms.')
}
// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
}

jar {
manifest {
attributes([
"Specification-Title": "mininggadgets",
"Specification-Vendor": "direwolf20",
"Specification-Version": "1", // We are version 1 of ourselves
"Implementation-Title": project.name,
"Implementation-Version": "${version}",
"Implementation-Vendor" :"direwolf20",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
// 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.withType(ProcessResources).configureEach {
var replaceProperties = [
minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range,
neo_version : neo_version, neo_version_range: neo_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,
]
inputs.properties replaceProperties

filesMatching(['META-INF/mods.toml']) {
expand replaceProperties + [project: project]
}
}

jar.finalizedBy('reobfJar')

// Example configuration to allow publishing using the maven-publish plugin
publishing {
publications {
maven(MavenPublication) {
register('mavenJava', MavenPublication) {
from components.java
artifactId = project.archivesBaseName.toLowerCase()
}
}
}

def makeChangelog() {
def changelogText = file("./CHANGELOG.md").text;

def output = "";
def readLines = false
for (line in changelogText.lines()) {
if (line.startsWith("### ") || line.startsWith("## ")) {
if (readLines) {
break;
}

if (line.contains("${mod_version}") && line.startsWith("### ")) {
readLines = true;
}
}
if (readLines) {
output += line + "\n";
}
}

return output.trim();
}


tasks.register("testChangelog") {
group = "tests"

doLast {
println makeChangelog()
}
}

publishMods {
dryRun = providers.environmentVariable("CURSE_TOKEN").getOrNull() == null
file = jar.archiveFile
changelog = makeChangelog()
type = STABLE

modLoaders.add("neoforge")
modLoaders.add("forge")

curseforge {
projectId = "351748"
accessToken = providers.environmentVariable("CURSE_TOKEN")
minecraftVersions.add(project.mc_version)

optional {
slug = "charging-gadgets"
repositories {
maven {
url "file://${project.projectDir}/repo"
}
}

github {
repository = "direwolf20-mc/MiningGadgets"
accessToken = providers.environmentVariable("GITHUB_TOKEN")
commitish = providers.environmentVariable("GITHUB_SHA").orElse("dryRun")
tagName = providers.environmentVariable("GITHUB_REF_NAME").orElse("dryRun")
}
}

tasks.withType(JavaCompile).configureEach {
Expand Down
Loading

0 comments on commit 595795a

Please sign in to comment.