The Ultimate Guide to Minecraft Modification with Java


The Ultimate Guide to Minecraft Modification with Java

This Minecraft Modding tutorial will show you how to create a custom Sword and get you started in Minecraft modding.

We will be using Minecraft 1.12.2 because it is compatible with our current Minecraft courses. You may need to set up different versions.

As a rule, Minecraft mod code will not work with any version of Minecraft. 1.13 and higher versions will not support 1.12 mods.

This tutorial requires a Mac or PC computer. Chromebooks and mobile devices won't work properly.

Step 1: Install Java Developer Kit (JDK). Step 2: Setup your Text Editor
Step 3: Install the Forge
Step 4: Install Pinta
Step 5: Create your project
Step 6: Create Your Own Mod – A Custom Sword
Step 7: Create your Mod
Step 8: Test your mod!
What can Minecraft 1.12.2 allow kids to do?

Step 1: Install Java Developer Kit (JDK).

You will need to download Java Developer Kit in order to make Minecraft Modding in Eclipse run correctly.

The JDK 8 download link is available HERE. To use Minecraft Modding properly, you will need JDK 8.

The download page should detect your platform and provide the correct download. The version I am downloading is for Windows 64-bit. You can click “Other platforms”, to search for versions for other operating systems. To begin your download, click the “Latest release” button.

The executable file will now be downloaded.

Once you are done, locate the file in your downloads directory and run the executable.

Follow the instructions in the pop-up window to install the JDK on your computer. Click on each button, keeping the default settings, until the JDK is installed.

To continue, you will need to agree with the End-User License Agreement.

Let Java run until it is done installing.

Now that JDK has been completed, we can start the next step to set up our code editor.

Step 2: Create your Text Editor

Before we can start Minecraft modding, we need to download some tools.

First, let's download the Eclipse IDE. It is one of the most widely used professional text editors for Java.

Click HERE to download the installer. Look for the Get Eclipse IDE 2020 – 06 Download area. It looks like this:

Click the Download 64 bit button to open the next page where you can download. Wait for Eclipse to finish downloading by clicking the Download button.

Open the executable file from your download file to launch Eclipse.

After the launcher opens select the Eclipse IDE For Java Developers.

Next, select the default location to install the software and click the INSTALL button.

You will be prompted to accept the Eclipse agreement.

Next, you will be prompted to accept the license agreement.

Accept the Eclipse Foundation Software User Agreement by ticking the box “Remember accepted licens”

Once you accept it, you can move on to the next step.

Accept the Eclipse Foundation certificate, as shown in the photo below.

Eclipse will then be downloaded and available for use when we need it to write our code.

Next, we will install the Java Developer Kit to allow our code to work with Minecraft.

Step 3: Install the Forge

Next, you will need the 1.12.2 Minecraft Forge version. This will allow us to modify Minecraft 1.12.2. These instructions should work with any Minecraft version, from 1.12.2 to the latest.

The download link is HERE. Follow the instructions below.

This page contains the recommended and most recent version of Forge. The Recommended Version Mdk (Mod Development Kit), file is available for 1.12.2.

You don't have to click on anything except the “Skip” button at the top-right corner. This button is highlighted in red below.

Once you have downloaded it, locate it in your downloads directory, right-click on the zip up folder, and then select Extract All…

Next, click Extract.

This will be our project folder. We will make a copy, rename it, and move it to another location on our computer.

We recommend that you keep a copy of this document in your Documents folder, or on your Desktop.

Right click on the folder and copy it.

In this example, we will call it ForgePractice.

We have the Forge folder setup and are ready for our new project!

Step 4: Install Pinta

Next, we need to install the Pinta software that will allow us to change the appearance of our Sword Texture.

Click the link HERE to go to the Pinta Download Page.

Click the link to download the OS for Windows or Mac from this page.

Once the installer has been downloaded, open it in your downloads folder. Then, run the installer.

Install the application completely and accept any agreements along the route.

When the installation is complete, close it.

We now have the programs that we need to make our mod.

Next, we need to create our project.

Step 5: Create your project

Start Eclipse. It will ask you to select a directory to be used as Eclipse's workspace. This directory must be located outside of your project folder. I recommend that you create “eclipseworkspace” within your Documents folder. You can also use the default Eclipse location.

Eclipse will now open. Close the Welcome tab.

Click on “Import Projects …”” in the Package Explorer.

Click Next in the “Import” window that opens.

Next, click “Browse …”” and choose your project folder. Click “Select Folder”.

This should now be visible. Click Finish. After importing the project, it should close.

Now you should see your default workspace view.

Click the Gradle Tasks tab in the lower right corner of the window. It looks like this.

Double-click on genEclipseRuns and expand the “fg_runs” task folder to run the task. This will set up our Minecraft launch configuration. Once the task is finished, we can import our new launch configurations.

Navigate to the File menu for Eclipse at the top of your window. Click it and then click Import in that menu.

In the menu that opens, click the arrow next Run/Debug. Select Launch Configurations, then click Next.

Checkmark the box next To ForgePractice (or the name of your folder if it is named differently) in the next menu. It should display the runClient or runServer configurations. Click Finish.

We need to make one more edit before we can start Minecraft. Click on the arrow beside the green Run button. Click on Run Configurations. This option is also available in the Run menu at Eclipse's top.

In the new window, click on the Environment tab. Go to the MC_VERSION section of the list.

Double-click the $MC_VERSION value to change it to 1.12. Next, click Run. The Eclipse should now launch your Minecraft.

You can close the Minecraft Client. Now you can run the game by clicking the green Run button in the toolbar at the top of Eclipse.

Now we are ready to learn Java and create a Mod!

Step 6: Create Your Own Mod – A Custom Sword

Our Minecraft modding tutorial is finally here!

Once Eclipse has been opened and loaded, you can start typing java code.

Let's start by opening the Mod java example file that has been provided.

Click the arrow to the right of the name to open the project folder. The name of your project folder will likely match the name you gave it in Documents.

Now open the “src/main/java” folder and then open the “com.example.examplemod” file and inside you will find

Double-click this to open this java code file.

This file contains our start code. It contains our mod ID, name, and description. In ExampleMod, we first need to find the lines that delineate our MODID or NAME.

Modify the MODID to a sword and make sure it is in lower case

This is the unique ID we will use to identify our mod.

The NAME is the mod's name as it will appear on Minecraft.

This is what you like.

These are String variables so make sure they are in quotation marks

Strings can be either words or characters.

(We will be covering variables in the next few minutes).

Open the mod information file by going to the src/main/resources directory.

Open and change modid to “sword”. You can also change the name, description and credits to suit your needs.

These Strings will be read by code if they are not in quotation marks.

Next, create variables for our ToolMaterial or sword.

These lines should be placed beneath the private static Logger logger line.

Variables are useful in code because they act like boxes with names that store information we can use.

We are creating variables myToolMaterial, and mySword.

The types of variables are ToolMaterial, Item.

Once the variables are created, import the code files that describe what a ToolMaterial or an Item do.

You can do this by hovering over the red error lines beneath ToolMaterial or Item.

Import the code shown in the dropdown menu.

Start with the ToolMaterial shown below.

Next, import the Item as shown below.

We will now be creating a custom sword in Minecraft.

This is where you define the custom tool material variable that we created.

Enter the preInit function as shown. Below the logger line, enter the myToolMaterial.

This line fills in myToolMaterial variable and provides information about the material's use for tools.

This will be our tool material. Let's fill in the name, harvest levels, damage, etc.

Change the name to a String variable, which is the material name.

This can be named whatever you want.

The harvest level is a measure of how much it can extract resources from certain minerals.

This is how we would determine if the material can be used to make diamonds from Diamond Ore.

This is why it can mine whatever we want.

MaxUses is the number of times it can be used before it breaks. Efficiency is used for harvesting tools to determine how fast it will mine or harvest a block.

It is the amount of damage it does to an entity when it hits it.

Enchantability is a function of how easy it is for you to enchant.

Add a description of what your sword is after you have completed the material line.

This line delineates the sword as a new type of sword called CustomSword.

We must create this class. To do that, we hover over the red error line and click

Create the class “CustomSword”

A new window will open, please keep these settings at their default settings and click Finish to close it.

This will create a new Java file CustomSword, and open it automatically.

This is a Class, which is code that describes what CustomSword is and how it behaves.

We can make sure that the import and public classes lines are changed to “ItemSword” instead. This will define our class with all the information that is already available for swords in Minecraft.

This allows us to swing it and damage creatures, as well as pick up and drop it, and any interaction a sword has in the code.

Now we need to add a constructor to our class.

This is how the sword is made. This is how blueprints are used to create buildings.

We are creating specific rules to guide the creation of our sword.

Once the constructor is added in, change it to remove the Material reference in the parentheses and then fill in our ExampleMod.myToolMaterial.

After these changes have been made, we need the RegistryName, UnlocalizedName and CreativeTab to be able to use our sword.

Because our code uses these names to identify our sword and link it to our texture, the Registry and Unlocalized names must be “my_sword”.

You can change the CreativeTab to the tab where you want the sword.

We chose COMBAT, but you will see a list where you can choose which tab you want your sword in.

Once you have completed this, your class is ready for action.

We will need to create a new Java class to register our sword in Minecraft.

Go to the Package Explorer on the left side of Eclipse and right click on the com.example.examplemod package and create a new Class (as shown below).

This will open the class window that we saw earlier.

Next, we will name it CommonProxy. Then, we will select Finish.

Now we want to go above the public class CommonProxy line and write the @mod.EventBusSubscriber.

This will allow the class to be run during Minecraft's loading so that it can register our sword in the game.

Just like Item and ToolMaterial, we need to import the mod code.

Once the file is imported, we will need to create a new function to run specific code to register the item in Minecraft.

Include the ExampleMod.mySword in the registerAll() parentheses. This tells register function that you are trying to register our sword.

Now, import the code from this Class.

We need to import SubscribeEvent and RegistryEvent as well as Item.

We are importing code from another source to assist us with our register code.

Start with SubscribeEvent, as shown below.

Next Import RegistryEvent, as shown below.

Finally, Import Item (net.minecraft.item), as shown below.

After these imports are completed, we can test the “sword”, but it won't look like a sword yet.

To test our code, click inside a code window. Next, go up to the green button and press it only one time.

Make sure to press the green button only, not the buttons with icons in the corner.

After some time, you will see a window open Forge Minecraft.

Wait until Minecraft is fully loaded to the main menu.

After you are done waiting, click Single Player on the main menu.

Next, click on Create New World to create a Creative mode game.

Next, change the game mode from Creative to Creative and modify the name. Finally, select Create New World.

This will open the new Minecraft world. It may take some time to open it.

Once the world has been opened, click on the “e” button and the Creative Tab inventory will open.

Go to the Combat tab, or the tab you selected when we set the Creative Tab within our code.

Scroll down to the bottom of this tab and make sure your sword is there.

We will be changing the name and look of the sword, but if you place it in your inventory, it will work exactly as we coded!

After you have tested your purple and black block blade, let's get back to our code and link the model and texture in our code.

Exit the Minecraft window, open, and add a registerRender function to the CommonProxy Class as outlined below.

This will register the sword model based on the item you want to register.

In the next few steps, we will link this with our sword.

We need to import more code.

Make sure to import ModelLoader and ModelResourceLocation.

ModelLoader is your first step.

Next, Import ModelResourceLocation as shown below.

Let's now make our swords!

Register the ExampleMod.mySword variable using the registerRenders function.

We now need to import the ModelRegistryEvent Code so that our models properly render in Minecraft.

Now, we must name our sword.

Right-click on the src/main/resources to create a new untitled text file.

Add a code line to name the sword.

You can change the name of your sword to the right side of the equals symbol (=).

Let's now save this untitled file.

Click File > Save As to open a window asking you to choose the file's location.

Select the MDKExample>src>main>resources folder and change the file name to be en_us.lang and then click OK to make the file

Now, we need to create our sword texture and import into our project.

Below is a picture I have of an Iron Sword from Minecraft.

Right-click on it, select “Save image …” and save the file as “my_sword.png”.

Because Minecraft requires a smaller file, it is small.

Once you have it saved click on it and then copy it.

Once the file is copied, let us find the folder where we need it to be pasted.

Navigate to ForgePractice's project folder. Open the src> main> resources folder. Copy and paste the my_sword.png file into this folder.

Now, return to Eclipse and place a new Text file in the src/main/resources directory as we did before.

In this new file, enter the code that will delineate the item sword resources.

This file will be saved as a JSON file. To do this, go to File > Save As and save the untitled file my_sword.json within MDKExample > main > Java > resources.

Click the triangle next to Package Explorer to change the Package Presentation from Hierarchical. This is because we will be adding more packages to organize and set up our code so that our sword files can be properly managed.

We now need to create packages for our resources folder.

Right-click on the folder to add a new package

Name it assets.sword in the pop-up window and click Finish to create the package that will contain our other three packages.

Right click on assets.sword and add a new package.

In the pop-up window, name it assets.sword.lang.

Now, make two additional packages within assets.sword

Name these “assets.sword.textures” and “assets.sword.lang”.

Once you have made these, drag them into their respective folders, as shown in this image.

Customizing your sword is the last thing you should do.

Pinta can be opened by searching for Pinta using our search bar, and then opening the Pinta program.

Once Pinta is open, click File > Open to open a new window.

Let's now locate our sword in our project folder ForgePractice.

Now it's time to paint the sword!

Zoom in all the way and turn anti-aliasing on. Also, change the brush width to 1. These settings are highlighted in this image.

Now all that's left is to paint your sword, and then erase or add whatever you like.

Use the colors, the brush and the eraser tool.

As with the paint brush, make sure you change your eraser anti-aliasing and brush width.

Paint your sword to make it look however you like. To undo any mistakes, hold down CNTL and press down Z. On a Mac, hold down the Command button then press down on Z.

Once you are done, go to File > Save and ensure that you save any changes you make.

We are done with our custom Sword Mod!

Now you can test it by clicking the green play button, just like we did before!

You will need to make sure everything is exactly as you want. Then, compile your mod and test it in Minecraft.

Step 7: Create your Mod

Now that we have our code, it is time to compile and create our mod.

To build it, you will need to navigate to the project folder and right-click in an open space to select “Open Powershell Window here” or “Open Command Window here”.

Once the window is opened, type in the command “./gradlewbuild” and hit Enter to execute this command.

Wait for the BUILD SUCCESSFUL message to appear.

Once the build is complete, go back to ForgePractice's project folder and open the build folder.

Modid-1.0.jar is required.

This is our build mod file

Next, we'll show you how to load your Mod into your Minecraft game.

Step 8: Test your mod!

To test our mod, we must make sure that we have regular Minecraft Forge installed.

We were working in the Forge developer kit.

We now need to access Minecraft Forge.

Return to the Minecraft Forge download page you were at earlier.

Once you are on this page, click the regular installation button.

After the download is complete, open the executable file from your downloads folder.

Once it launches, you will see the Forge installation window.

Make sure that Install client is selected. Keep the default location, then click OK.

After the Forge client has been installed successfully, press OK to confirm.

After Forge has been installed, we need to locate our build mod file within our Eclipse project folder.

Open your ForgePractice folder.

Next, open the build folder.

This is where our Mod will be.

Right click and rename modid-1.0.jar as you wish

Once the file has been renamed you can right click on it and copy it.

Once the jar file has been copied, we will need to open the folder containing our mods.

Type %appdata% into the search bar. Open the folder that appears in the search results.

Once you have opened the folder, open the.minecraft file.

You will see a mods folder in this.minecraft directory. Open this folder.

Next, copy the mod you copied earlier.

Your mod is now ready to go in Minecraft!

Now launch Minecraft and open Forge. Search and Open the regular Minecraft version.

This must be the Java version.

It will not work with Windows 10 or a mobile Minecraft version.

After the Minecraft Launcher has been opened, click the Launch Options tab to add new.

Change the version to release 1.12.2-forge in the Add New window

Name it Forge 1.12, or something descriptively comparable.

Click the drop-down next to PLAY to return to the main Minecraft News tab. Select the Forge 1.12 launch version that we made.

Once you have selected the option, click PLAY to launch Minecraft Forge.

Once Minecraft has been loaded, we will need to create a new level similar to what we did when we tested our sword.

Go to Single Player, then create a new world just like we did before.

Change the setting to Creative Mode and modify your World Name.

Once you are done, click on the Create button to start the Minecraft game.

Similar to earlier, click “e” on the keyboard to locate your sword in Creative Tab. Next, navigate to the tab where you want your Sword to appear.

Mine is the Combat tab, and as you can see the custom sword is at bottom of the list.

You have now created your Minecraft Mod from scratch!


You can make another sword with the same techniques, or you can challenge yourself to make an Axe or any other tool.