Skip to content

Commit

Permalink
Kotlin (GTNewHorizons#19)
Browse files Browse the repository at this point in the history
* spaces

* revert kotlin ver

* more framework for kotlin

* make it available to external consumers

* vscode

* update scripts to properly catch broken runserveR

* editor config

* fix recursive zips

* improve

* update links

* more cleanup
  • Loading branch information
bombcar authored Feb 14, 2022
1 parent ab7a0ee commit a71130d
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 77 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
16 changes: 11 additions & 5 deletions .github/scripts/test-no-error-reports.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release-packages-latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release-packages-tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.gradle
.settings
/.idea/
/.vscode/
/run/
/build/
/eclipse/
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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).
Expand All @@ -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.

Expand All @@ -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

Expand Down
69 changes: 35 additions & 34 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//version: 1644510936
//version: 1644612407
/*
DO NOT CHANGE THIS FILE!
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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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")
}

Expand 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')
}

Expand All @@ -207,7 +210,6 @@ else {
archivesBaseName = modId
}


def arguments = []
def jvmArguments = []

Expand All @@ -221,8 +223,8 @@ if(usesMixins.toBoolean()) {
}

minecraft {
version = minecraftVersion + "-" + forgeVersion + "-" + minecraftVersion
runDir = "run"
version = minecraftVersion + '-' + forgeVersion + '-' + minecraftVersion
runDir = 'run'

if (replaceGradleTokenInFile) {
replaceIn replaceGradleTokenInFile
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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'
Expand All @@ -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]
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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")
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/porting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Loading

0 comments on commit a71130d

Please sign in to comment.