[Java] Let's create a mod for Minecraft 1.16.1 [Add item]

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

First article: Introduction Previous article: Basic files Next article: Add Block

Add item

First of all, we will add basic items. I changed the writing style a little to at 1.14.4 (it does not mean that the implementation method has changed due to the version upgrade).

Item registration

\src\main\java\jp\koteko\liveinwater\
   ├ item
   │   └ Items.java
   └ LiveInWater.java

Items.java


package jp.koteko.liveinwater.item;

import jp.koteko.liveinwater.LiveInWater;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.ArrayList;
import java.util.List;

@Mod.EventBusSubscriber(modid = LiveInWater.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class Items {
    public static List<Item> itemList = new ArrayList<Item>();
    public static final Item WATERTREE_ROOT = register("watertree_root", new Item((new Item.Properties()).group(ItemGroup.MATERIALS)));

    private static Item register(String key, Item itemIn) {
        itemList.add(itemIn);
        return itemIn.setRegistryName(LiveInWater.MOD_ID, key);
    }

    @SubscribeEvent
    public static void registerItems(RegistryEvent.Register<Item> event) {
        for (Item item : itemList) {
            event.getRegistry().register(item);
        }
    }
}

Add items to List at the same time as declaration / initialization, andregister ()all items in the list with a for loop.

Each annotation (annotation) has the following functions.

EventBusSubscriber

Annotate a class which will be subscribed to an Event Bus at mod construction time. Defaults to subscribing the current modid to the MinecraftForge.EVENT_BUS on both sides.

It seems that this class is registered in EventBus of forge.

SubscribeEvent

Annotation to subscribe a method to an Event This annotation can only be applied to single parameter methods, where the single parameter is a subclass of Event. Use IEventBus.register(Object) to submit either an Object instance or a Class to the event bus for scanning to generate callback IEventListener wrappers. The Event Bus system generates an ASM wrapper that dispatches to the marked method.

It seems necessary to indicate that the method is a handler.

If you attach these, the item will be registered automatically.

If it's just a non-functional item, it's just an instance of the ʻItem class. As the name suggests, ʻItem.Properties is a class that manages item properties, and there are many other things you can do besides the group () that sets the creative tab, so let's take a look at the relevant class as appropriate. Also, for an instance of the ʻItem class, use setRegistryName () to determine the internal name when registering an item in forge. Use MOD_ID for the namespace and make it MOD_ID: ITEM_NAME`.

resources settings

The addition of items is completed in the previous section, but the display in the game is not ready as it is, so we will set these. Place the files under resources.

\src\main\resources
   └ assets
      └ liveinwater
         ├ lang
         │  └ en_us.json
         │  └ ja_jp.json
         ├ models
         │  └ item
         │     └ watertree_root.json
         └ textures
            └ item
               └ watertree_root.png

(Slightly renamed from the 1.14.4 article.)

lang\en_us.json


{
  "item.liveinwater.watertree_root": "WaterTree Root"
}

lang\ja_jp.json


{
  "item.liveinwater.watertree_root": "Water tree root"
}

" item. [MOD_ID]. [ITEM_NAME] ":" Display name "

watertree_root.json


{
  "parent": "item/generated",
  "textures": {
    "layer0": "liveinwater:item/watertree_root"
  }
}

For simple items, parent is ʻitem / generated MOD_ID: [texture file path]`

textures\item\watertree_root.png The formula seems to be 16 * 16 png, so create a texture and place it according to this. (It's very difficult to handwrite by yourself ...)

Verification

Start the game and check. キャプチャ.PNG Since ʻItemGroup.MATERIALS` is specified, there are more items on this tab if it is creative. The texture is reflected properly and the name set in the language file is displayed.

reference

[Minecraft Forge Event System Overview --Minecraft Modding Wiki](https://mcmodding.jp/modding/index.php/Minecraft_Forge_Event%E3%82%B7%E3%82%B9%E3%83%86%E3%83% A0% E6% A6% 82% E8% A6% 81) [Java] Let's create a mod for Minecraft 1.14.4 [1. Add items] Creating Minecraft 1.14.4 Forge Mod Part 3 [Adding non-functional items]

Next article

Add block

Recommended Posts

[Java] Let's create a mod for Minecraft 1.16.1 [Add item]
[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.14.4 [1. Add items]
[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 [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 timed process with Java Timer! !!
Let's create a super-simple web framework in Java
[Java] Create a filter
[Java basics] Let's make a triangle with a for statement
Create a java method [Memo] [java11]
[Java] Create a temporary file
How to create a lightweight container image for Java apps
[Java twig] Create a parser combinator for recursive descent parsing 2
Minecraft Modding [1.12] How to attach a special render for Item
Create a MOB using the Minecraft Java Mythicmobs plugin | Preparation 1
Let's create a TODO application in Java 4 Implementation of posting function
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
[Java twig] Create a parser combinator for recursive descent parsing (also memoize)
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
Let's create a REST API using WildFly Swarm.
[Windows] [IntelliJ] [Java] [Tomcat] Create a Tomcat9 environment with IntelliJ
[Java] Create something like a product search API
Let's create a RESTful email sending service + client
Try to create a bulletin board in Java
How to create pagination for a "kaminari" array
Let's create a custom tab view in SwiftUI 2.0
[Java] Create a collection with only one element