(This article is one of a series of commentary articles)
First article: Introduction Previous article: Basic files Next article: Add Block
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).
\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`.
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 ...)
Start the game and check. 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.
[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]