Learning Java Through Modding: Auroral Forces

  • The FTB Forum is now read-only, and is here as an archive. To participate in our community discussions, please join our Discord! https://ftb.team/discord

Bearnado123

New Member
Jul 29, 2019
298
0
0
So over the past week I've learned the basics of Java and have gone through and tried to learn the details of the IDE I'm using and I've decided that it's time to try and apply what I've learned to a larger project. So I'm going to try to make a mod. I might put some minor dev commentary on here at some points and will probably put the link to the Github so others can take a look at the code. So before I dive right in does anyone, especially mod devs, have any tips, suggestions, or miscellaneous comments?
 

OreCruncher

Well-Known Member
Mod Developer
May 22, 2013
312
217
73
My Chair
When you learn to write software two things are generally occuring:
  • You are learning a computer language and it's frameworks (Java, Java SDK, etc.)
  • You are learning to design computer software (when to use a Set over a List, best way to lay out class structures, etc.)

From what I have seen with beginning modders is they trip over the second one quite a bit which is a cool thing. The reason it is cool is that you learn to write good software by doing and making mistakes. Over my career as a software engineer I have made some doozy of mistakes, and I have learned quite a bit. And I am still learning because software design is an ever evolving field.

As it applies to Minecraft modding be prepared to get a lot of opinions as to the best way to do things. Some of it will be good advice, a lot of it will be just opinion. In the end you will have to be satisfied with what you produce, and that is what will ultimately count.

Don't be afraid to ask questions. I tell the software devs I am responsible for the only stupid question is the one that remains unanswered. If you do have a question it's best to ask for the place to start looking for a solution and not for *the* solution. Problem solving is a journey. If you short circuit that journey the chance you will learn something is pretty remote.

As it relates to Forge be prepared to spend time digging. For complex situations Forge is not well documented. The best way to figure Forge out is to look at what others have done with their mods. This will require time studying since you are starting out, but as you gain experience you get a feel for code and know where to start looking. Copy/paste of existing code can be OK *if* you understand what that code does. I personally have seen folks copy/paste code without understanding and as a side effect create more problems for themselves.

Lastly, there are a lot of good mod tutorials that can be found by searching the Internet. Also, there are a lot of bad ones that basically say "put this code here" and not really explain what is going on. Once you get started writing a mod you quickly learn what is valuable.

EDIT:
Some more things to keep in mind...
  • Embrace iterative development. Do a little design, write a little code, test the heck out of it before moving on to the next piece of code.
  • Be mindful that your mod may run on a server. If your core mod logic relies on software pieces that are client side ONLY it will crash the server. (It's why you see those @SidedOnly annotations in the source code.)
  • Less is more. Keep things simple, both from a coding standpoint and feature standpoint. Only make things more complicated if there is a darn good reason. Stability is king.
  • Your mod is just a piece of the software stack running on a modded client/server. Do your best to make it a good citizen.
 
Last edited:

Type1Ninja

New Member
Jul 29, 2019
1,393
-7
0
When you learn to write software two things are generally occuring:
  • You are learning a computer language and it's frameworks (Java, Java SDK, etc.)
  • You are learning to design computer software (when to use a Set over a List, best way to lay out class structures, etc.)

From what I have seen with beginning modders is they trip over the second one quite a bit which is a cool thing. The reason it is cool is that you learn to write good software by doing and making mistakes. Over my career as a software engineer I have made some doozy of mistakes, and I have learned quite a bit. And I am still learning because software design is an ever evolving field.

As it applies to Minecraft modding be prepared to get a lot of opinions as to the best way to do things. Some of it will be good advice, a lot of it will be just opinion. In the end you will have to be satisfied with what you produce, and that is what will ultimately count.

Don't be afraid to ask questions. I tell the software devs I am responsible for the only stupid question is the one that remains unanswered. If you do have a question it's best to ask for the place to start looking for a solution and not for *the* solution. Problem solving is a journey. If you short circuit that journey the chance you will learn something is pretty remote.

As it relates to Forge be prepared to spend time digging. For complex situations Forge is not well documented. The best way to figure Forge out is to look at what others have done with their mods. This will require time studying since you are starting out, but as you gain experience you get a feel for code and know where to start looking. Copy/paste of existing code can be OK *if* you understand what that code does. I personally have seen folks copy/paste code without understanding and as a side effect create more problems for themselves.

Lastly, there are a lot of good mod tutorials that can be found by searching the Internet. Also, there are a lot of bad ones that basically say "put this code here" and not really explain what is going on. Once you get started writing a mod you quickly learn what is valuable.

EDIT:
Some more things to keep in mind...
  • Embrace iterative development. Do a little design, write a little code, test the heck out of it before moving on to the next piece of code.
  • Be mindful that your mod may run on a server. If your core mod logic relies on software pieces that are client side ONLY it will crash the server. (It's why you see those @SidedOnly annotations in the source code.)
  • Less is more. Keep things simple, both from a coding standpoint and feature standpoint. Only make things more complicated if there is a darn good reason. Stability is king.
  • Your mod is just a piece of the software stack running on a modded client/server. Do your best to make it a good citizen.
Well freakin' said, good sir. :D

My recommendation is Pahimar's Let's Mod Reboot tutorial for 1.7.10. I started learning to mod all of 3 days ago, and I've coded infinitely durable armor and a mostly-functional lightning rod just with that tutorial and some googling/digging through code. :)
 

Bearnado123

New Member
Jul 29, 2019
298
0
0
So I need a little bit of help. While I've been trying to set up the events, preInit, init, and postInit, in my mod class I can not get the @mod.EventHandler to work like Pahimar does in his tutorials. It just gives me an error saying:
Error:(14, 6) java: type annotations are not supported in -source 1.6
(use -source 8 or higher to enable type annotations)
Does anyone have any idea how to fix this. Sorry if I've made a noobish mistake.
 

Strikingwolf

New Member
Jul 29, 2019
3,709
-26
1
So I need a little bit of help. While I've been trying to set up the events, preInit, init, and postInit, in my mod class I can not get the @mod.EventHandler to work like Pahimar does in his tutorials. It just gives me an error saying:
Error:(14, 6) java: type annotations are not supported in -source 1.6
(use -source 8 or higher to enable type annotations)
Does anyone have any idea how to fix this. Sorry if I've made a noobish mistake.
I have no idea how you got that error (github?). The error is saying you used type annotations, which are only available in Java 8
 

Bearnado123

New Member
Jul 29, 2019
298
0
0
I have no idea how you got that error (github?). The error is saying you used type annotations, which are only available in Java 8
I got the error while I ran the project in the IDE, Yeah I saw the thing about java 8 as well which is weird because I have version 8 update 45 on my computer which is the most up to date version.
 

Strikingwolf

New Member
Jul 29, 2019
3,709
-26
1
I got the error while I ran the project in the IDE, Yeah I saw the thing about java 8 as well which is weird because I have version 8 update 45 on my computer which is the most up to date version.
MC modding uses Java 7 or 6 (6 in this case). I'm asking for your source code, paste it here or put it on github please
 

Bearnado123

New Member
Jul 29, 2019
298
0
0
package com.Bearnado123;import cpw.mods.fml.common.Mod;import cpw.mods.fml.common.event.FMLInitializationEvent;import cpw.mods.fml.common.event.FMLPostInitializationEvent;import cpw.mods.fml.common.event.FMLPreInitializationEvent;

@Mod(modid="Auroral-Forces", name="Auroral-Forces", version="1.7.10-1.0")
public class AuroralForces
{
@Mod.Instance("Auroral-Forces")
public static AuroralForces Instance

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event){

}

@Mod.EventHandler
public void init(FMLInitializationEvent event){

}

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event){

}
}
This is the mod class that I made for this, It worked until I put in the 3 init events and the Instance object. Sorry about the formatting getting messed up but It did that after I copy pasted. I haven't really taken the time to figure out Git yet so this is the best I could do for right now.
 

Type1Ninja

New Member
Jul 29, 2019
1,393
-7
0
package com.Bearnado123;import cpw.mods.fml.common.Mod;import cpw.mods.fml.common.event.FMLInitializationEvent;import cpw.mods.fml.common.event.FMLPostInitializationEvent;import cpw.mods.fml.common.event.FMLPreInitializationEvent;

@Mod(modid="Auroral-Forces", name="Auroral-Forces", version="1.7.10-1.0")
public class AuroralForces
{
@Mod.Instance("Auroral-Forces")
public static AuroralForces Instance

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event){

}

@Mod.EventHandler
public void init(FMLInitializationEvent event){

}

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event){

}
}
This is the mod class that I made for this, It worked until I put in the 3 init events and the Instance object. Sorry about the formatting getting messed up but It did that after I copy pasted. I haven't really taken the time to figure out Git yet so this is the best I could do for right now.
Try commenting out the inits and instance one by one until you don't get the error; try to figure out which one is causing the issue (or if all of them cause it).
Protip: You can use code tags for code. [.code][/code] (without the period, of course)
For Example:
Code:
System.out.println("Code goes here");
 
  • Like
Reactions: Bearnado123

Bearnado123

New Member
Jul 29, 2019
298
0
0
So I have absolutely no way to explain this but I commented everything out and started re adding the code piece by piece and everything worked. I'm definitely not gonna complain because it's working but that was weird.
 
  • Like
Reactions: Type1Ninja