[Java] [Java]Let’s create a Minecraft Mod 1.14.4 [1. Add Items]

2 minute read

(This article is one of a series of commentary articles)

First article: Introduction Previous article: 0. Basic file Next article: 2. Add Block

Add item

First, let’s add a non-functional item, which is “Hello, World!” in Micra’s Modding. Of course, you can write it in the main file, but as it increases, it will mess up later, so I will create a class to manage items and write it there.

\src\main\java\jp\koteko\example_mod\
   ├ ExampleMod.java
   └ lists
      └ ItemList.java

ItemList.java


package jp.koteko.example_mod.lists;

import jp.koteko.example_mod.ExampleMod;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = ExampleMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ItemList {
    public static Item ExampleIngot = new Item(new Item.Properties().group(ItemGroup.MISC))
            .setRegistryName(new ResourceLocation(ExampleMod.MOD_ID, "example_ingot"));

    @SubscribeEvent
    public static void registerItems(RegistryEvent.Register<Item> event) {
        event.getRegistry().registerAll(
                ExampleIngot
        );
    }
}

Also make some changes to the main file.

ExampleMod.java


//...
@Mod(ExampleMod.MOD_ID) // change
public class ExampleMod
{
    public static final String MOD_ID = "example_mod"; // Addition
    //...
}

Now let’s start the game. Capture.PNG If you check the items in the creative, you can see that the number of dubious black and purple item.example_mod.example_ingot items is increasing. This black-purple that you will see disgustingly from now is the display when the corresponding texture was not found.

A brief description of the code
#### **` the part that registers the item`** ```java // It seems that writing a line starting with @ (annotation) will make it feel good @Mod.EventBusSubscriber(modid = ExampleMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD) public class ItemList { // Declare and initialize the item as a member variable // Set creative tab in group() ItemGroup.MISC is Miscellaneous (Other) // Set the item ID to register with setRegistryName // Item ID in which "example_ingot" part is registered Lowercase public static Item ExampleIngot = new Item(new Item.Properties().group(ItemGroup.MISC)) .setRegistryName(new ResourceLocation(ExampleMod.MOD_ID, "example_ingot")); @SubscribeEvent public static void registerItems(RegistryEvent.Register event) { // Register an instance of the Item class passed as an argument with registerAll() // You can pass multiple arguments separated by commas event.getRegistry().registerAll( ExampleIngot ); } } ``` </div></details> ___ Now, let's fix the black purple and set it to display the correct item name. The files and tree structure to be added first are shown below. Please be careful about the singular and plural forms. ``` \src\main\resources └ assets └ example_mod ├ lang │ └ en_us.json │ └ ja_jp.json ├ models │ └ item │ └ example_ingot.json └ textures └ items └ example_ingot.png ``` The json file under `lang` defines the display in each language. It is managed by ID in the program, and the display name is described here. The json file under `models` defines how to apply the texture. The file name is [corresponding item ID].json. Place the texture files under `textures`. Next, let's write the contents. #### **`en_us.json`** ```json { "item.example_mod.example_ingot": "Example Ingot" } ``` #### **`en_us.json`** ```json { "item.example_mod.example_ingot": "example ingot" } ``` `"item.MOD_ID.item ID": "display name"` #### **`example_ingot.json`** ```json { "parent": "item/generated", "textures": { "layer0": "example_mod:items/example_ingot" } } ``` `MOD_ID:items/[texture file name]` The model file is important for detailed display settings, but we will omit it here. Prepare `example_ingot.png` appropriately and place it, then start the game again. ![Capture.PNG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/256627/d50036d0-3851-7da8-5f99-e35e01117512.png) ![Capture2.PNG](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/256627/ceb68965-0e9b-2e20-1341-7ee0f62f17d7.png) **Items have been added! ** # Development Q. I want to make a tool A. It is explained in [4. Add Tool](https://qiita.com/koteko/items/0c3a73d1ed299cfbde02). Q. I want to make a compatible recipe A. It is explained in [6. Add recipe](https://qiita.com/koteko/items/4e6f4e25db43907770d9). Q. I want to make food A. It is undecided (I want to write it somewhere). # Reference [Minecraft 1.14.4 Forge Mod Part 3 [Add non-functional items]](https://qiita.com/Hiroya_W/items/4fec2d799e499c4cd7c2) # Next article [2. Add Block](https://qiita.com/koteko/items/c904b3bfdd90f0b9a98a)