RkShaRkz / Starsector-IntelliJ-Template

Starsector mod template with pre-configured IntelliJ project files and instructions.
The Unlicense
0 stars 1 forks source link

Starsector IntelliJ Mod Template

v1.0.1

Description

This is a template for a generic Starsector mod using Java.

When you are done, you will have a mod that does nothing, but is ready for anything to be added.

Written for IntelliJ Community (free download), but should work with any IDE. You do NOT need IntelliJ Ultimate. Latest version of IntelliJ is 2022.2 as of writing.

Optional

Initial

FAQ

Explanation of Folders/Files

The template contains many folders and files that are commonly used, but not all. You may not need everything, but leaving them in place doesn't hurt either.

IntelliJ Configuration

Set your SDK (the thing that compiles the Java code)

SDKs!

Ensure that your run configuration is correct:

Run configuration!

"I didn't install the game to the default location"

If your game isn't installed to C:\Program Files (x86)\Fractal Softworks\Starsector then we need to fix some more file paths.

If you did install to the default location, skip to the next part.

  1. Open .idea/libraries/starfarer_api.xml. It should be fairly clear what needs to be fixed; any path that's pointing to the default game installation should be changed to point to wherever you have it installed.
    1. It's also possible to edit this in File -> Project Structure -> Libraries, but for editing en masse, editing the xml directly is simpler.

Library configuration!

Running the game

To actually build your mod and run the game with it, look for and click the Debug icon, which looks like a bug and is green by default. It should be at the top of IntelliJ and next to Build (hammer icon) and Run (play icon) buttons.

Clicking the Debug button will build the .jar, launch the game and pause it, attach IntelliJ's debugger, and unpause the game. The game's launcher will then show. Don't forget to enable your mod in the launcher.

Don't click the Run (play) icon; it will cause the game to wait indefinitely for the debugger and never launch.

It's working, now what?

Now you have a template that works, but we need to personalize it so multiple people can use the template without stepping on each others' toes, so to speak.

See that in src, we have author.modname as the package (which matches the folder path src/author/modname).

  1. [ ] The first step is to change the package of our code. This is an organization thing; if there are two Java files with the same name in the same package, then only one of them will get loaded, but if they're in different packages, both will be loaded.
    1. The easy way to change this is to open up TemplateModPlugin.java, click on the first line (package...), right-click, and choose Refactor -> Rename. Change it to match your username and modname (or whatever you prefer) .
    2. When done, you shouldn't have any code in author.modname. If that still exists, it can be safely deleted.
    3. Rename!

  2. [ ] Now, we've changed where the ModPlugin is located and we need to tell the game the new location the game can call it when the game loads.
    1. Open the mod_info.json file, find "modPlugin", and edit it to use your new package (if you forgot, it's the first line of your TemplateModPlugin.java file).
  3. [ ] You can also change the name of the .jar file, which is Template.jar by default, in File -> Project Structure -> Artifacts, then just right-click on Template.jar and choose rename.
    1. [ ] You will also need to update the name of the .jar in your mod_info.json file so the game knows where to look.

Jar!

Adding more dependencies/libraries

Need to depend on another mod or library (e.g. GraphicsLib, LazyLib, LunaLib, MagicLib, Nexelerin, etc)?

  1. File -> Project Structure -> Modules -> "starsector-intellij-template" -> Dependencies tab -> + icon -> JARS or Directories. Select the .jar(s) you want to add.
  2. Leave Export unchecked and Scope to Compile.

Other

Author: Wisp

Lowtech Tempest: Selkie