Skip to content

Commit be499bc

Browse files
authored
Initial commit
0 parents  commit be499bc

12 files changed

Lines changed: 668 additions & 0 deletions

File tree

.github/workflows/commitTest.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Build Mod
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
buildJar:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Set up PATH
12+
run: |
13+
echo "${ANDROID_HOME}/build-tools/34.0.0" >> $GITHUB_PATH
14+
- name: Set up JDK 17
15+
uses: actions/setup-java@v1
16+
with:
17+
java-version: 17
18+
- name: Build mod jar
19+
run: |
20+
chmod +x ./gradlew
21+
./gradlew deploy
22+
- name: Upload built jar file
23+
uses: actions/upload-artifact@v4
24+
with:
25+
name: ${{ github.event.repository.name }}
26+
path: build/libs/${{ github.event.repository.name }}.jar

.gitignore

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
logs/
2+
/core/assets/mindustry-saves/
3+
/core/assets/mindustry-maps/
4+
/core/assets/bundles/output/
5+
/core/assets/.gifimages/
6+
/deploy/
7+
/desktop/packr-out/
8+
/desktop/packr-export/
9+
/desktop/mindustry-saves/
10+
/desktop/mindustry-maps/
11+
/desktop/gifexport/
12+
/core/lib/
13+
/ios/assets/
14+
/core/assets-raw/sprites/generated/
15+
/core/assets-raw/sprites_out/
16+
/annotations/build/
17+
/annotations/out/
18+
/net/build/
19+
/tools/build/
20+
/tests/build/
21+
/server/build/
22+
/test_files/
23+
/annotations/build/
24+
/desktop-sdl/build/
25+
desktop-sdl/build/
26+
/android/assets/mindustry-maps/
27+
/android/assets/mindustry-saves/
28+
/core/assets/gifexport/
29+
/core/assets/version.properties
30+
/core/assets/locales
31+
/ios/src/io/anuke/mindustry/gen/
32+
/core/src/io/anuke/mindustry/gen/
33+
ios/robovm.properties
34+
packr-out/
35+
config/
36+
*.gif
37+
38+
version.properties
39+
40+
.attach_*
41+
## Java
42+
43+
*.class
44+
*.war
45+
*.ear
46+
hs_err_pid*
47+
crash-report-*
48+
replay_pid*
49+
50+
## Robovm
51+
/ios/robovm-build/
52+
53+
## GWT
54+
/html/war/
55+
/html/gwt-unitCache/
56+
.apt_generated/
57+
.gwt/
58+
gwt-unitCache/
59+
www-test/
60+
.gwt-tmp/
61+
62+
## Android Studio and Intellij and Android in general
63+
/android/libs/armeabi/
64+
/android/libs/armeabi-v7a/
65+
/android/libs/arm64-v8a/
66+
/android/libs/x86/
67+
/android/libs/x86_64/
68+
/android/gen/
69+
.idea/
70+
*.ipr
71+
*.iws
72+
*.iml
73+
/android/out/
74+
com_crashlytics_export_strings.xml
75+
76+
## Eclipse
77+
78+
.classpath
79+
.project
80+
.metadata/
81+
/android/bin/
82+
/core/bin/
83+
/desktop/bin/
84+
/html/bin/
85+
/ios/bin/
86+
/ios-moe/bin/
87+
*.tmp
88+
*.bak
89+
*.swp
90+
*~.nib
91+
.settings/
92+
.loadpath
93+
.externalToolBuilders/
94+
*.launch
95+
96+
## NetBeans
97+
98+
/nbproject/private/
99+
/android/nbproject/private/
100+
/core/nbproject/private/
101+
/desktop/nbproject/private/
102+
/html/nbproject/private/
103+
/ios/nbproject/private/
104+
/ios-moe/nbproject/private/
105+
106+
/build/
107+
/android/build/
108+
/core/build/
109+
/desktop/build/
110+
/html/build/
111+
/ios/build/
112+
/ios-moe/build/
113+
114+
/nbbuild/
115+
/android/nbbuild/
116+
/core/nbbuild/
117+
/desktop/nbbuild/
118+
/html/nbbuild/
119+
/ios/nbbuild/
120+
/ios-moe/nbbuild/
121+
122+
/dist/
123+
/android/dist/
124+
/core/dist/
125+
/desktop/dist/
126+
/html/dist/
127+
/ios/dist/
128+
/ios-moe/dist/
129+
130+
/nbdist/
131+
/android/nbdist/
132+
/core/nbdist/
133+
/desktop/nbdist/
134+
/html/nbdist/
135+
/ios/nbdist/
136+
/ios-moe/nbdist/
137+
138+
nbactions.xml
139+
nb-configuration.xml
140+
141+
## Gradle
142+
143+
/local.properties
144+
.gradle/
145+
gradle-app.setting
146+
/build/
147+
/android/build/
148+
/core/build/
149+
/desktop/build/
150+
/html/build/
151+
/ios/build/
152+
/ios-moe/build/
153+
154+
## OS Specific
155+
.DS_Store
156+
Thumbs.db
157+
android/libs/

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Mindustry Java Mod Template
2+
A Java Mindustry mod template that works on Android and PC. The Kotlin version of this mod can be seen [here](https://github.com/Anuken/MindustryKotlinModTemplate).
3+
4+
## Building for Desktop Testing
5+
6+
1. Install JDK **17**.
7+
2. Run `gradlew jar` [1].
8+
3. Your mod jar will be in the `build/libs` directory. **Only use this version for testing on desktop. It will not work with Android.**
9+
To build an Android-compatible version, you need the Android SDK. You can either let Github Actions handle this, or set it up yourself. See steps below.
10+
11+
## Building through Github Actions
12+
13+
This repository is set up with Github Actions CI to automatically build the mod for you every commit. This requires a Github repository, for obvious reasons.
14+
To get a jar file that works for every platform, do the following:
15+
1. Make a Github repository with your mod name, and upload the contents of this repo to it. Perform any modifications necessary, then commit and push.
16+
2. Check the "Actions" tab on your repository page. Select the most recent commit in the list. If it completed successfully, there should be a download link under the "Artifacts" section.
17+
3. Click the download link (should be the name of your repo). This will download a **zipped jar** - **not** the jar file itself [2]! Unzip this file and import the jar contained within in Mindustry. This version should work both on Android and Desktop.
18+
19+
## Building Locally
20+
21+
Building locally takes more time to set up, but shouldn't be a problem if you've done Android development before.
22+
1. Download the Android SDK, unzip it and set the `ANDROID_HOME` environment variable to its location.
23+
2. Make sure you have API level 30 installed, as well as any recent version of build tools (e.g. 30.0.1)
24+
3. Add a build-tools folder to your PATH. For example, if you have `30.0.1` installed, that would be `$ANDROID_HOME/build-tools/30.0.1`.
25+
4. Run `gradlew deploy`. If you did everything correctlly, this will create a jar file in the `build/libs` directory that can be run on both Android and desktop.
26+
27+
## Adding Dependencies
28+
29+
Please note that all dependencies on Mindustry, Arc or its submodules **must be declared as compileOnly in Gradle**. Never use `implementation` for core Mindustry or Arc dependencies.
30+
31+
- `implementation` **places the entire dependency in the jar**, which is, in most mod dependencies, very undesirable. You do not want the entirety of the Mindustry API included with your mod.
32+
- `compileOnly` means that the dependency is only around at compile time, and not included in the jar.
33+
34+
Only use `implementation` if you want to package another Java library *with your mod*, and that library is not present in Mindustry already.
35+
36+
---
37+
38+
*[1]* *On Linux/Mac it's `./gradlew`, but if you're using Linux I assume you know how to run executables properly anyway.*
39+
*[2]: Yes, I know this is stupid. It's a Github UI limitation - while the jar itself is uploaded unzipped, there is currently no way to download it as a single file.*

assets/sprites/frog.png

39.7 KB
Loading

build.gradle

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
apply plugin: "java"
2+
3+
version '1.0'
4+
5+
sourceSets.main.java.srcDirs = ["src"]
6+
7+
repositories{
8+
mavenCentral()
9+
maven{ url "https://raw.githubusercontent.com/Zelaux/MindustryRepo/master/repository" }
10+
maven{ url 'https://www.jitpack.io' }
11+
}
12+
13+
java{
14+
targetCompatibility = 8
15+
sourceCompatibility = JavaVersion.VERSION_17
16+
}
17+
18+
ext{
19+
//the build number that this mod is made for
20+
mindustryVersion = 'v150.1'
21+
jabelVersion = "93fde537c7"
22+
//windows sucks
23+
isWindows = System.getProperty("os.name").toLowerCase().contains("windows")
24+
sdkRoot = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT")
25+
modDir = "${System.getenv("APPDATA")}\\Mindustry\\mods"
26+
}
27+
28+
//java 8 backwards compatibility flag
29+
allprojects{
30+
tasks.withType(JavaCompile){
31+
options.compilerArgs.addAll(['--release', '8'])
32+
}
33+
}
34+
35+
dependencies{
36+
compileOnly "com.github.Anuken.Arc:arc-core:$mindustryVersion"
37+
compileOnly "com.github.Anuken.Mindustry:core:$mindustryVersion"
38+
39+
annotationProcessor "com.github.Anuken:jabel:$jabelVersion"
40+
}
41+
42+
//force arc version
43+
configurations.all{
44+
resolutionStrategy.eachDependency { details ->
45+
if(details.requested.group == 'com.github.Anuken.Arc'){
46+
details.useVersion "$mindustryVersion"
47+
}
48+
}
49+
}
50+
51+
task jarAndroid{
52+
dependsOn "jar"
53+
54+
doLast{
55+
if(!sdkRoot || !new File(sdkRoot).exists()) throw new GradleException("No valid Android SDK found. Ensure that ANDROID_HOME is set to your Android SDK directory.");
56+
57+
def platformRoot = new File("$sdkRoot/platforms/").listFiles().sort().reverse().find{ f -> new File(f, "android.jar").exists()}
58+
59+
if(!platformRoot) throw new GradleException("No android.jar found. Ensure that you have an Android platform installed.")
60+
61+
//collect dependencies needed for desugaring
62+
def dependencies = (configurations.compileClasspath.asList() + configurations.runtimeClasspath.asList() + [new File(platformRoot, "android.jar")]).collect{ "--classpath $it.path" }.join(" ")
63+
64+
def d8 = isWindows ? "d8.bat" : "d8"
65+
66+
//dex and desugar files - this requires d8 in your PATH
67+
"$d8 $dependencies --min-api 14 --output ${project.archivesBaseName}Android.jar ${project.archivesBaseName}Desktop.jar"
68+
.execute(null, new File("$buildDir/libs")).waitForProcessOutput(System.out, System.err)
69+
}
70+
}
71+
72+
jar{
73+
archiveFileName = "${base.archivesBaseName}Desktop.jar"
74+
75+
from{
76+
configurations.runtimeClasspath.collect{ it.isDirectory() ? it : zipTree(it) }
77+
}
78+
79+
from(projectDir){
80+
include "mod.hjson"
81+
}
82+
83+
from("assets/"){
84+
include "**"
85+
}
86+
}
87+
88+
task deploy(type: Jar){
89+
dependsOn jarAndroid
90+
dependsOn jar
91+
archiveFileName = "${base.archivesBaseName}.jar"
92+
93+
from{ [zipTree("$buildDir/libs/${project.archivesBaseName}Desktop.jar"), zipTree("$buildDir/libs/${project.archivesBaseName}Android.jar")] }
94+
95+
doLast{
96+
delete{
97+
delete "$buildDir/libs/${project.archivesBaseName}Desktop.jar"
98+
delete "$buildDir/libs/${project.archivesBaseName}Android.jar"
99+
}
100+
}
101+
}
102+
103+
task compileAndCopy{
104+
dependsOn jar
105+
106+
doLast{
107+
copy{
108+
from "$buildDir/libs/"
109+
into "$modDir/"
110+
include "${project.archivesBaseName}Desktop.jar"
111+
}
112+
}
113+
}

gradle.properties

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
org.gradle.jvmargs=--illegal-access=permit \
2+
--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \
3+
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
4+
--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED \
5+
--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED \
6+
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \
7+
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \
8+
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED \
9+
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \
10+
--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED \
11+
--add-exports=jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED \
12+
--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED \
13+
--add-exports=java.base/sun.reflect.annotation=ALL-UNNAMED

gradle/wrapper/gradle-wrapper.jar

54.9 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)