diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ebbc2b6 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,19 @@ +# This is the universal Text Editor Configuration +# for all GTNewHorizons projects +# See: https://editorconfig.org/ + +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.{bat,ini}] +end_of_line = crlf + +[*.{dtd,json,mcmeta,md,sh,svg,xml,xsd,xsl,yaml,yml}] +indent_size = 2 diff --git a/.github/scripts/test-no-error-reports.sh b/.github/scripts/test-no-error-reports.sh index e387660..84c1e5d 100755 --- a/.github/scripts/test-no-error-reports.sh +++ b/.github/scripts/test-no-error-reports.sh @@ -1,22 +1,28 @@ -if [[ -d "run/crash-reports" ]]; then +#!/usr/bin/env bash + +RUNDIR="run" +CRASH="crash-reports" +SERVERLOG="server.log" + +if [[ -d $RUNDIR/$CRASH ]]; then echo "Crash reports detected:" - cat $directory/* + cat $RUNDIR/$CRASH/crash*.txt exit 1 fi -if grep --quiet "Fatal errors were detected" server.log; then +if grep --quiet "Fatal errors were detected" $SERVERLOG; then echo "Fatal errors detected:" cat server.log exit 1 fi -if grep --quiet "The state engine was in incorrect state ERRORED and forced into state SERVER_STOPPED" server.log; then +if grep --quiet "The state engine was in incorrect state ERRORED and forced into state SERVER_STOPPED" $SERVERLOG; then echo "Server force stopped:" cat server.log exit 1 fi -if grep --quiet 'Done .+ For help, type "help" or "?"' server.log; then +if ! grep --quiet -Po '.+Done \(.+\)\! For help, type "help" or "\?"' $SERVERLOG; then echo "Server didn't finish startup:" cat server.log exit 1 diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 08df9fe..2a74327 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -14,16 +14,16 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - with: + with: fetch-depth: 0 - + - name: Set up JDK 8 uses: actions/setup-java@v2 with: java-version: '8' distribution: 'adopt' cache: gradle - + - name: Grant execute permission for gradlew run: chmod +x gradlew @@ -36,8 +36,8 @@ jobs: - name: Run server for 1.5 minutes run: | mkdir run - echo "eula=true" > run/eula.txt - timeout 90 ./gradlew runServer | tee --append server.log || true + echo "eula=true" > run/eula.txt + timeout 90 ./gradlew runServer 2>&1 | tee -a server.log || true - name: Test no errors reported during server run run: | diff --git a/.github/workflows/release-packages-latest.yml b/.github/workflows/release-packages-latest.yml index 1f1b162..bd553e5 100644 --- a/.github/workflows/release-packages-latest.yml +++ b/.github/workflows/release-packages-latest.yml @@ -38,8 +38,8 @@ jobs: -x "README.md" \ -x "LICENSE" \ \ - -x "starter.zip" \ - -x "migration.zip" + -x "packages/starter.zip" \ + -x "packages/migration.zip" - name: Zip migration uses: montudor/action-zip@v1 @@ -59,8 +59,8 @@ jobs: -x "LICENSE" \ -x "README.md" \ \ - -x "starter.zip" \ - -x "migration.zip" + -x "packages/starter.zip" \ + -x "packages/migration.zip" - name: Update latest tag uses: "marvinpinto/action-automatic-releases@latest" diff --git a/.github/workflows/release-packages-tags.yml b/.github/workflows/release-packages-tags.yml index c256222..1bd8a6a 100644 --- a/.github/workflows/release-packages-tags.yml +++ b/.github/workflows/release-packages-tags.yml @@ -38,8 +38,8 @@ jobs: -x "README.md" \ -x "LICENSE" \ \ - -x "starter.zip" \ - -x "migration.zip" + -x "packages/starter.zip" \ + -x "packages/migration.zip" - name: Zip migration uses: montudor/action-zip@v1 @@ -60,8 +60,8 @@ jobs: -x "LICENSE" \ -x "README.md" \ \ - -x "starter.zip" \ - -x "migration.zip" + -x "packages/starter.zip" \ + -x "packages/migration.zip" - name: Release under current tag uses: "marvinpinto/action-automatic-releases@latest" diff --git a/.gitignore b/.gitignore index 75c41f6..48c525b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .gradle .settings /.idea/ +/.vscode/ /run/ /build/ /eclipse/ diff --git a/README.md b/README.md index 9433f64..c23fbec 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Example Forge Mod for Minecraft 1.7.10 [![](https://jitpack.io/v/GTNewHorizons/ExampleMod1.7.10.svg)](https://jitpack.io/#GTNewHorizons/ExampleMod1.7.10) -[![](https://github.com/GTNewHorizons/ExampleMod1.7.10/actions/workflows/gradle.yml/badge.svg)](https://github.com/GTNewHorizons/ExampleMod1.7.10/actions/workflows/gradle.yml) +[![](https://github.com/GTNewHorizons/ExampleMod1.7.10/actions/workflows/build-and-test.yml/badge.svg)](https://github.com/GTNewHorizons/ExampleMod1.7.10/actions/workflows/build-and-test.yml) An example mod for Minecraft 1.7.10 with Forge focussed on a stable, updatable setup. @@ -45,7 +45,7 @@ We also have described guidelines for existing mod [migration](docs/migration.md ### Files - [`build.gradle`](https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/build.gradle): This is the core script of the build process. You should not need to tamper with it, unless you are trying to accomplish something out of the ordinary. __Do not touch this file! You will make a future update near impossible if you do so!__ - - [`gradle.properties`](https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/gradle.properties): The core configuration file. It includes + - [`gradle.properties`](https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/gradle.properties): The core configuration file. It includes - [`dependencies.gradle`](https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/dependencies.gradle): Add your mod's dependencies in this file. This is separate from the main build script, so you may replace the [`build.gradle`](https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradle) if an update is available. - [`repositories.gradle`](https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/repositories.gradle): Add your dependencies' repositories. This is separate from the main build script, so you may replace the [`build.gradle`](https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/build.gradle) if an update is available. - [`jitpack.yml`](https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/jitpack.yml): Ensures that your mod is available as import over [Jitpack](https://jitpack.io). @@ -55,7 +55,7 @@ We also have described guidelines for existing mod [migration](docs/migration.md You may activate Forge's Access Transformers by defining a configuration file in `gradle.properties`. -Check out the [`example-access-transformers`](https://github.com/SinTh0r4s/ExampleMod1.7.10/tree/example-access-transformers) brach for a working example! +Check out the [`example-access-transformers`](https://github.com/GTNewHorizons/ExampleMod1.7.10/tree/example-access-transformers) brach for a working example! __Warning:__ Access Transformers are bugged and will deny you any sources for the decompiled minecraft! Your development environment will still work, but you might face some inconveniences. For example, IntelliJ will not permit searches in dependencies without attached sources. @@ -64,9 +64,9 @@ __Warning:__ Access Transformers are bugged and will deny you any sources for th Mixins are usually used to modify vanilla or mod/library in runtime without having to change source code. For example, redirect a call, change visibility or make class implement your interface. It's an advanced topic and most mods don't need to do that. You can activate Mixin in 'gradle.properties'. In that case a mixin configuration (usually named `mixins.mymodid.json`) will be generated automatically, and you only have to write the mixins itself. Dependencies are handled as well. -Take a look at the examples in [`com.myname.mymodid.mixinplugin.*`](https://github.com/SinTh0r4s/ExampleMod1.7.10/tree/example-mixins/src/main/java/com/myname/mymodid/mixinplugin) and [`com.myname.mymodid.mixins.*`](https://github.com/SinTh0r4s/ExampleMod1.7.10/tree/example-mixins/src/main/java/com/myname/mymodid/mixins). +Take a look at the examples in [`com.myname.mymodid.mixinplugin.*`](https://github.com/GTNewHorizons/ExampleMod1.7.10/tree/example-mixins/src/main/java/com/myname/mymodid/mixinplugin) and [`com.myname.mymodid.mixins.*`](https://github.com/GTNewHorizons/ExampleMod1.7.10/tree/example-mixins/src/main/java/com/myname/mymodid/mixins). -Check out the [`example-mixins`](https://github.com/SinTh0r4s/ExampleMod1.7.10/tree/example-mixins) brach for a working example! +Check out the [`example-mixins`](https://github.com/GTNewHorizons/ExampleMod1.7.10/tree/example-mixins) brach for a working example! ### Advanced diff --git a/build.gradle b/build.gradle index 3d3fd92..db31851 100644 --- a/build.gradle +++ b/build.gradle @@ -1,4 +1,4 @@ -//version: 1644510936 +//version: 1644612407 /* DO NOT CHANGE THIS FILE! @@ -6,7 +6,7 @@ Also, you may replace this file at any time if there is an update available. Please check https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/build.gradle for updates. */ -import org.gradle.internal.logging.text.StyledTextOutput +import org.gradle.internal.logging.text.StyledTextOutput import org.gradle.internal.logging.text.StyledTextOutputFactory import org.gradle.internal.logging.text.StyledTextOutput.Style @@ -45,20 +45,21 @@ plugins { id 'eclipse' id 'scala' id 'maven-publish' - id('org.jetbrains.kotlin.jvm') version ('1.6.10') apply false - id('org.ajoberstar.grgit') version('4.1.1') - id('com.github.johnrengelman.shadow') version('4.0.4') - id('com.palantir.git-version') version('0.13.0') apply false - id('de.undercouch.download') version('5.0.1') + id 'forge' + id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false + id 'org.jetbrains.kotlin.kapt' version '1.5.30' apply false + id 'org.ajoberstar.grgit' version '4.1.1' + id 'com.github.johnrengelman.shadow' version '4.0.4' + id 'com.palantir.git-version' version '0.13.0' apply false + id 'de.undercouch.download' version '5.0.1' + id 'com.github.gmazzo.buildconfig' version '3.0.3' apply false } if (project.file('.git/HEAD').isFile()) { apply plugin: 'com.palantir.git-version' } -def out = services.get(StyledTextOutputFactory).create("an-output") - -apply plugin: 'forge' +def out = services.get(StyledTextOutputFactory).create('an-output') def projectJavaVersion = JavaLanguageVersion.of(8) @@ -173,7 +174,7 @@ configurations.all { try { 'git config core.fileMode false'.execute() } -catch (Exception e) { +catch (Exception ignored) { out.style(Style.Failure).println("git isn't installed at all") } @@ -183,19 +184,21 @@ String versionOverride = System.getenv("VERSION") ?: null try { identifiedVersion = versionOverride == null ? gitVersion() : versionOverride } -catch (Exception e) { +catch (Exception ignored) { out.style(Style.Failure).text( 'This mod must be version controlled by Git AND the repository must provide at least one tag,\n' + - 'or the VERSION override must be set! ').style(Style.SuccessHeader).text('(Do NOT download from GitHub using the ZIP option, instead\n' + + 'or the VERSION override must be set! ').style(Style.SuccessHeader).text('(Do NOT download from GitHub using the ZIP option, instead\n' + 'clone the repository, see ').style(Style.Info).text('https://gtnh.miraheze.org/wiki/Development').style(Style.SuccessHeader).println(' for details.)' ) versionOverride = 'NO-GIT-TAG-SET' identifiedVersion = versionOverride } version = minecraftVersion + '-' + identifiedVersion -String modVersion = identifiedVersion +ext { + modVersion = identifiedVersion +} -if( identifiedVersion.equals(versionOverride) ) { +if(identifiedVersion == versionOverride) { out.style(Style.Failure).text('Override version to ').style(Style.Identifier).text(modVersion).style(Style.Failure).println('!\7') } @@ -207,7 +210,6 @@ else { archivesBaseName = modId } - def arguments = [] def jvmArguments = [] @@ -221,8 +223,8 @@ if(usesMixins.toBoolean()) { } minecraft { - version = minecraftVersion + "-" + forgeVersion + "-" + minecraftVersion - runDir = "run" + version = minecraftVersion + '-' + forgeVersion + '-' + minecraftVersion + runDir = 'run' if (replaceGradleTokenInFile) { replaceIn replaceGradleTokenInFile @@ -255,8 +257,8 @@ minecraft { } } -if(file("addon.gradle").exists()) { - apply from: "addon.gradle" +if(file('addon.gradle').exists()) { + apply from: 'addon.gradle' } apply from: 'repositories.gradle' @@ -304,7 +306,7 @@ dependencies { apply from: 'dependencies.gradle' -def mixingConfigRefMap = "mixins." + modId + ".refmap.json" +def mixingConfigRefMap = 'mixins.' + modId + '.refmap.json' def refMap = "${tasks.compileJava.temporaryDir}" + File.separator + mixingConfigRefMap def mixinSrg = "${tasks.reobf.temporaryDir}" + File.separator + "mixins.srg" @@ -408,12 +410,11 @@ tasks.withType(JavaExec).configureEach { ) } -processResources -{ +processResources { // this will ensure that this task is redone when the versions change. inputs.property "version", project.version inputs.property "mcversion", project.minecraft.version - + // replace stuff in mcmod.info, nothing else from(sourceSets.main.resources.srcDirs) { include 'mcmod.info' @@ -437,7 +438,7 @@ processResources def getManifestAttributes() { def manifestAttributes = [:] - if(containsMixinsAndOrCoreModOnly.toBoolean() == false && (usesMixins.toBoolean() || coreModClass)) { + if(!containsMixinsAndOrCoreModOnly.toBoolean() && (usesMixins.toBoolean() || coreModClass)) { manifestAttributes += ["FMLCorePluginContainsFMLMod": true] } @@ -453,7 +454,7 @@ def getManifestAttributes() { manifestAttributes += [ "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "MixinConfigs" : "mixins." + modId + ".json", - "ForceLoadAsMod" : containsMixinsAndOrCoreModOnly.toBoolean() == false + "ForceLoadAsMod" : !containsMixinsAndOrCoreModOnly.toBoolean() ] } return manifestAttributes @@ -540,7 +541,7 @@ artifacts { } } -// The gradle metadata includes all of the additional deps that we disabled from POM generation (including forgeBin with no groupID), +// The gradle metadata includes all of the additional deps that we disabled from POM generation (including forgeBin with no groupID), // and isn't strictly needed with the POM so just disable it. tasks.withType(GenerateModuleMetadata) { enabled = false @@ -565,17 +566,17 @@ publishing { artifactId = System.getenv("ARTIFACT_ID") ?: project.name // Using the identified version, not project.version as it has the prepended 1.7.10 version = System.getenv("RELEASE_VERSION") ?: identifiedVersion - + // remove extra garbage from who knows where pom.withXml { def badPomGroup = ['net.minecraft', 'com.google.code.findbugs', 'org.ow2.asm', 'com.typesafe.akka', 'com.typesafe', 'org.scala-lang', 'org.scala-lang.plugins', 'net.sf.jopt-simple', 'lzma', 'com.mojang', 'org.apache.commons', 'org.apache.httpcomponents', - 'commons-logging', 'java3d', 'net.sf.trove4j', 'com.ibm.icu', 'com.paulscode', 'io.netty', 'com.google.guava', - 'commons-io', 'commons-codec', 'net.java.jinput', 'net.java.jutils', 'com.google.code.gson', 'org.apache.logging.log4j', - 'org.lwjgl.lwjgl', 'tv.twitch', ''] + 'commons-logging', 'java3d', 'net.sf.trove4j', 'com.ibm.icu', 'com.paulscode', 'io.netty', 'com.google.guava', + 'commons-io', 'commons-codec', 'net.java.jinput', 'net.java.jutils', 'com.google.code.gson', 'org.apache.logging.log4j', + 'org.lwjgl.lwjgl', 'tv.twitch', 'org.jetbrains.kotlin', ''] Node pomNode = asNode() pomNode.dependencies.'*'.findAll() { - badPomGroup.contains(it.groupId.text()) + badPomGroup.contains(it.groupId.text()) }.each() { it.parent().remove(it) } @@ -688,7 +689,7 @@ def deobf(String sourceURL, String fileName) { String bon2File = bon2Dir + "/BON2-2.5.0.jar" String obfFile = cacheDir + "modules-2/files-2.1/" + fileName + ".jar" String deobfFile = cacheDir + "modules-2/files-2.1/" + fileName + "-deobf.jar" - + if(file(deobfFile).exists()) { return files(deobfFile) } @@ -719,7 +720,7 @@ def deobf(String sourceURL, String fileName) { // Helper methods def checkPropertyExists(String propertyName) { - if (project.hasProperty(propertyName) == false) { + if (!project.hasProperty(propertyName)) { throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/GTNewHorizons/ExampleMod1.7.10/blob/main/gradle.properties") } } diff --git a/docs/porting.md b/docs/porting.md index 28de4af..4d63968 100644 --- a/docs/porting.md +++ b/docs/porting.md @@ -38,7 +38,7 @@ After all these preparations nothing should be in the way of porting the mod, th Good approach is to start working with smaller things first, building up your confidence in how the mod works and gradually approaching more complex stuff, here is a general algorithm: 1. Begin with fixing moved/renamed things by deleting all bad imports and with help of the IDE re-import equivalents if present. - Intelij IDEA has settings for unambiguous auto-import and import optimization on the fly, which can greatly speedup the process. Just pay attention to what is actually imported. + Intelij IDEA has settings for unambiguous auto-import and import optimization on the fly, which can greatly speedup the process. Just pay attention to what is actually imported. 2. Remove all nonworking code which is not easily fixable (e.g., class only introduced in newer forge) and provide stubs in its place. For example, replace reference to method of non existing class with your method in your class, it can have an empty body and mocked return so the code can compile and run without issues. Do not forget to track all things you've stubbed, if you are working on port alone - TODOs should be sufficient (most IDEs have a built in TODO browser). diff --git a/src/main/java/com/myname/mymodid/Config.java b/src/main/java/com/myname/mymodid/Config.java index 09a54f3..33136b9 100644 --- a/src/main/java/com/myname/mymodid/Config.java +++ b/src/main/java/com/myname/mymodid/Config.java @@ -6,7 +6,7 @@ import net.minecraftforge.common.config.Property; import java.io.File; public class Config { - + private static class Defaults { public static final String greeting = "Hello World"; } @@ -14,13 +14,13 @@ public class Config { private static class Categories { public static final String general = "general"; } - + public static String greeting = Defaults.greeting; public static void syncronizeConfiguration(File configFile) { Configuration configuration = new Configuration(configFile); configuration.load(); - + Property greetingProperty = configuration.get(Categories.general, "greeting", Defaults.greeting, "How shall I greet?"); greeting = greetingProperty.getString(); diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index c226201..e61cddf 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -1,16 +1,21 @@ -[ - { - "modid": "${modId}", - "name": "${modName}", - "description": "An example mod for Minecraft 1.7.10 with Forge focussed on a stable setup.", - "version": "${modVersion}", - "mcversion": "${minecraftVersion}", - "url": "https://github.com/SinTh0r4s/MyMod", - "updateUrl": "", - "authorList": ["SinTho0r4s"], - "credits": "", - "logoFile": "", - "screenshots": [], - "dependencies": [] - } -] +{ + "modListVersion": 2, + "modList": [{ + "modid": "${modId}", + "name": "${modName}", + "description": "An example mod for Minecraft 1.7.10 with Forge focused on a stable setup.", + "version": "${modVersion}", + "mcversion": "${minecraftVersion}", + "url": "https://github.com/SinTh0r4s/MyMod", + "updateUrl": "", + "authorList": ["SinTho0r4s"], + "credits": "", + "logoFile": "", + "screenshots": [], + "parent": "", + "requiredMods": [], + "dependencies": [], + "dependants": [], + "useDependencyInformation": true + }] +}