|
1 | | -# `MindustryModTemplate` |
2 | | - |
3 | | -[Mindustry](https://github.com/Anuken/Mindustry) Java mod biotech, otherwise known as JAR-modding, complete with [`EntityAnno`](https://github.com/GglLfr/EntityAnno) and syntax downgrader integration, works for both Android and PC. |
4 | | - |
5 | | -## Using |
6 | | - |
7 | | -Before going into using this biotech, be aware that a fair amount of Java knowledge and Git *(GitHub Desktop is fine, but `git` CLI is a million times better)* is **highly beneficial**. Going in blind isn't impossible, but you'll face a lot of problems. Not that people on [the Discord](https://discord.gg/mindustry) won't help, though, so be communicative! |
8 | | - |
9 | | -1. Install JDK 17 or higher. Plain or terminal-based code editors are **completely *not* recommended!** Use an IDE like [IntelliJ IDEA](https://www.jetbrains.com/idea/download/); there are free Community Edition releases available, just scroll down a bit. |
10 | | -2. Click the `Use this biotech` button and create your repository. |
11 | | -3. Clone a local copy of the repository. |
12 | | - |
13 | | -> [!IMPORTANT] |
14 | | -> A **local copy** is *not* a mere ZIP archive you obtain by downloading. This is where the Git knowledge comes to play. If you have GitHub CLI or GitHub Desktop installed, the site should provide instructions on how to use either, under the `<> Code` menu. |
15 | | -> |
16 | | -> `Download ZIP` is **not** a proper way to clone your repository. |
17 | | -
|
18 | | -4. Refactor namings to your preferences. The biotech is designed in such a way that this step should only require you to modify: |
19 | | - - `gradle.properties`, the "Project configurations" section. For the "package" properties, if you don't know what you're doing, simply just change `biotech` to your preferred mod root package naming *(e.g. `mymod`, or `confictura` if your mod name is "confictura")*. |
20 | | - - `mod.json`, which is the entire metadata of your mod. |
21 | | - - `src/` folder and its contents, which is where your Java source files are stored. Rename folders, package, and class names as you prefer. Note that the main mod class' full name *(package + class)* must correspond to the `main` property in `mod.json`. |
22 | | - - `.github/workflows/ci.yml`, which is the automated Continuous Integration that runs on your GitHub repository everytime you push a commit. This automates cross-platform builds which you might find useful. You should only edit the last 2 lines about `name` and `path`. |
23 | | - |
24 | | -> [!TIP] |
25 | | -> There's no `name` property in this biotech's `mod.json`. That property is automatically filled up when building. |
26 | | -
|
27 | | - Here's an example of a properly configured mod base from the biotech, *assuming |
28 | | - "confictura" as the name*: |
29 | | - ```mermaid |
30 | | - --- |
31 | | - title: Project Hierarchy |
32 | | - --- |
33 | | - graph LR; |
34 | | - %%{init:{'flowchart':{'nodeSpacing': 10, 'rankSpacing': 10}}}%%; |
35 | | - |
36 | | - classDef folder fill:#465768,stroke:#bdcedf; |
37 | | - classDef file fill:#468868,stroke:#bdffdf; |
38 | | -
|
39 | | - root{{"/"}}; |
40 | | - github{{".github/"}}; |
41 | | - workflows{{"workflows/"}}; |
42 | | - assets{{"assets/"}}; |
43 | | - gradle{{"gradle/"}}; |
44 | | - wrapper{{"wrapper/"}}; |
45 | | - src{{"src/"}}; |
46 | | - confictura{{"confictura/"}}; |
47 | | - class root,github,workflows,assets,gradle,wrapper,src,confictura folder; |
48 | | -
|
49 | | - ci(["ci.yml"]); |
50 | | - wrapper-jar(["gradle-wrapper.jar"]); |
51 | | - wrapper-prop(["gradle-wrapper.properties"]); |
52 | | - main(["ConficturaMod.java"]); |
53 | | - ignore([".gitignore"]); |
54 | | - readme(["README.md"]); |
55 | | - build(["build.gradle.kts"]); |
56 | | - prop(["gradle.properties"]); |
57 | | - wrapper-unix(["gradlew"]); |
58 | | - wrapper-windows(["gradlew.bat"]); |
59 | | - icon(["icon.png"]); |
60 | | - meta(["mod.json"]); |
61 | | - settings(["settings.gradle.kts"]); |
62 | | - class ci,main,prop,meta file; |
63 | | -
|
64 | | - root-->github-->workflows-->ci; |
65 | | - root-->assets; |
66 | | - root-->gradle-->wrapper-->wrapper-jar & wrapper-prop; |
67 | | - root-->src-->confictura-->main; |
68 | | - root-->ignore & readme & build & prop & wrapper-unix & wrapper-windows & icon & meta & settings; |
69 | | - ``` |
70 | | - |
71 | | - Here are the changes made to files highlighted above; red denotes removals, green denotes additions: |
72 | | - `./github/workflows/ci.yml`: |
73 | | - ```diff |
74 | | - ... |
75 | | - uses: actions/upload-artifact@v4 |
76 | | - with: |
77 | | - - name: ModTemplate (zipped) |
78 | | - + name: Confictura (zipped) |
79 | | - - path: build/libs/ModTemplate.jar |
80 | | - + path: build/libs/Confictura.jar |
81 | | - ``` |
82 | | - |
83 | | - `src/confictura/ConficturaMod.java`: |
84 | | - ```diff |
85 | | - - package biotech; |
86 | | - + package confictura; |
87 | | - |
88 | | - import mindustry.mod.*; |
89 | | - - import biotech.gen.*; |
90 | | - + import confictura.gen.*; |
91 | | - |
92 | | - - public class ModTemplate extends Mod{ |
93 | | - + public class ConficturaMod extends Mod{ |
94 | | - @Override |
95 | | - public void loadContent(){ |
96 | | - EntityRegistry.register(); |
97 | | - } |
98 | | - } |
99 | | - ``` |
100 | | - |
101 | | - `gradle.properties`: |
102 | | - ```diff |
103 | | - ##### Project configurations. |
104 | | - # The mod's internal name, corresponds to `name` in `mod.json`. |
105 | | - - modName = mod-biotech |
106 | | - + modName = confictura |
107 | | - # The mod's fetched entity sources package. |
108 | | - - modFetch = biotech.fetched |
109 | | - + modFetch = confictura.fetched |
110 | | - # The mod's input entity sources package. |
111 | | - - modGenSrc = biotech.entities.comp |
112 | | - + modGenSrc = confictura.entities.comp |
113 | | - # The mod's generated sources package. |
114 | | - - modGen = biotech.gen |
115 | | - + modGen = confictura.gen |
116 | | - # The mod's JAR file name. Desktop build is suffixed with `Desktop`. |
117 | | - - modArtifact = ModTemplate |
118 | | - + modArtifact = Confictura |
119 | | - ... |
120 | | - ``` |
121 | | - |
122 | | - `mod.json`: |
123 | | - ```diff |
124 | | - { |
125 | | - - "displayName": "Mod Template", |
126 | | - + "displayName": "Confictura", |
127 | | - - "description": "Mindustry Java mod biotech, complete with EntityAnno and syntax downgrader integration.", |
128 | | - + "description": "Dive into the past of a trauma-driven uprising.", |
129 | | - "version": "1.0", |
130 | | - "minGameVersion": "146", |
131 | | - "author": "You", |
132 | | - "java": true, |
133 | | - - "main": "biotech.ModTemplate" |
134 | | - + "main": "confictura.ConficturaMod" |
135 | | - } |
136 | | - ``` |
137 | | - |
138 | | -5. Put your asset files *(textures, sounds, music, etc.)* inside `assets/`. The contents of this folder are included in the built JARs, and should look similar to those of JSON and JS mods. |
139 | | - ```mermaid |
140 | | - graph TD; |
141 | | - %%{init:{'flowchart':{'nodeSpacing': 10}}}%%; |
142 | | - |
143 | | - classDef folder fill:#465768,stroke:#bdcedf; |
144 | | -
|
145 | | - assets{{"assets/"}}; |
146 | | - bundles{{"bundles/"}}; |
147 | | - maps{{"maps/"}}; |
148 | | - music{{"music/"}}; |
149 | | - shaders{{"shaders/"}}; |
150 | | - sounds{{"sounds/"}}; |
151 | | - sprites{{"sprites/"}}; |
152 | | - class assets,bundles,maps,music,shaders,sounds,sprites folder; |
153 | | -
|
154 | | - assets-->bundles & maps & music & shaders & sounds & sprites; |
155 | | - ``` |
156 | | - That's all! You can start hacking your way into modding now. Refer to the [**Building**](#building) section on how to build the JARs. |
157 | | - |
158 | | -## Building |
159 | | - |
160 | | -Mindustry Java mods are cross-platform, supporting PC (Windows, Mac, Linux) and Android. This section describes how to build the JARs for both PC and Android. Building these JARs are done through the usage of terminals: `cmd.exe` in Windows, Terminal in Mac, and if you're either on Linux or using a terminal emulator on Android such as Termux, you should already know what you're doing anyway. Following these steps should require basic terminal functionality such as `cd`. |
161 | | - |
162 | | -### Desktop Build |
163 | | - |
164 | | -Desktop builds are convenient for testing, but will obviously **not** work on Android, so never include this in your releases. Desktop JARs have `Desktop` suffixed to their name, e.g. `ModTemplateDesktop.jar`. Here's how you can build the mod: |
165 | | -1. Open your terminal, and `cd` to your local copy of the mod. |
166 | | -2. Ensure your internet connection on first or clean builds, as the project will try to fetch prerequisites from the internet. |
167 | | -3. Run `gradlew jar` *(replace `gradlew` with `./gradlew` on Mac/Linux)*. This should create a JAR inside `build/libs/` that you can copy over to the Mindustry mods folder to install it. |
168 | | -4. You can also then run `gradlew install` to automatically install the mod JAR, or even `gradlew jar install` to do both compiling and installing at once. |
169 | | - |
170 | | -### Android Build |
171 | | - |
172 | | -Android builds are automated on the CI hosted by GitHub Actions, so you should be able to just push a commit and wait for the CI to provide your build. If you still want to build locally, though, follow these steps. |
173 | | - |
174 | | -#### Installing Android SDK |
175 | | -1. Install [Android SDK](https://developer.android.com/studio#command-line-tools-only), specifically the "**Command line tools only**" section. Download the tools that match your platform. |
176 | | -2. Unzip the Android SDK command line tools inside a folder; let's call it `AndroidSDK/` for now. |
177 | | -3. Inside this folder is a folder named `cmdline-tools/`. Put everything inside `cmdline-tools/` to a new folder named `latest/`, so that the folder structure looks like `AndroidSDK/cmdline-tools/latest/`. |
178 | | -4. Open your terminal, `cd` to the `latest/` folder. |
179 | | -5. Run `sdkmanager --install "platforms;android-35" "build-tools;35.0.0"`. These versions correspond to the `androidSdkVersion` and `androidBuildVersion` properties inside `gradle.properties`, which default to `35` and `35.0.0`, respectively. |
180 | | -6. Set environment variable `ANDROID_SDK_ROOT` as the full path to the `AndroidSDK/` folder you created, and restart your terminal to update the environments. |
181 | | - |
182 | | -#### Building |
183 | | -1. Open your terminal, and `cd` to your local copy of the mod. |
184 | | -2. Run `gradlew dex`. This should create a cross-platform JAR inside `build/libs/` that isn't suffixed with `Desktop` that you can copy over to the Mindustry mods folder to install it. |
185 | | -3. You can then copy the resulting artifact to your phone's Mindustry mods folder in its data directory. |
186 | | - |
187 | | -## Adding Dependencies |
188 | | - |
189 | | -**Never** use `implementation` for Mindustry/Arc groups and their submodules. There's a reason they're `compileOnly`; they're only present in compilation and excluded from the final JARs, as on runtime they're resolved from the game instance itself. Other JAR-mod dependencies must also use `compileOnly`. Only ever use `implementation` for external Java libraries that must be bundled with your mod. |
190 | | - |
191 | | -## License |
192 | | - |
193 | | -The project is licensed under [GNU GPL v3](/LICENSE). |
| 1 | +-??? |
0 commit comments