Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: Tutorial: Setting up NetBeans for Starfarer Mods (image heavy!)  (Read 25892 times)

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile

Prior to today I had been coding my mods in NotePad++, occasionally calling the java compiler from the command line when I needed more detailed error messages. Not exactly ideal. So I decided to pick up a real Java IDE, and ended up choosing NetBeans. It's been such a massive improvement that I figured I would help pave the way for any others who want to try it out. Here's a tutorial to get an existing mod working in NetBeans. If I explained something poorly, click the spoiler tag underneath that paragraph for pictures.

(Keep in mind I've only been using NetBeans for a few hours and figured it out as I wrote this tutorial, so it's likely some of this information might be wrong. Code at your own risk! :))

"This looks like a really difficult tutorial. I mean, it's like four pages long. Is this really worth it?"

It's not as hard as it looks, I'm just terrible at writing tutorials ;). Plus, it has lots of pretty pictures to look at :P. As for why you would want to work in a real IDE, there are a few benefits: most importantly, you will get instant feedback on any bugs you make. If you've been editing the java files in Notepad++ or something so far, you're probably intimately familiar with the following: trying to launch Starfarer, having it crash, then reading the end of a logfile to get a uselessly cryptic error message about what went wrong. With NetBeans you get real error messages, ones you can Google for help with, and you get them as you type. Bugs become much easier to squash. It also has a host of other features that I won't bore you with.

Let's begin. First up, you will need the Java Development Kit if you don't already have it (if you have to ask, you probably don't have it). That can be downloaded here (it's the download called JDK, if that wasn't obvious). Java 6 or 7, doesn't really matter. Compatability isn't an issue since you won't be using what you compile with NetBeans (Starfarer compiles the mods itself when it launches); NetBeans just makes working with the source files a lot easier.

Next, you'll need NetBeans itself. NetBeans can be downloaded from netbeans.org. It's up to you if you grab the beta version or not; I've tried both and either should work just fine. You only need the Java SE version for making Starfarer mods.

Once you've installed and run the program, this is close to what you should see (I've already customized my windows, sorry!):
Spoiler
[close]

Go to File - New Project. Make sure the category is set to Java and select "Java Project with Existing Sources" in the Projects box. Hit Next. Name your project anything you like, and put it anywhere except in your mod folder. We're not interested in the project files NetBeans generates.
Spoiler

[close]

You'll now see two empty boxes. We're interested in the top one, Source Package Folders. Hit "Add Folder" to the right of this box. Browse to the mods directory and select your mod folder (ignore the image below showing the data folder, it's wrong). Hit OK, then Next.
Spoiler


[close]

Now we come to the Includes & Excludes menu. Chances are that your mod isn't pure code, so we'll have do to a bit of work here. Change the text in the Includes box from "**" to "**/*.java". If you did this right, only your .java files are in the Included Files box now, with everything else under Excluded Files. Hit Finish.
Spoiler

(Ignore the background in this one. I forgot to take a screenshot, so had to go back later.
[close]

You should now be able to see your project's folder structure under the Projects tab on the left of the main IDE screen. But what's with all the red exclamation point signs?
Spoiler
[close]

Well, you're still missing something very important. Your code is referencing all these Starfarer APIs, but NetBeans has no idea what you are talking about. To fix this, we need to add the Starfarer API to the Project Libraries. Right click on Libraries in the Project tab, and select "Add Jar/Folder". Navigate to the Starfarer install directory, and enter the folder starfarer-core. Find starfarer.api.jar and select it. You might also want to add lwjgl_util.jar, as that is where the Vector2f class is defined.
Spoiler

[close]

Note that at this point you're probably still going to have a bunch of compile errors due to missing dependencies. Remember, Starfarer mods work by adding your mod on top of what's in starfarer-core, and NetBeans doesn't know about those files. The laziest easiest way to fix this is to just look at the compile errors, find out what files are missing, and copy them over from the Starfarer/starfarer-core/data directory (for most current mods, BaseSpawnPoint will be the big one). After you're done, go to Source - Scan for External Changes. That should allow NetBeans to notice the files you just added. Don't worry about cluttering up your mod, you should only need a few files; even if you did somehow require every core file for compatability, it would add less than 100 kilobytes to your mod size. I'm sure there's a better way of doing this, does anyone who uses NetBeans know of one? I'm aware that you can add starfarer-core to your project source, but then you run the risk of editing core files.

Most of the compile error warnings should have vanished now (you might still have to do a bit of cleanup), and as an added bonus you can now browse the API at your leisure in the Libraries tree.
Spoiler
[close]

Although you might notice something strange...
Spoiler
[close]

You're looking at a generated source file. Not very intuitive, is it? Don't worry, we can fix this. Right click on starfarer.api.jar in your Projects tab, and click Edit. Hit the Browse button next to Sources and head back to starfarer-core. This time, select starfarer.api.zip.
Spoiler

[close]

You might have to reload the file before any changes show up, but it should now look something like this:
Spoiler
[close]

Isn't this:
Code
SectorEntityToken addPlanet(SectorEntityToken focus, String name, String type,
float angle, float radius, float orbitRadius, float orbitDays);
Much more intuitive than this:
Code
public SectorEntityToken addPlanet(SectorEntityToken set, String string, String string1, float f, float f1, float f2, float f3);

You're pretty much ready to go at this point. Happy coding!

(If this tutorial was missing anything, let me know and I'll fix it)
« Last Edit: June 26, 2013, 10:40:32 AM by LazyWizard »
Logged

CrashToDesktop

  • Admiral
  • *****
  • Posts: 3876
  • Quartermaster
    • View Profile
Re: Tutorial: Setting up NetBeans for Starfarer Mods (image heavy!)
« Reply #1 on: June 15, 2012, 08:24:27 AM »

Ahh.....thanks!  Some of the errors I get aren't noted very well in the .log, will this help me in that?  I mean, like tell me the actual source file?
Logged
Quote from: Trylobot
I am officially an epoch.
Quote from: Thaago
Note: please sacrifice your goats responsibly, look up the proper pronunciation of Alex's name. We wouldn't want some other project receiving mystic power.

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: Tutorial: Setting up NetBeans for Starfarer Mods (image heavy!)
« Reply #2 on: June 15, 2012, 08:29:15 AM »

Yep. And it shows more than one error at a time, too, unlike starfarer.log. :)
Logged

Upgradecap

  • Admiral
  • *****
  • Posts: 5422
  • CEO of the TimCORP
    • View Profile
Re: Tutorial: Setting up NetBeans for Starfarer Mods (image heavy!)
« Reply #3 on: June 15, 2012, 08:39:07 AM »

Comprehensive tutorial of a good thing. Describes in detail of what to do and how to install.


Why did you say that you didn't know how to write a tutorial? ;)
« Last Edit: July 07, 2013, 06:11:41 PM by Upgradecap »
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: Tutorial: Setting up NetBeans for Starfarer Mods (image heavy!)
« Reply #4 on: June 15, 2012, 08:42:55 AM »



Comprehensive tutorial of a good thing. Describes in detail of what to do and how to install.


Why did tou say that you didn't know how to write a tutorial? ;)

Back when I worked on a MUD, whenever I tried to explain something technical to a non-coder they would end up more confused than before. It became kind of a running joke that I couldn't get others to understand me.

Hmm, I guess I'm getting better at it. :)
Logged

Upgradecap

  • Admiral
  • *****
  • Posts: 5422
  • CEO of the TimCORP
    • View Profile
Re: Tutorial: Setting up NetBeans for Starfarer Mods (image heavy!)
« Reply #5 on: June 15, 2012, 08:43:37 AM »

I'm Sorry for acting stupid here, but what's a MUD?
Logged

LazyWizard

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1363
    • View Profile
    • GitHub Profile
Re: Tutorial: Setting up NetBeans for Starfarer Mods (image heavy!)
« Reply #6 on: June 15, 2012, 09:00:43 AM »

I'm Sorry for acting stupid here, but what's a MUD?

Text-based MMO, precursors to modern MMOs. In fact, the first MMOs were called graphical MUDS before they decided on a better name.
Logged

Sproginator

  • Admiral
  • *****
  • Posts: 3592
  • Forum Ancient
    • View Profile
Re: Tutorial: Setting up NetBeans for Starfarer Mods (image heavy!)
« Reply #7 on: June 15, 2012, 03:49:08 PM »

Lazy, im very greatful you joined the forums, you have, so far, really helped with tutorials, care to help my noobs guide to modding out?
Logged
A person who's never made a mistake, never tried anything new
- Albert Einstein

As long as we don't quit, we haven't failed
- Jamie Fristrom (Programmer for Spiderman2 & Lead Developer for Energy Hook)

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Tutorial: Setting up NetBeans for Starfarer Mods (image heavy!)
« Reply #8 on: June 15, 2012, 04:02:26 PM »

Quote
it's like four pages long. Is this really worth it?

If you manage to do it, its always worth it
Logged

KriiEiter

  • Commander
  • ***
  • Posts: 126
    • View Profile
Re: Tutorial: Setting up NetBeans for Starfarer Mods (image heavy!)
« Reply #9 on: June 23, 2012, 11:10:07 AM »

I'm Sorry for acting stupid here, but what's a MUD?

Text-based MMO, precursors to modern MMOs. In fact, the first MMOs were called graphical MUDS before they decided on a better name.

Haha yeah MUDs must seem like some ancient form of entertainment to a 14 year old. :P  

Thanks bunches for this tutorial.  I only know basic programming structure and theory (veryyy basic) so I'm basically stuck with grabbing a completed code and modifying it as best I can for my custom stuff.

This should help a lot with learning how to make my own missions (and eventually faction).

**Edit**

Made my own mission after getting this all set up, thanks a lot!  Now to make more ships and weapons so I have something actually worth modding in.  :P
« Last Edit: June 23, 2012, 12:15:23 PM by KriiEiter »
Logged
"If it aint broke, don't fix it."

Wriath

  • Captain
  • ****
  • Posts: 280
    • View Profile
Re: Tutorial: Setting up NetBeans for Starfarer Mods (image heavy!)
« Reply #10 on: June 24, 2012, 06:59:15 PM »

mumuorpeguh is not a better name than g-mud.

CrashToDesktop

  • Admiral
  • *****
  • Posts: 3876
  • Quartermaster
    • View Profile
Re: Tutorial: Setting up NetBeans for Starfarer Mods (image heavy!)
« Reply #11 on: June 24, 2012, 07:14:29 PM »

Made my own mission after getting this all set up, thanks a lot!  Now to make more ships and weapons so I have something actually worth modding in.  :P
Making the mission isn't the hard part.  Once you get used to it, you can whip out mission in mere minutes.  It's campaign where this really makes it easier.  If you've ever modded campaign .java files, you'll know what I mean. ;D
Logged
Quote from: Trylobot
I am officially an epoch.
Quote from: Thaago
Note: please sacrifice your goats responsibly, look up the proper pronunciation of Alex's name. We wouldn't want some other project receiving mystic power.

cp252

  • Admiral
  • *****
  • Posts: 586
    • View Profile
Re: Tutorial: Setting up NetBeans for Starfarer Mods (image heavy!)
« Reply #12 on: June 25, 2012, 10:57:05 AM »

Haha yeah MUDs must seem like some ancient form of entertainment to a 14 year old. :P  
We still play them, you know. (Well the youngest person I know who does is 15, but still)
OT, yes it is a very nice tutorial. But I don't even know what NetBeans is for after glancing at it~
Logged

KriiEiter

  • Commander
  • ***
  • Posts: 126
    • View Profile
Re: Tutorial: Setting up NetBeans for Starfarer Mods (image heavy!)
« Reply #13 on: June 25, 2012, 11:52:26 AM »

Made my own mission after getting this all set up, thanks a lot!  Now to make more ships and weapons so I have something actually worth modding in.  :P
Making the mission isn't the hard part.  Once you get used to it, you can whip out mission in mere minutes.  It's campaign where this really makes it easier.  If you've ever modded campaign .java files, you'll know what I mean. ;D

Yeah, once I figured out the mission coding, it was pretty simple.  It's just that I haven't programmed anything since about junior year of highschool (which was about 6 years ago now) and that was just SUPER BASIC VB.

Luckily the code is quite intuitively layed out upon glancing at it.  And looking at the comments some modders have put in helped a bunch.

It seems most of the work making my own faction will be in the spriting and balancing of ships and weapons.
Logged
"If it aint broke, don't fix it."