(This article is one of a series of commentary articles)
First article: Introduction Previous article: 0. Basic files Next article: 2. Add Block
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. 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.
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
);
}
}
\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.
** Items have been added! ** **
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).
Creating Minecraft 1.14.4 Forge Mod Part 3 [Adding non-functional items]