In this Minecraft Modding tutorial, we will be providing you with step-by-step instructions on how to get started with Minecraft modding while creating an awesome custom Sword that you’ll get to play in the game.

We’ll be using Minecraft 1.18, as it is the version compatible with our current Minecraft courses. Newer versions may use different setup instructions.

As a rule of thumb, Minecraft mod code is not compatible from version to version. For example, 1.18 mods will not work with 1.19 and above.

You’ll need a PC or Mac computer for this tutorial, as Chromebooks or mobile devices will not run the software properly.

At CodaKid we have taught over 50,000 students Minecraft coding, and have won numerous industry awards for online courses including a Parents’ Choice Gold Award and CODiE Finalist for Best Coding and Computational Thinking Solution.

While we teach coding for kids, this guide can be used by teachers, parents, or anyone with an interest in creating a custom Sword Mod for Minecraft Forge.

We hope that you enjoy this free step by step guide to covering one of the first courses we teach in our Minecraft Modding series.

We’ll cover the very basics of what you’ll need to start Minecraft modding, and you will learn how to use Java, one of the most popular programming languages in the world.

We’ll also teach you how to download and use the Eclipse IDE, a text editor used by professional developers at companies such as Facebook, Google, and Amazon.

We will continue to update this blog in the coming months and transition to more recent versions of Minecraft as they become stable for mod creation. Our next big course revision will take place after the upcoming Minecraft Caves and Cliffs Update.

Step 1: Set up Java Developer Kit (JDK)

We will need to download the Java Developer Kit that will let our Minecraft Modding in Eclipse work correctly.

You can find the download link HERE for JDK 17. The version of JDK you need is JDK 17 to work properly with Minecraft Modding.

On the website, you’ll find several versions of JDK 17. For this tutorial, we’ll be utilizing version 17.0.2+8 or the most recent release. As shown in the image below, I’m selecting the Windows(x64) “.msi” version for download. However, versions of the JDK are also available for other platforms, allowing you to download the version that suits your system’s requirements best.

The download will start as soon as you click on the “.msi” download button. After downloading, you will find the executable file in your download folder.

Run the executable file to install the JDK.

Please follow the instructions provided in the pop-up window to install the JDK on your computer. Click on the “Next” button at each step, keeping the default settings unchanged, until the JDK installation is complete.

Now that the JDK installation is complete, we can proceed to set up our code editor in the next step.

Step 2: Set up your Text Editor

Before we begin Minecraft modding, we’ll need to download some tools.

First, for this guide, we are going to download the Eclipse IDE, one of the most popular professional text editors for Java in the world.

To download the installer, please click on the following link: Eclipse Downloads | The Eclipse Foundation Look for the “Get Eclipse IDE 2023 Download” section that resembles the following image:

Click on the “Download x86_64” button, and the next page will appear where you can initiate the download. Click on the “Download” button displayed on that page and wait for the Eclipse file to finish downloading.

Locate the executable file in your downloads folder and open it to launch the Eclipse installer.

Once the launcher opens, please select the “Eclipse IDE for Java Developers” option.

On the next window, please keep the default installation location and then click the “INSTALL” button.

The next window will appear, where you will need to accept the agreement for Eclipse. Please read the agreement and then click on the “Accept” button to proceed.

After completing the above step, the installation process will begin.

After a successful installation, click on the “Launch” button to start the Eclipse IDE.

Once this process is completed, Eclipse will be downloaded and ready for use when we need to write our code.

The next step involves installing the Java Developer Kit (JDK), which will enable our code to work seamlessly with Minecraft.

Step 3: Set up Forge

Next, you’ll need to download Minecraft Forge for the 1.18 version, which is essential for modding Minecraft 1.18. The instructions provided here should be applicable to any Minecraft version from 1.18 onwards.

You can locate the download link HERE, and then simply adhere to the instructions we’ve outlined below.

On this page, you’ll find the latest and recommended version of Forge. Download the Recommended Mdk (Mod Development Kit) file for 1.18, as depicted.

You will be redirected to Forge’s advertisement page. You don’t need to click on anything except for the “Skip” button located in the top-right corner, highlighted in red below.


Note:If you use an ad blocker, this page may not load properly. For this page to function properly, you must disable your ad blocker.

Once the MDK is downloaded, locate it in your downloads folder. Right-click on the zipped folder and select “Extract All…” from the options that appear.

In the next window, please click on the “Extract” button.

This will be our project folder, so we want to create a copy, rename it, and move it to a new location on our computer.

We suggest making a copy in either your Documents folder or on your Desktop.

Right-click on the unzipped forge folder, select “Copy,” and then navigate to the desired location where you want to place it. Right-click in the location and select “Paste.” Ensure that you give it a descriptive name.

In this example, we will name it “ForgePractice.”

We have successfully set up the Forge folder, and now we are ready to create our new project!

Step 4: Install Pinta

Next we want to install the Pinta program we will use to change the look of our Sword Texture.

To download Pinta, please follow this link: HERE and you will be directed to the Pinta download page.

On this page, click on the download link corresponding to your operating system, whether it’s Mac or Windows.

Once you have downloaded the installer, open it from your downloads folder and run the installer.

Proceed with the installation process, ensuring that you fully install the application and accept any agreements presented along the way.

Now that we have the necessary programs, we are ready to create our mod project.

Step 5: Create Your Project

To begin, launch Eclipse. It will prompt you to choose a directory to use as Eclipse’s workspace. It’s important to note that this directory should be located outside of your project folder.

I recommend creating a folder named “eclipse-workspace” within your Documents folder. However, you can also choose to use the default location provided by Eclipse.

Eclipse will now open. Please close the Welcome tab by clicking on the close button (usually an “X” or a tab close button) located on the Welcome tab itself.

In the Package Explorer, click on “Import projects…”

In the “Import” window that pops up, select “Existing Gradle Project” and click Next.

On the next page, click “Browse…” and select your project folder. Click “Select Folder”.

You should now see this. Click Finish. It should close after importing the project.

You should now see your default workspace view:

Go into the Gradle Tasks tab at the bottom of the window. It looks like this:

Expand the “forgegradle runs” task folder, and double-click on genEclipseRuns to run the task to set up our Minecraft launch configuration.

Once it’s finished running, Go back to the “forgegradle runs” task folder and double-click on “runClient” and wait for the process to complete. It will open the Minecraft window; you just need to close it after it has loaded and proceed further.

After that, we need to import our new launch configurations.

Go to the File menu of Eclipse near the top of the window. Click it, then click Import in the menu that appears.

Click the arrow next to Run/Debug in the menu that appears. Select Launch Configurations and click Next.

In the next menu, checkmark the box next to ForgePractice (or your folder name if you named it differently). It should show the runClient and runServer configurations selected. Click Finish.

Just one more edit before we can run Minecraft. Click the arrow next to the green Run button. Click on Run Configurations. You can also find this from the Run menu at the top of Eclipse.

Go to the Environment tab in the new window that appears. Go to the MC_VERSION line in the list. Click on the Add button to include the MC_VERSION entry if it isn’t already there.

Double-click on the ${MC_VERSION} value and change it to 1.18 Then click Run. Your Minecraft should now launch from Eclipse.

You can close out of the Minecraft Client; you should now be able to run the game just by clicking the green “Run” button in the toolbar near the top of Eclipse.

We are now ready to start Creating a Mod and learning Java!

Step 6: Make Your Own Mod – A Custom Sword!

Finally our Minecraft modding tutorial begins!

Once Eclipse is loaded up and opened, we are ready to start typing in java code.

Let’s open an example Mod java file that is provided for us that we will be starting from.

On the left side of the window, open the project folder by clicking the arrow next to the name. Your project folder will likely be named with the same name you gave to the folder in Documents.

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

Double click this to open up this java code file.

This file contains some starting code. Keep the first line which the package name and remove the rest of the code.

Now add the below lines of code to the ExampleMod.java file.

@Mod(ExampleMod.MODID)

This line serves as your mod’s name tag. You use this to notify Minecraft that your code is a mod. ExampleMod.MODID is your mod’s unique name or ID, similar to how each student in a school has a unique roll number.

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)

This is equivalent to saying your mod wants to listen in on important announcements (events) made by Minecraft while it is booting up and running. This way, your mod knows when Minecraft is doing something that requires its involvement. For example, while Minecraft is preparing all of the blocks, your mod can say, “Hey, I have a new block to add too!”

Now, we’re going to create a new class. Think of a class as a blueprint for building something. In this case, we’re building our Minecraft mod. “public class ExampleMod” indicates that you’re creating a new public class (or blueprint) for your mod and naming it ExampleMod. It’s currently empty – there’s nothing between the brackets. But soon, you’ll be inserting a lot of code to make your mod do cool things!

After adding the class, you will notice the red lines under the above lines of code. We need to fix them before moving forward.

Simply place your cursor over the word “Mod” with the red line under it to import the package shown in the image.

Ready to personalize your mod? It’s time to give it a unique name and version number! Here’s how we do it:

public static final String MODID = “examplemod”” This is your mod’s unique nickname, similar to a secret codename known only to Minecraft. Just keep it lowercase and avoid spaces.

public static final String MODNAME = “YOUR MOD NAME HERE”” This is where you get to choose a show-stopping name for your mod, one that players will notice and remember. Replace “YOUR MOD NAME HERE” with any name that will distinguish your mod!

public static String VERSION = “0.0.1”” Wouldn’t it be cool if your mod had versions like real video games? You certainly can! This is the version number of your mod.

Each line starts with public static final String or public static String which basically means this piece of information won’t change as the game is played.

Imagine if your mod could send you messages telling you exactly what it’s doing while it’s running. That’s exactly what we’re going to do now!

private static final Logger LOGGER = LogManager.getLogger()“: This line of code creates a LOGGER, which acts as a personal messenger for your mod. While your mod is running, it can send you updates or alerts in the Minecraft console. This is extremely useful when determining whether or not your mod is functioning properly or when looking for bugs.

“private”: The keyword “private” indicates that the LOGGER can only be used within this class. It’s a private messenger dedicated solely to this blueprint (ExampleMod)!

“static final”: These keywords indicate that there is only one LOGGER for the entire class, and it will not change once set.

“Logger LOGGER”: This creates a new Logger (a tool for logging messages) and names it LOGGER.

“LogManager.getLogger()”: This retrieves a Logger from the LogManager, which is a system that manages all of your mod’s logging (or message sending).

As we did earlier, we need to remove the errors from our code. Place your mouse over the words with the error message and import the appropriate package as shown in the image below.

We’re now entering an exciting phase. It’s time to start planning what cool items your mod will add to Minecraft. We’re getting ready to make your very own custom sword in this step!

public static CustomSword mySword”: So we’re telling the computer to make a variable called mySword, and CustomSword is the type of that variable, meaning we can only store CustomSwords inside of it.

We’ve created the variable mySword to store something, but we haven’t actually put anything in there yet. We need to do what’s called initializing our variable, where we put something inside of it.

In the next steps, we’ll define what exactly this CustomSword is and how it should behave in the game. Go to CustomSword and quick fix it to create a new class.

A new window will open up, keep these values at the default settings and just click Finish.

This will create a new Java code file called CustomSword and automatically open it up for it.

This is a class, which is code that defines what the CustomSword is and how it behaves

Now go back to ExampleMod.java.


Are you ready to put your mod into action? It’s time to create a constructor, which is a special function. This function has the same name as the class and is called when a new instance (or object) of the class is created.

public ExampleMod()“: This is where our constructor begins. The fact that it is public implies that it can be accessed from anywhere. Our constructor’s name is ExampleMod, which is also the name of our class! The () denotes that it does not require any additional information to function; it simply does its job when called upon. The constructor name must be the same as the name of the class.

Now we are going to initialize the variable. The first word is mySword. That’s the name of the variable we just created.

Next, we see an equal sign. Whenever you see “variable name = ”, we’re telling the computer what to put inside that variable. We’re opening that drawer in the computer’s memory, and we’re putting something inside.

So by saying “mySword = new CustomSword()”, we’re making a new CustomSword and storing it inside our variable.

Now open the CustomSword.java.

public class CustomSword extends SwordItem”: Here, we are making a new type of sword called CustomSword, and it’ll have all the regular features of a Minecraft sword. But we’re also going to add some cool new things to it.

“extends”: It is a keyword by which one object (class) can acquire the properties and behavior of another object using inheritance. In this case, our custom will acquire the properties of Swordtem.

Go to the SwordItem and quick fix it to import the package shown in the image.

public CustomSword()“: We’re creating a constructor for our CustomSword, just like we did with our ExampleMod. Remember that the public part means that it is accessible from anywhere, and CustomSword is the name of our builder. The () indicates that it does not require any additional information to begin.

We’ve reached the core of our CustomSword constructor now. This is where you start defining what your sword is made of and how powerful it is.

What does super mean? Here it means that we want the computer to use the code from the SwordItem. We’re building a normal sword, but we’re going to give it some data to customize it.

We’re going to give our sword a tier. There are different tiers in Minecraft: wood, stone, iron, diamond, netherite and gold. Eventually we’ll create our own custom tier for our sword, but for now we’ll pick one that already exists.

super(Tiers.DIAMOND);”: Click inside of the parentheses after super. Type in “Tiers.”, and you’ll see a list pop up of the available tiers in Minecraft.


If you lose the list, you can erase the period and type it again, and the list should reappear.

You can click to choose any tier you want.

super(Tiers.DIAMOND, 0, 0F);”: Add a comma after the tier name. Type in a 0, then another comma, then 0F.

0”: This is the attack damage of our sword. Right now, it’s set to 0, but don’t worry, you can change that later to make our sword powerful!

0F”: This is the attack speed of our sword. It’s also set to 0 for now, but you can change it later to suit our needs.

Next, we’ll say which creative mode tab we want our CustomSword to be in. In creative mode you can see every item in the game.

Add another comma after 0F. Then write “new Item.” and select the properties() from the list.

If you see the red line under the Item, then put a cursor on it and import the package as shown in the image below.

After Properties(), add “.tab()”. And inside of tab’s parentheses, write “CreativeModeTab.”, and you’ll see a list of tabs to choose from.

Choose the tab you want your sword to be in.

It’s finally time to put your hard work to use and add your CustomSword to the Minecraft world. Let’s get it registered so that players can get their hands on this incredible creation!

Go back to ExampleMod.java. Find the comment that says INITIALIZE VARIABLES and add the REGISTER ITEM code below it.


registerItem(mySword, “my_sword”);”: This is where we put our CustomSword in the game. Just making the variable and initializing it isn’t enough. We have to tell Minecraft to actually put it into the game. This is called registering.

There are two arguments we need to fill in. An argument is a piece of information we pass into a function.

The item argument is the item we want to register, and the registryName is what we’ll name it inside of the registry.

The item will be our mySword variable, which we made earlier.

Note: Make sure this is in all lowercase letters. This isn’t the name of the sword you’ll see in the game. We’ll customize that later. This is just the name Minecraft will use to keep track of the sword internally.

Congratulations! You’ve come a long way in your modding journey. Now, let’s look at the code that handles the item registration process.

Put your cursor on registerItem and select the option Create method.

private void registerItem(CustomSword mySword2, String string)”: This is a new method, a custom function that we created. The private keyword indicates that only code within this class may use it. When it finishes, it returns void. The method’s name is registerItem, and it takes two inputs: mySword2, the custom sword you want to register, and string, the name you want to give your custom sword.

mySword2.setRegistryName(string);“: This is a crucial line! It is changing the registry name of your custom sword to the one you specified. Consider a registry name to be your custom sword’s unique identity card. It is the method by which Minecraft keeps track of your custom items.

Now, you’re creating a queue, a special list that will hold all the custom items you want to register in Minecraft.

public static ArrayList<Item> itemsToRegister = new ArrayList<>();“: This line creates a new ArrayList called itemsToRegister. An ArrayList is similar to a magical bag in which you can keep many items in one place. In this case, our items are of the type Item, which means we can put custom swords, custom tools, or any other custom items in this bag!

itemsToRegister.add(mySword2);“: Finally, this line adds your custom sword to the list of items that are awaiting registration. “Hey, Minecraft, don’t forget about my awesome sword,” you seem to be saying. When you get the chance, register!”

Import some required packages, as shown in the below images.

Now, it’s time to set up a magical event that will bring all your custom items to life in the Minecraft world. Just go through the image and complete the code.

@SubscribeEvent“: This annotation indicates that the method registerItems is an event subscriber. “Hey, this method wants to listen to certain events, and I’m interested in the RegistryEvent,” it tells Minecraft.Item> event registration.”

Import the SubscribeEvent.

Import the RegistryEvent.

Create the method doItemRegistry and add the line of code as shown in the image.

Your mod is almost ready to shine. In the next steps, we’ll dive into the Minecraft world and witness the wonders of your custom items in action. Congratulations on coming so far! You’re almost there!

Once these imports are done, we can actually test out or “sword” except it will not look like a sword just yet.

In order to test out our code, make sure you are clicked inside a code window and then go up to the green play button and press it only once.

Make sure you press the button that is just the green button and not the ones with little icons in the corner.

Also, make sure that you are running the runClient option if you have multiple options under the green button.

After some time, you should see a window start opening Forge Minecraft.

Wait until it fully loads Minecraft to its main menu.

Once you have finished waiting, select Single Player at the main menu.

Next, select Create New World to start setting up a Creative mode game.

Then change the game mode to Creative and change the name, then select Create New World.

This will open the new world and take a bit of time to open the Minecraft world.

Once the world is opened, click the “e” button to open the Creative Tab inventory.

Go to the Combat tab or whatever tab you picked when we set the Creative Tab in our code.

Scroll to the bottom of the tab and make sure you have your sword.

We will be updating the look and the name, but if you put it in your inventory, you will have a sword that will function as we coded it to!

Note: The texture of the sword will look like black and blue boxes because we haven’t created the texture file for our sword. Also, we will give our sword a customized name in the next steps.

Once you are done testing your purple and black block sword, let’s go back to our project.

Now we need to name our sword.

Right click on the src/main/resources and make a new folder assets/examplemod/lang

Right click on the newly created assets/examplemod/lang (assets.examplemod.lang) folder and create the new file en_us.json.

Now add in a code line that will name the sword.

You can customize the name of your sword by changing the name to the right of the colon (:) symbol.

Note: Install the JSON editor plugin if you want to open JSON files from within Eclipse. Click on the Help tab, then go to Eclipse Marketplace and search for the JSON. Install the plugin as shown in the image below.

Now we need to make our sword texture and import it into our project.

Right click on the src/main/resources and make a new folder assets/examplemod/textures/items

I have attached a picture of an Iron Sword in Minecraft below.

Go ahead and right-click on it and select “Save image as…” then save the file as “my_sword.png”.

It is a small file because Minecraft needs a smaller image.

Once you have it saved, right-click on the picture wherever it is saved on your computer and then copy it.

Go to our project folder ForgePractice and open the src > main > resources > assets > examplemod > textures > items folder and paste in the my_sword.png into here.

Now it’s time to customize our sword.

Open Pinta by searching for Pinta in our search bar and opening the Pinta program.

With Pinta opened, go to File > Open where a new window will open up.

Let’s now find our sword imagine in our project folder ForgePractice > src > main > resources > assets > examplemod > textures > items

Now we need to actually paint the sword!

Zoom all the way in, turn anti aliasing to the off position and change the brush width to 1. All of these settings are highlighted in the image below.

Now all you need to do is paint your sword and erase or add anything you want.

Use the colors, the brush, and the eraser tool.

Make sure to change your eraser anti aliasing and brush width as needed, just like we did with the paint brush.

Then paint your sword to look like whatever you want! If you make a mistake, you can hold down CTRL and then press down on Z to undo the changes. On a Mac, you’ll hold down the Command button and press down on Z.

Once you are done, go to File > Save and make sure the new changes are saved you made.

Now return to Eclipse and add a new folder and file into the src/main/resources folder like we did before.

In this new file, type in code that will define the item sword resources.

Once this is all finished we are done with our custom Sword mod!

You can now test it by clicking on the Green play button just like what we did earlier!

Make sure everything is perfect and as you want it and then get ready to Compile your Mod and test it in Minecraft.

Step 7: Compile your Mod

Now that our code is finished, we need to compile and build our mod.

In order to build it, we need to go to the project folder we made and Shift + right click in an open space and select “Open Powershell window here” or “Open command window here”.

Once the window is open, write in the command “./gradlew build” and press Enter to run this command.

Once this build is finished, return to your project folder ForgePractice and open the build folder and then the libs folder.

Make sure you see modid-1.0.jar.

This is our build mod file!

In the next step, we will show you how to load your Mod onto your Minecraft game.

Step 8: Test your Mod!

Now to test our mod we need to make sure we have regular Minecraft forge downloaded.

What we were working in was the developer kit for Forge.

Now we need to access the Minecraft Forge client.

Return to the same Minecraft Forge download page we were at earlier.

Now once at this page click the regular install button shown.

Once the download finishes, open the executable file in your downloads folder.

Once this launches, you should see the Forge install window.

Make sure you have Install client selected, and keep the default location and then click OK.

Make sure the Forge client installs successfully and then press OK when it is done installing.

Once Forge is done installing, we need to find our build mod file in our Eclipse project folder.

Open your ForgePractice folder.

Then open the build folder and find the libs folder in here.

This is where our Mod will be.

Right click and rename the modid-1.0.jar to what you want.

Once it is renamed, go ahead and right click and copy the new jar file.

Once the jar file is copied, we need to open the folder that has our mods in it.

Go to the search bar and type %appdata% and open the folder that shows up in the search.

When this folder is open, go to and open the .minecraft folder.

Inside this .minecraft folder, you should see a mods folder, open up this folder.

Next, paste in your mod we copied earlier.

Your mod is all set up to work in Minecraft!

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

This has to be the Java version of Minecraft.

The Windows 10 or a mobile version of Minecraft will not work.

Once the Minecraft Launcher is opened, go to the Minecraft Java Edition then go to Installations. There you will see Forge version 1.18 that we installed earlier.

Once this is selected, click Play to launch the Minecraft Forge version.

Once Minecraft is loaded, we need to make a new level just like what we did when testing our sword.

Go to Single Player and then Create New World just like we did earlier

In the settings, change it to Creative Mode and change your World Name.

Once all of this is done, click the Create button and wait for the new Minecraft game to load.

Just like earlier, find your sword in the Creative Tab by clicking “e” on your keyboard, and then head to the tab you set your Sword to appear in.

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

You’ve officially created your own Minecraft Mod from scratch and loaded it into your own Minecraft game!

Congratulations!

You can make another sword using the same techniques or even challenge yourself to create an Axe or other tool.

Conclusion

If you enjoy Minecraft Modding and want to take your skills further, CodaKid has a series of courses that can teach you how to make your own custom creature, biome, dimension, insane explosions, and special effects, and more!

Our courses even include messaging and screen share support from live engineers if you ever get stuck, and our courses even come with a two-week free trial!

We hope you enjoyed The Ultimate Guide to Minecraft Modding with Java in 2023. If you enjoyed our Minecraft modding tutorial, we’d love it if you could share it with friends.

If you have any questions or comments, please leave them below!

Happy Minecraft Modding!

Minecraft Modding course

Related Articles
How to Install Minecraft Forge | The Ultimate Guide
What started as a seemingly simple sandbox survival video game in 2009 has since blown up to become one of...
14.01.2024
Choose Your Learning Path
Award-winning online coding and game design classes. Try for free.