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".

Setting Up



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.

If you are updating from 1.8/1.9, then I will show you how to update to 1.11 later on. For now, let's just stick to the very beginning of our mod. The mod that we are going to make is a mod that has ores, items, tools, armour, oregen, biomes, mobs, chest loots, special blocks, special items, and others at request.

To start off you will need to go to the minecraft forge website and download the latest.

Here is the link to the list of minecraft forge releases. Choose 1.11 Minecraft, and download the MDK.

Next go to the JDK download screen here, and the JRE here. Download and install those two components and you should be ready to go in no time.

Next is downloading Java Eclipse from here. Just download and install it and you'll soon be ready to start coding.

Before we start coding we have to create a folder on our desktop and call it whatever you want, as for me I will be calling it "Tutorial". Next, extract your forge zip folder and once it is done, highlight and drag and drop all the files and folders into our newly created folder. Once it is all done migrating, create a batch file and call it "run.bat". Right click &gt; Edit, and once the window opens, type in,


gradlew setupDecompWorkspace eclipse

Save it, and run the batch file by double clicking it. Once you have ran and completed it, then you have just successfully set up minecraft forge for mod development.

=========================================Explanations=========================================

gradlew

This part of the code calls on the other batch file in the folder, created by the felllas at Forge, that has all the commands needed to prepare the environment, and even change it and update it to another version.


setupDecompWorkspace

This part of the code basically sets up the workspace environment that we will be developing in. It creates all the necessary folders and files that are decompiled from objects to classes to java files. It creates the "src" folder that we will be relying on heavily throughout this series.


eclipse

This creates the Java Eclipse environment in a folder called "eclipse". This also sets up the Java Project that will be in the environment that we will be making our mod in.

gradlew setupDecompWorkspace eclipse

Altogether, they create the entire project environment necessary for minecraft modding.

=========================================Common Errors=======================================
Error #1: Command line interface opens and closes immediately

    A good way to figure out what is going on here is to shift-right-click in the mod environment (aka: the folder created at the beginning) and select "Open Command Window Here". Re-enter the gradlew command as stated above and look at the log it gives you. Right click and in the command window, and select "Mark". Highlight the entire log, and right click, copy, and paste it into a text file. You can see it there. I recommend going to google for the answers first before sending me any logs. If you have come to a last resort situation, then you may email me the log here.*

Error #2: Build Failed with and Exception

    This is a case of a typo. If you get this, then most likely what you did was you misspelled something in your batch file. Check it again, and make sure it is all spelled correctly.