Amazon Ad

Tuesday, January 31, 2017

Configurations

Hello, my name is Alex and I am going to show you how to create a mod for minecraft forge 1.11.2. There's not a lot of tutorials on 1.11 so I am creating one for those that want to get started.

WARNING: IF YOU DO NOT KNOW ANYTHING ABOUT JAVA, PLEASE LEARN THE BASICS BEFORE ATTEMPTING TO FOLLOW ANY MODDING TUTORIALS!!!!!

In this tutorial I will be showing you how to configure your project to be fit for modding. We will open up our Java Eclipse Neon.2 for this tutorial.

Your window, once loaded up, should look something like this:




The selection to the left of "Browse..." should have a default workspace folder selected. Click "Browse..." and navigate to your newly created folder with all the mod files. Make sure you select the eclipse folder, as shown below:
Click "Okay" and let then continue to click "Okay" again. Let Eclipse load up and you should be faced with the following screen:


We need to go into hierarchical view in our package explorer. Go up to the top right of your package explorer and click the downward arrow.



Go to package presentation and click on hierarchical view. Now we are ready to go.

Go ahead and open that project, go to "src/main/java" and delete the package in the folder. Now we are ready to set up our configurations.

Right click the "src/main/java" and go to New > package and name it after your website reversed, so for example: "net.minecraft" is minecraft's package namespace. If you don't have a website, then just do "com.<yourname>.<modid>". I will get into the modid later, but for now, just make the modid "tut". So mine looks like "com.couchdoescode.tut". Go ahead and create the package. Right click this package and go to New > Class. We will name this "TutorialMod". Make sure there are no spaces in your class names. Create the class and you should be presented with the following screen:


Next we will write some code finally. Above your class declaration, write the following line:

1
@Mod(modid=Ref.MODID, name=Ref.NAME, version=Ref.VERSION)

This is an annotation, which adds metadata to your class. Metadata is data about data. So for example, the carpet in vanilla minecraft has metadata. It's one piece of data, being the carpet object, and there is data about that data that tells it to render multiple TYPES of carpets, while using one object. This object can then have multiple different versions of itself and the end result is a carpet, or wood, or grass/snowy grass. This @Mod adds information to the class and tells Forge that this is the main mod class.

Within the parameters, the arguments that are passed specify the "modid", "name", and "version" of the mod. "modid" is the id of the mod, or the namespace. It is how we are going to be looking for models and textures of the blocks, items, mobs, etc that we will be creating. "name" is the name of your mod, which will be used by Forge to identify it in the console. "version" is kinda self explanatory. It is basically the version of your mod, not the game.

Now onto creating the "Ref" file that needs to be created. There are errors which we need to resolve and this is how you fix it. Right click the package again and create a class called "Ref". In this we will need a few lines of code. So go ahead and type in the following lines of code:

1
2
3
public static final String MODID = "tut";
public static final String NAME = "Tutorial Mod";
public static final String VERSION = "1.0_a";

These are constants that we will be relying on for the next few tutorials. Once you put these into your "Ref" class, and save it, the errors will go away.

==========================================Proxies=============================================

We have to set up our proxies now. Proxies are Forge's way of finding models and textures and registering everything in the game. First, create a new package called "com.<yourname>.tut.proxy". Within this, create two classes called "ClientProxy" and "CommonProxy". Also, create an interface called "IProxy". In "IProxy", create three methods as follows:

1
2
3
public void preInit();
public void init();
public void postInit();

These are methods that our classes can use. They are like blank blueprints. We will call these methods and whatever classes that are implementing them, they will be called as well.

In the "CommonProxy" class, we will implement "IProxy" like this:

1
public class CommonProxy implements IProxy{

You will have a red line under your class name, so go ahead and add unimplemented methods so that your class then looks like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
package com.couchdoescode.tut.proxy;

public class CommonProxy implements IProxy{

 public void preInit() {
  
 }

 public void init() {
  
 }

 public void postInit() {
  
 }

}

Next, in your "ClientProxy" extend your class to "CommonProxy" like this:

1
public class ClientProxy extends CommonProxy{

This allows us to use the methods that are also in "CommonProxy" but the difference is one is CLIENT side and one is SERVER side. "ClientProxy" is where we will be putting Tile Entities in, or anything that is processed on the client side. "CommonProxy" is where we will be registering our models and textures and everything else in the game, so like blocks and items.

In your "TutorialMod" we have to add some methods. Enter them as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
 @EventHandler
 public void preInit(FMLPreInitializationEvent event){
 }
 
 @EventHandler
 public void init(FMLInitializationEvent event){
 }
 
 @EventHandler
 public void postInit(FMLPostInitializationEvent event){
 }

The "EventHandler" annotation tells Forge that the method is an event handler, and will be loaded by Forge Modloader. "FML(Pre/Post)InitializationEvent" are classes that Forge also uses to process events before, during, and after the game is loaded, respectively. We will be putting game registries in the "preInit", Tile Entities and anything that are done during the game, in the "init", and recipes like crafting and smelting in the "postInit".

Next, above the methods created in "TutorialMod", create a static field of the type "IProxy" called "proxy".

1
public static IProxy proxy;

Above the static field, call the "SidedProxy" annotation, declaring this field as a sided proxy. Below is what we will have to declare in order to not get any errors.

1
@SidedProxy(clientSide=Ref.CLIENT_PROXY, serverSide=Ref.SERVER_PROXY)

We will need to create "CLIENT_PROXY" and "SERVER_PROXY" in our "Ref" class.

1
2
public static final String CLIENT_PROXY = "com.couchdoescode.tut.proxy.ClientProxy";
public static final String SERVER_PROXY = "com.couchdoescode.tut.proxy.CommonProxy";

Make sure you import everything in all your classes. A quick way to do it is "CTRL+SHIFT+O".

In your methods, call your proxy methods.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
 @EventHandler
 public void preInit(FMLPreInitializationEvent event){
  proxy.preInit();
 }
 
 @EventHandler
 public void init(FMLInitializationEvent event){
  proxy.init();
 }
 
 @EventHandler
 public void postInit(FMLPostInitializationEvent event){
  proxy.postInit();
 }

Now we are finished setting up the mod. Run the project by clicking the green play button at the top, and make sure that it is all correct.

==========================================Common Errors=====================================


Error #1: Attempted to load a proxy type ClientProxy into TutorialMod.proxy, but the types don't match
    This is simply an error caused by "ClientProxy" not extending "CommonProxy".

10 comments:

  1. What do you mean by making sure all is correct? Do you mean Minecraft starts up when you hit run?

    ReplyDelete
  2. This is so far a great tutorial and all Loaded up for me. ( even though there is still alot of red underlining I do hope is normal!) Thank you for putting this up it is so hard pulling bits of information here and there!

    ReplyDelete
  3. Red underlining probably means you haven't imported all the classes yet. For example if "FMLPreInitializationEvent" is underlined in your main mod class file, you need to import it up above the class declaration- "import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;"

    Hovering your mouse over the underlined text in Eclipse will show you a link to click and fill in the missing import. Or hit CTRL-SHIFT-O to do it all at once.

    ReplyDelete
  4. I followed everything step by step, but for some reason the "src/main/java" file never appears.
    Is there any way to fix this?

    ReplyDelete
  5. And when I click on the MDKExample folder, I get this error message:
    "The project description file (.project) for 'MDKExample' is missing. This file contains important information about the project. The project will not function properly until this file is restored."

    ReplyDelete
    Replies
    1. I'm the same person as the "Unkown" above me btw.

      Delete
    2. I also got this. Any fixes?

      Delete
  6. This comment has been removed by the author.

    ReplyDelete
  7. oops i forgot to make the IProxy interface
    my bad

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete