├── assets └── sprites │ └── frog.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── mod.hjson ├── .github └── workflows │ └── commitTest.yml ├── gradle.properties ├── src └── example │ └── ExampleJavaMod.java ├── gradlew.bat ├── .gitignore ├── README.md └── gradlew /assets/sprites/frog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Anuken/MindustryJavaModTemplate/HEAD/assets/sprites/frog.png -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Anuken/MindustryJavaModTemplate/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 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 6 | -------------------------------------------------------------------------------- /mod.hjson: -------------------------------------------------------------------------------- 1 | #the mod name as displayed in-game 2 | displayName: "Java Mod Template" 3 | 4 | #the internal name of your mod 5 | name: "example-java-mod" 6 | 7 | #your name 8 | author: "You" 9 | 10 | #the fully qualified main class of the mod 11 | main: "example.ExampleJavaMod" 12 | 13 | #the mod description as seen in the mod dialog 14 | description: "A Mindustry Java mod template." 15 | 16 | #the mod version 17 | version: 1.0 18 | 19 | #the minimum game build required to run this mod 20 | minGameVersion: 150 21 | 22 | #this is a java mod 23 | java: true 24 | -------------------------------------------------------------------------------- /.github/workflows/commitTest.yml: -------------------------------------------------------------------------------- 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 27 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /src/example/ExampleJavaMod.java: -------------------------------------------------------------------------------- 1 | package example; 2 | 3 | import arc.*; 4 | import arc.util.*; 5 | import mindustry.*; 6 | import mindustry.content.*; 7 | import mindustry.game.EventType.*; 8 | import mindustry.gen.*; 9 | import mindustry.mod.*; 10 | import mindustry.ui.dialogs.*; 11 | 12 | public class ExampleJavaMod extends Mod{ 13 | 14 | public ExampleJavaMod(){ 15 | Log.info("Loaded ExampleJavaMod constructor."); 16 | 17 | //listen for game load event 18 | Events.on(ClientLoadEvent.class, e -> { 19 | //show dialog upon startup 20 | Time.runTask(10f, () -> { 21 | BaseDialog dialog = new BaseDialog("frog"); 22 | dialog.cont.add("behold").row(); 23 | //mod sprites are prefixed with the mod name (this mod is called 'example-java-mod' in its config) 24 | dialog.cont.image(Core.atlas.find("example-java-mod-frog")).pad(20f).row(); 25 | dialog.cont.button("I see", dialog::hide).size(100f, 50f); 26 | dialog.show(); 27 | }); 28 | }); 29 | } 30 | 31 | @Override 32 | public void loadContent(){ 33 | Log.info("Loading some example content."); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 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/ 158 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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.* 40 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | --------------------------------------------------------------------------------