Creating mods for minecraft. Programs for creating mods for Minecraft

The buildings 03.07.2020
The buildings

This article describes the process of creating modifications for Minecraft using Forge and Eclipse. You don't need to be a professional to create simple modifications, but at least a mediocre understanding of the principles of the Java programming language is desirable. If you encounter any questions or problems while making modifications that are not covered here, please post them on the talk page.

Readiness table
Lesson 1.6+ 1.7+
Block Ready Ready
Item Ready Ready
Craft Ready Ready
Compilation Ready Ready
Generation Not planned Ready
Proxy and instance Not planned Ready
Mob Not planned Ready
Blocks with model Not planned Maybe
Add. Lessons Total: 2 Total: 12

First steps

Let's do the most important thing first: install Java and Eclipse. Regardless Minecraft versions, for which you want to create a modification, these steps are the same.

Java JDK

The most important thing for writing anything in Java is, naturally, the Java libraries themselves.

You can download them from the Oracle website. Go to this page and click on the Java icon on the left. Scroll down the page that opens a little, select that you agree with the license agreement (Accept License Agreement), and select the item corresponding to yours at the bottom of the first list operating system, and download. After downloading, simply install by clicking Next. After installation, you need to set the installation path to your Windows environment variables. To do this, go to the Computer Properties menu (⊞ Win + PauseBreak or My Computer -> Properties -> Advanced system settings -> Environment variables). Find the Path system variable, highlight it, and click Edit. At the very end of the Value line, add the path to JDK/bin separated by a semicolon, for example, C:\Program Files\Java\jdk1.7.0_45\bin . Then click OK three times.

How to create a mod for Minecraft?

In order to create mods in Minecraft, you must have at least basic knowledge of working with applications and programming in general.

You can create mods for Minecraft using the API or without it. API is an application programming interface that allows you to work with ready-made classes, functions, procedures, structures and constants for use in other programs. The most popular API for Minecraft is Minecraft Forge. Using Forge to create mods in a game requires the use of this API for the game itself, which significantly complicates the gameplay itself, but at the same time allows you to install applications without conflicts with your modifications and with the mods of other players. It is impossible to achieve this without an API.

Preparing to create mods in the game is as follows:

  1. Download latest version Java.
  2. Install Java SE Development Kit.
  3. Download Eclipse IDE for Java Developers and place a copy of it on your desktop.
  4. Download Minecraft Forge.
  5. Move all programs into one folder on your desktop and run install.cmd.
  6. After starting Eclipse, specify the folder you created earlier as the workspace.

After this, you can proceed directly to creating the mod. You will need to go through the following steps:

  1. Creating a base file that specifies the name, id and version of the mod;
  2. Creating a block;
  3. Creating a drop;
  4. Block generation;
  5. Creation of versatile structures;
  6. Multiblock structures;
  7. Crafting items;
  8. Creation of tools, etc.

By starting small, you will gradually understand the basic principles of how to create mods for Minecraft, and you can even add your own mods to the server in order to show them to your friends. If creating mods is not yet within your capabilities, read the article


No need to delete META-INF in minecraft.jar, and minecraft_server.jar
1. Create a folder (For example: MCP Forge) and unpack the contents of the archive with MCP there.
2. Copy the bin and resources folder from the client to the ../MCP Forge/jars/ folder, from the server we only need minecraft_server.jar.
3. Unpack the archive with Forge-src into the MCP Forge folder
4. Open the folder ../MCP Forge/forge/ and run the install.cmd file. We are waiting for the decompilation to finish..
(P.S If you want you to already have a ready-made MCP with Forge, for example, if you accidentally deleted it or something else, then: When the decompilation is completed, run the game and let it download the lib, and then add this MCP Forge to the archive, for example like this (mcp Forge 1.5.1)
5. “Install” and launch Eclipse, during startup you will be “asked” for the folder with the project, specify the path: ../MCP Forge/eclipse/
6. So, we opened the project, now (Usually on the left, there is a Package explorer) we look at what library it “eats” (In the Package explorer window, “open the Minecraft project” and if there is a line “JRE System Library”, then everything is fine, but if the line is “JRE System Library”, then right-click (Right-click), select Properties, then a window opens in which Execution environment is selected, select JavaSE-1.7 in it and click Ok.
7. So, the preparations are ready.

How do you start writing a mod?

First, we need to create a “base”, that is, the main “folder” in which our “base” and everything else will be stored.
1. Go to Eclipse, see the Minecraft folder in Package Explorer, open it, and right-click on the src folder, select New->Package. Open window in the Name line, we indicate the name of the folder in which everything will be stored (For example, take: mods.testmod.src) and click Ok.
2. Right-click on our folder (mods.testmod.src), then New -> Class. In the Name line, indicate the name of our file (For example: TestModBase) and click Finish.
3. Change the path, but do not remove mods, like this, for example mods.NewItemMod.src.
4. In new versions you need to import “A lot” of everything, to do it faster in Eclipse press “ctrl + shift + o”, and it will quickly import everything, and if a window appears then select the import you need.
5. If you do not work in Eclipse, then it will be much more difficult for you, so it is better to switch to it, it will indicate where the error is, and what imports are needed, and you will not ask stupid questions in the comments.

package mods.testmod.src;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.common.network.NetworkMod.SidedPacketHandler;
import cpw.mods.fml.common.SidedProxy;
@Mod (modid = "TestMod", name = "Test Mod", version = "0.0.1")
@NetworkMod(clientSideRequired = true, serverSideRequired = false, versionBounds = "1.0.0")

public class TestModBase (

@Instance("TestModID")
public static TestModBase instance;

@Init

{
}

@PreInit
public void preLoad(FMLPreInitializationEvent event)
{
}

@PostInit
public void postLoad(FMLPostInitializationEvent event)
{
}
}


In our TestModBase file
After the inscription:
public class TestModBase (
Enter this line:
public static final Block testBlock = new TestBlock(2020).setUnlocalizedName("testBlock");
Parsing:
public static final Block "testBlock" - testBlock the name of our block in the code (not in the game)
new TestBlock(2020) - TestBlock the name of our block in the code (not in the game), 2020 block ID
setUnlocalizedName("testBlock") - ("testBlock") the name of our block in the code (not in the game)
After the inscription:
@Init
public void load(FMLInitializationEvent event)
{

Enter this line:
GameRegistry.registerBlock(testBlock);
LanguageRegistry.addName(testBlock, "Test Block");

Parsing:
(testBlock) - the name of our block in the code (not in the game)
(testBlock, "Test Block") - testBlock is the name of our block in the code (not in the game), "Test Block" is the name of our block in the game.
Create a file testBlock and enter the following code into it:
package mods.testmod.src;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;

public class TestBlock extends Block (

public TestBlock(int par1)
{
super(par1, Material.ground);//Material
this.setCreativeTab(CreativeTabs.tabTools);//Add to creative
}
//Register the texture
@Override

{
}
}


In our TestModBase file
After the inscription:
public class TestModBase (
Enter this line:
public static Item testItem = new TestItem(2021).setUnlocalizedName("testItem");
Parsing:
public static final Item "testItem" - testItem is the name of our item in the code (not in the game)
new TestItem(2021) - TestItem the name of our item in the code (not in the game), 2021 item ID
setUnlocalizedName("testItem") - ("testItem") the name of our item in the code (not in the game)
After the inscription:
@Init
public void load(FMLInitializationEvent event)
{

Enter this line:
LanguageRegistry.addName(testItem, "Test Item");
Parsing:
(testItem, "Test Item") - testItem is the name of our item in the code (not in the game), "Test Item" is the name of our item in the game.
Create a file testItem and enter the following code into it:
package mods.testmod.src;

import net.minecraft.item.Item;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;

public class TestItem extends Item
{
public TestItem(int par1)
{
super(par1);
setCreativeTab(CreativeTabs.tabTools);
}

//Texture registration for an item is slightly different from a block
@Override
public void registerIcons(IconRegister par1IconRegister)
{
}
}


@Override
public void registerIcons(IconRegister par1IconRegister)
{
this.blockIcon = par1IconRegister.registerIcon("testmod:testBlock");
}

("testmod:testBlock"), testmod is the "name of the folder" in which the "folder with the texture" will be, testBlock is the name of our texture. This is our texture placement:

\Tutorial Forge 1.5.1\mcp744\src\minecraft\mods\testmod\textures\blocks\testBlock.png


@Override
public void registerIcons(IconRegister par1IconRegister)
{
this.itemIcon = par1IconRegister.registerIcon("testmod:testItem");
}

("testmod:testItem"), testmod is the "name of the folder" in which the "folder with the texture" will be, testItem is the name of our texture. This is our texture placement.

Custom modification computer games- this is a fairly common phenomenon, which is a change and addition of game files to obtain more content, variety of gameplay and so on. Sometimes mods can be small, adding only a couple of items or features. And sometimes you can find global mods that almost completely change the gameplay. For Minecraft, one of the most popular computer games of our time, gamers make quite a lot of different mods. Therefore, you can learn how to create a mod for Minecraft - it’s actually easier than it seems, but in any case it will take you quite a lot of time.

Mods for Minecraft

So, if you seriously decide to figure out how to create a mod for Minecraft, then you need to understand what exactly can be modified there. In fact, there are incredibly many possibilities - there are many more mods for this game than for all others. This is due to the fact that Minecraft looks quite simple - accordingly, it is easier to change something in it or add certain functions to it than to a top project on which hundreds of professionals have worked for several years. Now there are already mods such as “Industrial Craft” or “Taumcraft”, which can easily be considered global, as they add an incredible amount of content to the game - the first one takes Minecraft into the industrial era, adding hundreds of new recipes and items. The second one adds magic and everything that comes with it to the game. Naturally, it’s worth starting with more simple projects, but in the end you can also create something serious. But first, you need to learn how to create a mod for Minecraft.

Creating a pure mod

If you want to learn how to create a mod for Minecraft, then you need to immediately understand that it can be done with two completely different methods- with or without API. First you need to figure out how to create a pure mod that does not require additional software. IN in this case you need to have a good understanding of the game mechanics and have certain design skills, as well as the ability to program in high level. Then you can introduce something new into the game, as well as change certain items, functions and much more. As a result, you will be able to create a unique and unusual mod, but it is likely that it will be limited in use by other gamers, since it will not be standardized - accordingly, some gamers may have problems with launching and compatibility, regardless of what mode was this Minecraft modification created - survival or creative?

Creating mods using the API

API is a special software interface that already contains many functions from the game itself, as well as textures, skins and much more. This way, instead of writing all the code from scratch, you can already use ready-made solutions, which can be combined with each other, creating something new. Exists a large number of There are a variety of interfaces, and choosing something specific among them can be a challenge. Here you need to take into account the specifics of the mod, for example, in relation to the Minecraft mode - survival, hardcore, creative, and so on. But if you are just starting to make mods and also want your modification to be available maximum number people, then you need to use Minecraft Forge. This is the most common API that currently exists - at the same time, it is the most functional, extensive and in demand. Therefore, if you are going to add to Minecraft new fashion - pay attention to it first of all.

Features of using Minecraft Forge

Many gamers who create or use mods wonder why Forge is needed at all. After all, this is so inconvenient - you definitely need to install the API itself in order to be able to then launch the modification. Is it really impossible to do clean fashions, which do not require anything additional to play? In fact, Forge has many more advantages than disadvantages (by the way, there is only one, which is the need to pre-install the API to run the mod). Firstly, the process of creating a mod is simplified, and secondly, you have much more more possibilities, which require no effort to use. But the most important thing is that your mod becomes universal. If you make a modification without an API, as mentioned above, there is a high probability that many gamers will not be able to install it. If you used Forge, then any gamer with the API installed will be able to install your mod without the slightest problem.

Features of use

The most important rule of modification, no matter which option you choose, is to not modify the source files. For example, you decide to do for Minecraft mod on cars - it is better to add new objects rather than correct those that are in the game to avoid conflicts.


Today I am reopening the series of articles this time. I will not abandon it and will even respond to your comments. Well, from words to deeds. Go!
Preparation

To write our plugins we will need:
  • Eclipse Java application development environment;
  • Spigot Api: https://hub.spigotmc.org/nexus/content/groups/public/org/spigotmc/spigot-api/.
You will also need basic knowledge in Java. If there are none, then here are links to “raising your skill”:
  • Java Basics for Beginners
    The site is designed for those who are just starting to learn Java.
  • Java (Beginner) Programming Tutorials
    Video tutorial on Java, designed for beginners (I started with it).
  • Java reference
    I would call this a Java cheat sheet
  • Java expert
    And don't let the name scare you. Here you can find many examples of solutions for these or
    other tasks.
Installing and Configuring Eclipse
If you are already familiar with Eclipse or have a different IDE, then skip this section.

There should be no problems installing Eclipse: you just need to unpack it into any folder and run it. Immediately after this, Eclipse will ask you to indicate which working space(workspace) open now. This is the folder in which all created projects will be saved and where to place it is your personal decision. If you don't care, then leave everything as it is. If you suddenly want to change the workspace, then don’t worry: every time you start it, Eclipse will ask you about the workspace again. You can create as many of these spaces as you like, and each can be configured differently, for specific purposes. For example, I have 2 workspaces: for writing regular java applications and for writing bucket plugins. If you suddenly get tired of this message, there is a checkbox “Use this as the default and do not ask again”, which allows you to set the workspace as the default.+

As soon as you decide on the choice of location and Eclipse loads, we will see an invitation tab... which we immediately close. We don't need her.

Now we see the workspace of the Eclipse itself. From all this, we only need the following panels:

  • Package Explorer
    Your projects, packages (more on them later) and all sorts of files for our future plugins will be displayed here.
  • Problems
    We will rarely use this panel (if we ever get around to it), but it’s worth talking about. Errors made in the code will be shown here, as well as warning messages about possible errors or inaccuracies.
  • Outline
    Navigation directly through the open source java code will be displayed here.
The last 2 panels described can be completely collapsed, because We will rarely use them.

The workplace is almost ready. All that remains is to check 2 more boxes in the settings.

Go to the Window -> Preferences menu, then along the General -> Editor -> Text Editors tree and check the “Show line numbers” checkbox to enable display of line numbering. Now go to General -> Workspace and in the “Text file encoding” group set the encoding to UTF-8, thereby setting the default encoding.

The installation and configuration is done. Now I’ll explain how to create new project for the plugin. This can be done in one of 3 ways:

The New Java Project window will open in front of us. In Project name we indicate the name of our project

Click Next.
In the window that appears, go to the Libraries tab, click the Add External JARs button and select the downloaded Bukkit API

Click Finish.

On the left, in Package Explorer, our project appears with the src folder in which our source codes will be stored. Now let's create new class. This is done in exactly the same way as with the Java Project.

In the New Java Class window we only need the following columns:

  • Package
    indicates the package in which our class will be stored. The name format should be something like this: ru.dmitriymx.bukkit.tutorial.
    In a nutshell and in a nutshell, packages in Java are a namespace or “virtual folders” into which classes are placed. You can read more about this here: , , .
  • Name
    indicate the name of the class (for me it is DmxFirstPlugin)
Leave all other items as they are and click Finish.

Now let's move directly to the code.
Writing a simple plugin
As soon as we have created a new class, a ready-made empty template appears before our eyes

For now, this is just an empty class that is absolutely useless in everyday life. We will fix this. Let's change this

on this

Eclipse will highlight JavaPlugin to us, indicating an error in the code. If you move the mouse over such an underlined code, a window will open with a description of the error and how to solve it. In this case, we need to import the class from the Bukkit API, for which we select the item “Import ‘JavaPlugin’(org.bukkit.plugin.java)”

We immediately notice how the line is written above all our code

A little theoretical material. Plugins have 3 main methods: onEnable(), onDisable() and onLoad(). The first two are responsible for enabling and disabling the plugin, and the last one is triggered when the plugin is directly loaded into the server memory. It follows that onLoad is executed first, but the plugin itself starts working only after onEnable is called from the server side. When the server is turned off or rebooted, the onDisable method is called.

We sorted out the “entry-exit points”. Let's now write something more or less workable. Let's give general code class to the following form:

who doesn't see the second part:
What we just wrote about is a ready-made plugin. All he does is write in the chat about the arrival and departure of the player on the server. We will understand his work in order (how else?).
First, let me pay attention to the class declaration line. As you can see, the Listener extension has been added to our class. Without delving into the jungle of Java, I’ll say it simpler: by specifying this extension, we thereby expand the scope of the class not only as a plugin (JavaPlugin), but also as an event handler (Listener). But it’s in the onEnable() method that we register our class on the server as an event handler (this is a reference to itself, in case anyone has forgotten).

Next are our 2 event handlers onJoin() and onQuit(). The first one is responsible for the event of a player entering the server, and the second one is responsible for leaving. Using the event.getPlayer().sendMessage() method, we can send a message to the player who caused this event (in our case, the player who logged in). The static class ChatColor stores color constants for coloring. I think how to use it can already be seen from the example. Also, both of our processors notify other players on the server about events that have occurred, but they do it in different ways. In onJoin(), using the event.setJoinMessage() method, we change the usual “Player joined the game” message to any other one. And in onQuit() we did something different (for example purposes): we removed the output of the exit message and report this through the getServer().broadcastMessage() method, which simply sends the specified message to all players on the server.+

All that's left to do is write the important plugin.yml file and package it all into a jar file.

Plugin.yml is a plugin description file. It specifies the name of the plugin, the main class, description and what commands to register for plugins (more on this later), etc. In our case, the file should look like this:

Oh, I forgot to tell you where this file should be located. Right-click on the src folder in PackageExplorer and select File from the New menu. In the File name field, write plugin.yml and click Finish. In the opened text editor, we write what I indicated above. We save everything and move on to the last phase: packaging.

Right click on the src folder -> Export. In the folder tree, open Java and select the JAR file and click Next. Of the little things, we leave only “Export generated class files and resources” and “Compress the contents of the JAR file”. In the JAR file field we indicate where we will save the resulting plugin. After clicking Finish, you can put the plugin in the plugins folder, start the server and check its operation.

Do you see? It's quite simple. With practice, you will gain more experience and be able to make cooler plugins, even such legendary ones as WorldEdit and WorldGuard.
Source

We recommend reading

Top