[Java] Let's create a mod for Minecraft 1.14.4 [1. Add items]

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

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

Add item

First, let's add a non-functional item called "Hello, World!" In Minecraft's Moding. Of course, you can write it in the main file, but as it increases, it will get messed 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
        );
    }
}

We'll also make a few changes to the main file.

ExampleMod.java


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

Now let's start the game. キャプチャ.PNG If you check the items in the creative, you can see that the number of suspicious black and purple ʻitem.example_mod.example_ingot` items is increasing. ** This black-purple ** that you will see unpleasantly from now on is the display when the corresponding texture is not found.

A brief description of the code

The part to register the item


// @Lines starting with(Annotation)It seems that it will do various things if you write it
@Mod.EventBusSubscriber(modid = ExampleMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ItemList {
    //Declare and initialize the item as a member variable
    // group()In Creative tab settings ItemGroup.MISC is Miscellaneous(Other)
    //Item ID to be registered is set by setRegistryName
    // "example_ingot"Item ID in which the 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<Item> event) {
        // registerAll()Register an instance of the Item class passed as an argument in
        //Multiple arguments can be passed separated by commas
        event.getRegistry().registerAll(
                ExampleIngot
        );
    }
}
___ Now, let's fix the black-purple and set it to display the correct item name. Here is the file and tree structure to add first. Pay attention to 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. In the program, it is managed by ID, 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 file under textures.

Next, let's write the contents.

en_us.json


{
  "item.example_mod.example_ingot": "Example Ingot"
}

en_us.json


{
  "item.example_mod.example_ingot": "Example ingot"
}

" item.MOD_ID. Item ID ":" Display name " `

example_ingot.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 it is omitted here. ʻExample_ingot.png` is prepared and placed appropriately, and then the game is started again.

キャプチャ.PNG キャプチャ2.PNG

** Items have been added! ** **

development

Q. I want to make a tool A. 4. Add tools.

Q. I want to make a corresponding recipe A. 6. Add recipe.

Q. I want to make food A. It is undecided (I want to write it somewhere).

reference

Creating Minecraft 1.14.4 Forge Mod Part 3 [Adding non-functional items]

Next article

2. Add block

Recommended Posts

[Java] Let's create a mod for Minecraft 1.14.4 [1. Add items]
[Java] Let's create a mod for Minecraft 1.14.4 [4. Add tools]
[Java] Let's create a mod for Minecraft 1.14.4 [5. Add armor]
[Java] Let's create a mod for Minecraft 1.14.4 [7. Add progress]
[Java] Let's create a mod for Minecraft 1.14.4 [6. Add recipe]
[Java] Let's create a mod for Minecraft 1.16.1 [Add item]
[Java] Let's create a mod for Minecraft 1.14.4 [2. Add block]
[Java] Let's create a mod for Minecraft 1.16.1 [Add block]
[Java] Let's create a mod for Minecraft 1.14.4 [3. Add creative tab]
[Java] Let's create a mod for Minecraft 1.14.4 [Introduction]
[Java] Let's create a mod for Minecraft 1.16.1 [Introduction]
[Java] Let's create a mod for Minecraft 1.14.4 [99. Mod output]
[Java] Let's create a mod for Minecraft 1.16.1 [Add and generate trees]
[Java] Let's create a mod for Minecraft 1.14.4 [9. Add and generate trees]
[Java] Let's create a mod for Minecraft 1.14.4 [8. Add and generate ore]
[Java] Let's create a mod for Minecraft 1.14.4 [0. Basic file]
[Java] Let's create a mod for Minecraft 1.14.4 [Extra edition]
[Java] Let's create a mod for Minecraft 1.16.1 [Basic file]
Let's create a Java development environment (updating)
Let's create a super-simple web framework in Java
[Java] Create a filter
Create a java method [Memo] [java11]
[Java] Create a temporary file
How to create a lightweight container image for Java apps
Create a MOB using the Minecraft Java Mythicmobs plugin | Preparation 1
Let's create a TODO application in Java 4 Implementation of posting function
How to sign a Minecraft MOD
Let's create a TODO application in Java 6 Implementation of search function
Let's create a TODO application in Java 8 Implementation of editing function
Create a Java project using Eclipse
[Java] How to create a folder
Let's create a TODO application in Java 1 Brief explanation of MVC
Let's create a TODO application in Java 5 Switch the display of TODO
Create a fluentd server for testing
Let's install Docker on Windows 10 and create a verification environment for CentOS 8!
Let's go with Watson Assistant (formerly Conversation) ⑤ Create a chatbot with Watson + Java + Slack
Create a java web application development environment with docker for mac part2
[Java] Create and apply a slide master
How to create a Maven repository for 2020
Create a TODO app in Java 7 Create Header
[Rails] Let's create a super simple Rails API
[Java] Let's make a DB access library!
Let's make a calculator application with Java ~ Create a display area in the window
Java (add2)
Java (add)
Let's create a versatile file storage (?) Operation library by abstracting file storage / acquisition in Java
[Azure] I tried to create a Java application for free-Web App creation- [Beginner]
I made a Diff tool for Java files
How to create a database for H2 Database anywhere
A story about Java 11 support for Web services
Create a CSR with extended information in Java
Create a simple bulletin board with Java + MySQL
Let's create a REST API using WildFly Swarm.
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
Create a Lambda Container Image based on Java 15
[Java] Create something like a product search API
Let's create a RESTful email sending service + client
Let's create a custom tab view in SwiftUI 2.0
[Java] Create a collection with only one element
Create your own Android app for Java learning
Create Scala Seq from Java, make Scala Seq a Java List