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

Modding a game usually refers to modifying/tweaking a game’s normal files to add extra functionality or content of a game. Modding in Minecraft is extremely popular and the community provides really great extra mechanics like Industrial Craft 2 with an added electricity mechanic and Buildcraft 3 with an added pipe mechanic.

Prerequisites and Tools

Of course, modding a game requires you to have the actual game and know some programming, here’s what you’ll need to start dwelling into the world of game modding:

  1. Programming: Of course, this should’ve been obvious. You’ll need knowledge in Java Programming, the official Java Documentation] provides extensive tutorials and references on the language. # Java itself and the JDK (Java Development Kit). * There is a new version of Java and JDK (Java 8, JDK 8), but you would want to download [[https://www.java.com/en/download/manual.jsp|Java 7 and JDK 7 since 8 includes major code rewrite which would not be compatible with anything written in Java 7.
  1. APIs: An API stands for Application programming interface. This tells other software parts how they should work with your coding, acting as a middleman. You’ll need this for Minecraft so you don’t have to recode the entire thing just to add an ore or so:
  • ModLoader: ModLoader was a dominant API to use before Forge came out, and even has some part of its code embedded in Forge.
  • Forge ModLoader: A backwards compatible API with ModLoader properties, but adds tons of new methods, classes and utilities to create advanced mods and mod packs.
  • Minecraft Coder Pack (Although, not an API actually): MCP is a very simple tool to use since all it would do is break down Minecraft’s code into simpler, easy to read and edit code.
  1. IDE: An IDE stands for Integrated Development Environment and it’s incredibly helpful for any type of programming. Usually, MCP and Forge generate files that would be compatible and work with Eclipse.
  • Eclipse: A widely-known Java IDE and includes massive amounts of features for aid in Java programming. Comes with syntax correction, a decent semantics error correction system, project file explorer and built in editors/explorer.
  • NetBeans: A great alternative to Eclipse, features a syntax correction system similar to Eclipse and project explorer.

Setting up your Java environment

This tutorial is going to assume that you don’t have Java 7 nor JDK 7 (but you should have Java if you play Minecraft). You can download them from the Prerequisites section of this tutorial. You should install Java 7 and the JDK 7 like any other installation, shutting down any programs it prompts you to shut down before the actual installation. After you have installed both Java 7 and the JDK 7, you still have to tell your system to use it. Right click ‘Computer’ in the start menu and from there, you should choose ‘Properties’ from the context menu. Click on ‘Advanced system settings’ on the new Control Panel window and select the ‘Advanced’ tab. Click on ‘Environment Variables’, under ‘System Variables’, find the ‘PATH’ category, and double click on it. In new window, select the end of text in the text box, ‘Variable value’, add a semicolon (;) since every entry in the category are separated by one. You can then modify it by adding the location of your Java 7 AND JDK 7 installation including the program itself (typically is ‘C:\Program Files (x86)\Java\jre7\bin\java.exe’ and ‘C:\Program Files\Java\jdk1.7.0_51\bin\java.exe’, don’t forget the semicolon). Check to see if you did this correctly by opening Command Prompt as Administrator, then typing ‘java -version’. You should have Java specifications outputted on the command prompt.

Setting up your Coding environment

This tutorial is going to take the assumption that you are using Eclipse and Minecraft Forge ModLoader (once again, links are in the prerequisites section). They undoubtedly the best tools to use when modding in Minecraft, since Forge supports the use of thousands of item types and most mod developers include official Eclipse support. Eclipse doesn’t really have anything to setup except for specifying the project path. Forge Modloader requires downloading and generation of the Eclipse files, so that’s what we are going to explain in this tutorial.

Download a copy of the recommended source build (or ‘src’ on the site). You can download the latest version, but that may lead to unnecessary bugs. You can then extract the ‘.zip’ file to anywhere on your computer. Inside the folder, you are going to have to generate your own files for mod development. Hold down shift, then right click any blank space inside the folder and click on ‘Open command window here as Administrator’. Check to see if the path of the folder is annexed behind your text cursor. Now, type in ‘gradlew.bat setupDecompWorkspace –refresh-dependencies’. This will setup all the dependencies of Forge ModLoader including MCP, Java Libraries and setting up the actual environment. This requires about less than 10 minutes. After that’s done, you will have to specify which IDE you are going to use. In the same command prompt, type in ‘gradlew.bat eclipse’ since we are going to use Eclipse (you would type in ‘gradlew.bat idea’ if you are using NetBeans). Now that we have the environment setup, we can launch up Eclipse and point where the workspace is going to be. This is typically ‘YourForgeFolder\eclipse’. Congratulations, you are now set up for coding and development in the Minecraft game. To make sure that you can test, play and/or debug your mod, launch the game by pressing the green play button at the top of your IDE.

Actual Coding

Now that you are done with setting up Minecraft and the coding environment, you can finally begin to code. We will be using Minecraft 1.7.2 in this tutorial, and of course, we are going to assume you know how to code Java at this point. If you do not know how to code in Java, I suggest you stop reading this tutorial and start to learn it. Don’t forget to treat the internet as your library, it has all the information you need to do and learn anything.

Before we start anything, I do have a few tips that if you have done programming or Java programming in particular before, you should be familiar.

Remember that Case Matters: Realize that when coding, there’s going to be a bunch of text placed on screen and everything's going to get clumped up. Casing have made this easier, since it’s specifically needed for specifying names in Java. Some functions does require either ‘camelCase’ or ‘TitleCase’. Make your code readable and understandable: Like I just said, your code is going to be very bunched up. You’ll probably end up forgetting which line of code does what too without careful examination as well. To prevent this, you’ll want to put in comments. This is done by placing two forward slashes behind any line of text. You can also place in a forward slash and asterisk (/*), place it multiple lines of comments and end it with an asterisk and a forward slash (*/)

  1. Be comfortable with errors: Any experienced coder will say that half of the time spent coding is done by correcting errors. Eclipse will only help with the most obvious spelling and logical errors, it’s an invaluable tool but not a reliable tool.

Remember that when I said we were done with setting up Minecraft’s coding environment, and we can finally begin to code? Yeah, just that. We’re going to have to set up the coding bits so that we have a place to put our future blocks, items, recipes and etc. You should have your Eclipse project workspace pointed in the ‘eclipse’ folder that your Forge ModLoader API is in. If you do not see a project explorer on the left of your screen, then you have to switch to ‘Java’ workspace mode. You can activate this by exiting out of the welcome screen when you first open Eclipse. You should now be prompted with a different workspace. Start to expand the columns on in the ‘Package Explorer’ and find a package that says ‘com.example.examplemod’. You are going to want to drop that down and find a file called ‘ExampleMod.java’. By default, Forge Mod Loader generates this so that users can just simply add onto it. It should look like this:

package com.example.examplemod;

import net.minecraft.init.Blocks;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
@Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
public class ExampleMod
{
    public static final String MODID = "examplemod";
    public static final String VERSION = "1.0";
    @EventHandler
    public void init(FMLInitializationEvent event)
    {
       // some example code
       System.out.println("DIRT BLOCK >> "+Blocks.dirt.func_149732_F());
    }
}

You’ll probably notice a red squiggly line under the code, ‘func_149732_F’. A great thing about Eclipse is that it can solve logical errors for you by simply hovering your mouse over that certain code, then you’ll be greeted a couple suggestions on how the fix it. It seems like its just a simple name error, you’ll want to like on ‘Change to func_xxxxxx_x’ (This may vary on different modpack). Now, that squiggly line is gone, you’ll also notice that a red ‘x’ bottom left the file favicon which is located on your upper toolbar is present. You’ll have to save changes if you want to make that red ‘x’ disappear. Remember, Eclipse still treats every file in the package explorer as separate Java and class files, so errors are still present if you try to compile them without saving.

I also realise that all of this code is completely confusing, and that’s the beauty of coding! I like to break down each line of code or function and explain to them in a list, so here it is:

@Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)

This line is saying to get variables within the ‘ExampleMod’ java file and denote them into the Forge ModLoader system.

public static final String MODID = "examplemod";

This line is trying to start a variable ‘MODID’ and make denote a string to it, allowing for the previous line to get its modid data from here.

public static final String VERSION = "1.0";

This line is trying to start a variable ‘VERSION’ and make denote a string to it, allowing for the previous line to get its version data from here.

@EventHandler

This line is setting up a denotation that the following code will be initialized as an event and started up.

public void init(FMLInitializationEvent event)

This line is creating a method dedicated to anything that the modder wishes to initialize. Usually, minecraft modder can call class/java files from here to save a lot of space, since this is where initialization of functions in a mod is done.

You can probably guess the bits where you have to edit to adjust to you mod. This is the code I have set up for mines:

package thedischarger.tutorial;

import net.minecraft.init.Blocks;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
@Mod(modid = "Discharger's Modding Tutorial", version = "0")
public class ExampleMod
{
    @EventHandler
    public void init(FMLInitializationEvent event)
    {
       System.out.println("DIRT BLOCK >> "+Blocks.dirt.func_149730_j());
    }
}

Minecraft | Programming | How To


QR Code
QR Code minecraft_modding_1710 (generated for current page)
 

Advertise with Anonymous Ads