DEVTOME.COM HOSTING COSTS HAVE BEGUN TO EXCEED 115$ MONTHLY. THE ADMINISTRATION IS NO LONGER ABLE TO HANDLE THE COST WITHOUT ASSISTANCE DUE TO THE RISING COST. THIS HAS BEEN OCCURRING FOR ALMOST A YEAR, BUT WE HAVE BEEN HANDLING IT FROM OUR OWN POCKETS. HOWEVER, WITH LITERALLY NO DONATIONS FOR THE PAST 2+ YEARS IT HAS DEPLETED THE BUDGET IN SHORT ORDER WITH THE INCREASE IN ACTIVITY ON THE SITE IN THE PAST 6 MONTHS. OUR CPU USAGE HAS BECOME TOO HIGH TO REMAIN ON A REASONABLE COSTING PLAN THAT WE COULD MAINTAIN. IF YOU WOULD LIKE TO SUPPORT THE DEVTOME PROJECT AND KEEP THE SITE UP/ALIVE PLEASE DONATE (EVEN IF ITS A SATOSHI) TO OUR DEVCOIN 1M4PCuMXvpWX6LHPkBEf3LJ2z1boZv4EQa OR OUR BTC WALLET 16eqEcqfw4zHUh2znvMcmRzGVwCn7CJLxR TO ALLOW US TO AFFORD THE HOSTING.

THE DEVCOIN AND DEVTOME PROJECTS ARE BOTH VERY IMPORTANT TO THE COMMUNITY. PLEASE CONTRIBUTE TO ITS FURTHER SUCCESS FOR ANOTHER 5 OR MORE YEARS!

Minecraft Modding for 1.8

NOTE: This guide was made specifically for windows, things like the Downloads section may require different instructions depending on your system, and Thank You so much for reading! Minecraft Modding in 1.8 has changed drastically, and it's much easier than before! With all the new features added to make it a lot easier, this guide will show you that anyone could mod this great game! Famous Mods like Thermal Exapnsion which adds a crazy amount of customizable machines that'll automate your base along with Applied Energistics which allows players to spend end-game resources to stash millions of their end-game with a few blocks and some energy. In order to create the environment we need, we'll need to download a few programs to help us make this possible!

Downloading and Setting up Required Stuff!

Because Minecraft was programmed in Java, it's obvious that you'll need a distribution of Java in order to run it. However, because you're now going into an actual programming environment, you'll need the correct Java download to do so. You'll need a Java SDK. 1.8 actually uses the new Java version, Java 8, so head on over to Java's Download and click on 'Java Platform (JDK) 8uXX' where 'XX' is the version number. Select the 'Accept License Agreement' radio button under ' Java SE Development Kit 8uXX' and then select 'jdk-8uXX-windows-x64.exe' if you have a 64-bit version of windows, otherwise, try 'jdk-8u60-windows-i586.exe' It's a relatively large download, so be prepared to grab a snack if you have a slow download speed.

After you installed the JDK, you'll want to check if Java really is installed on your system, or version 8 at least. Open up command prompt (this is done by pressing 'CTRL+R' and entering 'CMD') then type in the following command: java -version You should get the output: java version “1.8.0_60” If you do not, you'll need to proceed with the extra step, if you do have the output, please skip it! The extra step is essentially going into the properties of 'My Computer'. All you have to do is right click 'My Computer' and click on properties. For Windows 10 users, this is done by going into the settings pane, clicking the 'About' category and clicking the 'System info' link. You'll want to click on 'Advanced system settings' with the UAC guard to the left of it. This means you need administrative privileges which i'm assuming you do since you need it to do anything in this guide. A new box shows up and you should click on 'Environment Variables…' with another box popping up. Under the 'Advanced' tab, look under the 'System variables' category and search for the 'Path' entry. Simply double click it and DO NOT DELETE ANYTHING. Simple add a semicolon (;) and then the path of your JDK's bin folder (for example, mine's C:\Program Files\Java\jdk1.8.0_60\bin). This is mainly found in your 'Program Files' folder if you installed Java as 64 bit, or 'Program Files (x86)' if you installed Java as 32 bit.

That's actually the hardest part of setting up the environment (other than the actual environment itself), now you need to install the IDE you'll need to actually program the Mod along with ModLoader to actually program off of. Usually you can either use NetBeans or Eclipse for this, for most of the community prefers to use Eclipse and frankly, I do too! For purposes of this tutorial, all mentions of the IDE both in text and code refers to Eclipse, so if you are to use Netbeans, please adjust according to it. Head over to Eclipse's Website and you'll notice how there are multiple packages of Eclipse to use. You'll want to use 'Eclipse IDE for Java Developers' since any will do, and you'll never need more tools in that package. There are options for a 32 bit and 64 bit download, so download depending on your system. Notice that the actual download is in a .zip file, this is because Eclipse isn't an installer, so you can simply unzip that and now in order to launch Eclipse, navigate to the folder and launch 'eclipse.exe' (but launching is not required yet).

For the last part, we need to setup the actual environment we're programming in. The ModLoader we'll be using is the Forge ModLoader. A huge majority of the modding community uses this because it's simply the most powerful ModLoader out there (and not to mention actually kept up to date). Head over to Forge's Download site and on this page you'll find different ModLoader versions for the version of Minecraft to mod off of. Click on 1.8 and then you'll want to download the 'Src' file from the 'Recommended' category. This is just in case the 'Latest' build doesn't end up crashing your code because of a silly bug. Unzip the Forge Modloader zip and navigate to that folder. At this point, we'll going to be creating a couple of '.bat' files. a 'bat' is short for 'Batch' files and essentially it's a bunch of Commands that's stored in a text file, and is executed when launched. So right click on the empty white part of the folder and press 'New', then create a new '.txt' document. You'll want to name it 'Setup Workspace.bat' and make sure the end is '.bat' instead of '.txt' or else it's not a batch file. To make it simpler, i'll post the three name of the files and then what you'll have to type into it:

Setup Workspace.bat

gradlew setupDecompWorkspace

Setup Eclipse.bat

gradlew eclipse

At this point, you'll want to launch 'Setup Workspace.bat' and then the command line should show up downloading and placing some necessary files in that directory. Once again, large amounts of files are being downloaded here so hang back from a minute. After that's done, execute 'Setup Eclipse.bat' and then wait a little again (this one won't take as long, I promise!). Now, you'll want to launch up Eclipse and it's going to ask you to select a workstation. Did you notice the new 'eclipse' folder in the directory of your ModLoader? You're going to set the path of your workstation in Eclipse to that folder. And there you have it, you've successfully set up your modding environment!

The Class

Now, on the left hand of the screen is a little file explorer called 'Package Explorer', and you should see a 'src/main/java, and a 'src/main/resources'. You'll want to dropdown the first one and delete the package inside this folder (done by right clicking and pressing Delete). Then right click the folder and click on 'New' and then 'Package'. Now, the naming scheme of packages in Java is a little weird. You'll want to always use 'com.' and then your username/moniker or name of the program you're writing. In this example, we're going with the package name 'com.example'. Now right click that package and click 'New', and create a new Class file. The first word in the class files are always uppercase, so our class name for now is 'ExampleMod.java'. After this, the class file is brought to your editor. I'm going to post snippets of code in here to explain each one carefully now and eventually the entire thing to minimize errors.

There are multiple Java imports we need to utilize. An import is when you're taking objects, methods and functions from other packages and classes and essentially referencing them into your code in order to utilize them. So we're going to be importing four things. This goes right below your 'package com.example;'

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;;

We're now referencing stuff we need from the Forge ModLoader in order to setup our first class. This is required in order to create three new methods in the brackets of 'public class ExampleMod'.

    @EventHandler
    public void preInit(FMLPreInitializationEvent event) // Initializes FML stuff before the actual load up
    {
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event) // Initializes FML stuff before the actual load up
    {
    }
    
    @EventHandler
    public void postInit(FMLPreInitializationEvent event) // Initializes FML stuff before the actual load up
    {
    }

There are different portions to these methods, the double slashes to the right of them means that anything afterwards is a comment, which the compiler ignores. This is extremely useful for going back to snippets of code and having it explain stuff for you, or whenever somebody else reads your code (like you reading mines). At this point, we're going to create a new class called 'Reference', this class is basically going to store the information about our mod in a nice and neat class. This goes in the brackets of the 'public class Reference'.

    public static final String MOD_ID = "em";    
    public static final String MOD_NAME = "ExampleMod";
    public static final String VERSION = "1.0.0";

So essentially, these are String variables with certain elements to them. So we were going to add a snippet of code right above 'public class ExampleMod' in the other class but instead of giving them the MOD_ID, MOD_NAME and VERSION Strings in that, we opted to just make another class in order to keep things tidy and easy to change. So under the main class, you're going to post this snippet of code right above 'public class ExampleMod'

@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION)

Now, at this point, you have your main class that you're going to build your mod off of.

package com.example;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;;

@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION)
public class ExampleMod
{
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) // Initializes FML stuff before the actual load up
    {
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event) // Initializes FML stuff before the actual load up
    {
    }
    
    @EventHandler
    public void postInit(FMLPreInitializationEvent event) // Initializes FML stuff before the actual load up
    {
    }
}

This is the heart of your mod, and eventually you'll be seeing this a lot until you have even more classes depending on how complicated your mod is.

Creating a New Item!

This is gonna be a long one. There's going to be a lot of classes and files to be created here, so bare with me. Now, we're gonna be creating yet even more classes this time. We're actually going to be creating two packages within the 'com.example' package also. So create a new package under that called 'com.example.initialize' and create another package called 'com.example.proxy'. Within the first package you created, you'll want to create a new class called 'ExampleItem'. Essentially, the name of your new item should be the name of the class file along with a 'Item' suffixed to the end of it. There's gonna be quite some code we'll post here, so here it is. We'll be importing these five classes first.

import com.example.Reference;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

Then we'll create a new 'Item' object named your new Item

    public static Item example_item;

We'll be referencing this later on, and it's very important to note that if you're going to be adding spaces to names, you'll have to replace it with an underscore. So now we'll be creating four new methods to reference in other classes, each of these have a specific purpose.

    public static void initItem()
    {
        example_item = new Item().setUnlocalizedName("example_item");
    }
    
    public static void registerItem()
    {
        GameRegistry.registerItem(example_item, example_item.getUnlocalizedName().substring(5));
    }
    
    public static void registerRenders()
    {
        registerRenderItem(example_item);
    }
    
    public static void registerRenderItem(Item item)
    {
        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
    }

The first method, 'initItem' essentially creates the actual Item object. Setting an UnlocalizedName means that's going to be the name of the Item code wise. The second method, 'registerItem' actually registers the item into the game and is processed as an Item. The whole reason why we extract any text after 5 characters (which is exactly what .substring(5) does) is because the actual identifier of the object is 'tile.example_item'. We only need 'example_item”, so the substring will only return strings after a certain amount of characters. The Third method, 'registerRenders' calls another method called 'registerRenderItem', the reason we do this is because we don't want to make 'registerRenderItem' just exclusive to the 'example_item' item, so we could create another item class and instead of creating the 'registerRenderItem class, all we have to do is parse that new item into the method from another class. The entire class should look like this:

package com.example.initialize;

import com.example.Reference;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

public class ExampleItem
{
    public static Item example_item;
    
    public static void initItem()
    {
        example_item = new Item().setUnlocalizedName("example_item");
    }
    
    public static void registerItem()
    {
        GameRegistry.registerItem(example_item, example_item.getUnlocalizedName().substring(5));
    }
    
    public static void registerRenders()
    {
        registerRenderItem(example_item);
    }
    
    public static void registerRenderItem(Item item)
    {
        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
    }
}

After doing all this, we'll create two new classes under the package 'com.example.proxy' named 'CommonProxy' and 'ClientProxy'.

The 'ClientProxy' Class:

package proxy;

import com.example.initialize.ExampleItem;

public class ClientProxy extends CommonProxy
{
    @Override
    public void registerRenders()
    {
        ExampleItem.registerRenders();
    }
}

The 'CommonProxy' Class:

package proxy;

public class CommonProxy
{
    public void registerRenders()
    {
        
    }
}

While there's not much to say about these two classes, they are required in order to synchronize items between the client and the server (the CommonProxy class is for the server). Any item you create has to call the 'registerRenders' method in the said Item's class in ClientProxy. Now going back to the 'Reference' class, we'll need to add in two new variables that we'll later use in the main 'ExampleMod' class. Under the three variables we made, we'll add in these two referenced from the two Proxy classes we just created:

    public static final String CLIENT_PROXY_CLASS = "com.example.proxy.ClientProxy.java";
    public static final String SERVER_PROXY_CLASS = "com.example.proxy.CommonProxy.java";

The new 'Reference.java' class file now looks like this:

package com.example;

public class Reference
{
    public static final String MOD_ID = "em";
    public static final String MOD_NAME = "ExampleMod";
    public static final String VERSION = "1.0.0";
    public static final String CLIENT_PROXY_CLASS = "com.example.proxy.ClientProxy.java";
    public static final String SERVER_PROXY_CLASS = "com.example.proxy.CommonProxy.java";
}

Over at the main class, 'ExampleMod', we'll need to add in more snippets of code right under the 'public class ExampleMod' just under the bracket:

    @SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
    public static CommonProxy proxy;

Essentially, we're referencing strings from another class just like the '@Mod' statement. Your new 'ExampleMod' class should look like this. Now, we'll need to start initializing the actual items. Under the 'FMLPreInitializationEvent' method, you'll add in these two lines which basically calls two methods we had created under the 'ExampleMod' class:

        ExampleItem.initItem();
        ExampleItem.registerItem();

and then add another line under the 'FMLInitializationEvent' method:

     proxy.registerRenders();

Your new 'ExampleMod' class should look like this:

package com.example;

import com.example.initialize.ExampleItem;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import proxy.CommonProxy;

@Mod(modid = Reference.MOD_ID, name = Reference.MOD_NAME, version = Reference.VERSION)
public class ExampleMod
{
    @SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
    public static CommonProxy proxy;
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) // Initializes FML stuff before the actual load up
    {
        ExampleItem.initItem();
        ExampleItem.registerItem();
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event) // Initializes FML stuff before the actual load up
    {
        proxy.registerRenders();
    }
    
    @EventHandler
    public void postInit(FMLPreInitializationEvent event) // Initializes FML stuff before the actual load up
    {
    }
}

Now, we'll need to start giving the item actual textures and we need to define the how the model is going to look like. Under the Package Explorer, find 'src/main/resources' and create a new folder named 'assets', under that create another called 'em', then create two new folders under than called 'models' and 'textures'. Create a 'item' folder under the 'models folder and then you'll want to create a next text file. Now, the extension of this file has to be a '.json' file, so save it as the name of your new Item, 'example_item.json' and then put in the following:

{
    "parent": "builtin/generated",
    "textures": {
        "layer0": "em:items/example_item"
    },
    "display": {
        "thirdperson": {
            "rotation": [ -90, 0, 0 ],
            "translation": [ 0, 1, -3 ],
            "scale": [ 0.55, 0.55, 0.55 ]
        },
        "firstperson": {
            "rotation": [ 0, -135, 25 ],
            "translation": [ 0, 4, 2 ],
            "scale": [ 1.7, 1.7, 1.7 ]
        }
    }
}

The only thing you really want to change in the ' “layer0”: ' where 'em' is the MOD_ID you defined in the 'Reference' class and then after 'items/', the name of your new Item. We actually can find the main source code of the entire game under the Package Explorer, by going into the 'Referenced Libraries' and then opening up the 'forceSrc-XX' jar file. For example, we can navigate towards 'net\minecraft\block\BlockDirt' and find out what lets the Dirt Block in vanilla Minecraft tick.

Creating a New Block!

Of course, Minecraft would be nothing without blocks. In this section, we'll learn how to program in a block! You'll want to create a new class inside the 'com.example.initialize' package called 'NameBlocks', in our case, we would have 'ExampleBlocks'. In here, we need to create methods similar to

Minecraft | Programming | How To


QR Code
QR Code minecraft_modding_18 (generated for current page)
 

Advertise with Anonymous Ads