So I know most of the forum have been indoctrinated into the unholy cult of NetBeans, but IntelliJ IDEA is pretty great and has several features that make modding Starsector a breeze (more so than NetBeans). It's also prettier.
If you suck at coding, you will still continue to suck. However, I can guarantee that following this tutorial will make you suck harder, faster, and more creatively than ever before!
By the end of this tutorial, you will have:
+ Configured IntelliJ for editing and compiling your mod's code into a JAR.
+ Setup and learned how to access the Starsector/LazyLib/ShaderLib Javadocs from within IntelliJ while coding.
+ Created a one-click build+run configuration for your mod + Starsector.
+ Setup some miscellaneous IntelliJ settings that I find helpful.
+ Learned a few other IntelliJ tricks.
+ Uninstalled NetBeans.
NOTE: this tutorial is aimed at IntelliJ IDEA versions 14+. Earlier versions are weird.
==============================================================
Download and setup IntelliJ:+ Download the Java 1.7 SE JDK for your OS (if you don't have it already). Unzip it and store it anywhere.
+ Get IntelliJ IDEA from
here (the Community Edition is great).
+ Open IntelliJ IDEA
===============================================================
Import your mod:+ File -> New project from existing sources
+ Select your mod's root folder
+ Create project from existing sources
+ Hit next a couple times, I think the rest of the config settings should be ok. Make sure it makes a module out of your project's src/ directory (or wherever your code lives).
But wait, I don't want to import a mod, I want to start my own from scratch!Download the source code for an existing mod and follow this tutorial with that mod. Doing this will let you learn the ins and outs of the IDE a bit before you start, and will ensure that you know how to compile a mod correctly. That way, if something doesn't work, you'll know it's your code and not the way you are setting up your project. I will recommend my mod (
https://github.com/jstaf/mayorate) as an example for this tutorial. I'm making this recommendation not because I'm trying to promote my mod, but because I know it is guaranteed to work with this tutorial. It also functions as an example for most everything you'd want to do, including custom planets/portraits/ships/AI/music/weapons/plugins/sector generation/skills/hullmods/ship systems/etc..
Once you've finished this tutorial with an example mod from the forums, use an existing mod from the forums to create your mod. Take this existing mod and delete everything but the mod_info.json and modPlugin.java files and start from there.
To configure your project:+ File -> Project Structure
+ Add JDK 1.7 to your project:
+ Platform Settings -> SDKs
+ Hit the "+", select the path to the JDK that you downloaded
+ Project Settings -> Project
+ Project SDK is 1.7
+ Project language level is 7.
+ Add dependencies to your project:
+ Make sure you have LazyLib and ShaderLib downloaded and in your mods folder if your project uses them.
+ Project Settings -> Libraries
+ To add Starsector as a dependency:
+ Hit the "+" sign at the top, select Java
+ Select all of the JARs in Starsector's root directory (as well as starsector.api.zip), hit OK
+ Name the dependency "starsector core" (or whatever you want)
+ Hit the "+" with a little globe on it to add a Javadoc
+ Enter "
http://fractalsoftworks.com/starfarer.api/", hit OK
+ To add LazyLib as a dependency:
+ Hit the "+" at the top, select Java
+ Add LazyLib.jar and javadoc.zip, hit OK
+ To add ShaderLib as a dependency:
+ Hit the "+" at the top, select Java
+ Add Shaders.jar
+ Add the javadoc/ folder
+ Configure your compiler output:
+ Project Settings -> Artifacts
+ Hit the "+" at the top, select JAR -> From modules with dependencies
+ Select module that was created on project import
+ Do not set a main class, extract to target JAR
+ Change name to your desired output JAR name (.jar gets automatically added)
+ Select your desired output directory
+ Check "build on make"
+ Remove everything thats not your module's compiled output. Select all of the stuff in the left panel, and hit "-"
+ Hit OK to close the settings dialog
Setup the ultra-fancy one-click build/run configuration:+ File -> Settings
+ Plugins -> Browse repositories
+ On Windows: Install the "Batch Support" plugin
+ On Mac/Linux: Install the "Bash Support" plugin
+ Restart IntelliJ IDEA to reflect the changes in plugins
+ Run -> Edit Configurations
+ Hit the "+" in the top left, create a new Batch (Windows) or Bash (Mac/Linux) run configuration
+ Set the name to "Starsector"
+ Hit the "..." next to "Script", select either starsector.bat (Windows) or starsector.sh (Mac/Linux)
+ Hit the "..." next to "Working Directory", select your Starsector install directory.
+ In the before launch panel, hit "+", select Build
+ Hit OK to create the configuration
To build and/or run Starsector:To build your mod's JAR and run Starsector:
Hit the play button in the top right corner to both compile your mod and run Starsector.
To simply build your mod's JAR (without running Starsector):
Hit the little "down pointing arrow with 01010110" icon in the upper right.
Make sure to delete the "out/" directory before distributing your mod, all of the code you want to distribute is packaged in the compiled JAR.
Bask in the glory that is IntelliJ IDEA:+ Self explanatory.
===================================================================================
Other useful configuration options (Optional):Disable project autoload (if you have other stuff you want to work on):
File -> Settings -> Appearance & Behavior -> System Settings -> Reopen last project on startup
Enable line numbers in all files:
File -> Settings -> Editor -> Appearance -> Show line numbers
Disable the *** spell check:
File -> Settings -> Editor -> Inspections -> Spelling
=================================================================================
Other neat features with this setup:When you're running your build configuration, the Starsector log will automatically dump down into the Run panel in the bottom of the screen. If you get an error, that will be the last thing in the console. You'll never need to open starsector.log and scroll all the way to the bottom ever again (unless you're just playing the game normally, of course).
If you need to look up the documentation for something, ctrl+q opens the relevant Javadocs in the editing window. You can also look at the Starsector source files this way.
Whenever you specify a color (e.g. "new Color(r, g, b, a)"), a little colored box pops up next to the line #s. Clicking the colored box gives you a color picker straight out of GIMP or Photoshop that will modify the color specified on that line.
"//TODO <your comment here>" creates a to-do comment in your code that you can go back to anytime/check with the little TODO dock in the bottom (If it isn't there: View -> Tool Windows -> TODO)
Possible autocompletions will popup as you type, which is nice for figuring things out stuff with the APIs.
Shift+F6 renames/refactors a variable/anything in all files of your project.
Ctrl+Enter == autocomplete.
Double-tap Shift searches inside your project for
anything.
Ctrl+/ == line comment.
Ctrl+Shift+/ == block comment.
Tools -> Create Javadoc creates Javadocs.
IntelliJ has nice Version Control capabilities with git and whatnot. Not covering them here, but make sure to check out what's possible (also check out the ".gitignore" plugin!).
======================================================================
Troubleshooting:If on running your configuration results in some weird "xxxxx.so not found" error or something like that, edit the "./jre_your_platform/java" bit in the first part of starsector.bat/starsector.sh to simply "java". Linux users are probably already familiar with this step.
*Updated to use a significantly nicer run configuration