(This article is one of a series of commentary articles)
First article: Introduction Previous article: 2. Add Blocks Next article: 4. Add Tools
I've added items and blocks so far, but it seems a bit strange to see them in the same tab as the vanilla [^ 1] items in the creative. Besides, it's nice to have additional items organized in their own tabs. Here we will add a creative tab for our mod.
\src\main\java\jp\koteko\example_mod\
├ ExampleItemGroup.java
├ ExampleMod.java
└ lists
ExampleItemGroup.java
package jp.koteko.example_mod;
import jp.koteko.example_mod.lists.ItemList;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class ExampleItemGroup extends ItemGroup {
public static final ExampleItemGroup DEFAULT = new ExampleItemGroup();
public ExampleItemGroup() {
super("example_mod");
}
@Override
@OnlyIn(Dist.CLIENT)
public ItemStack createIcon() {
return new ItemStack(ItemList.ExampleIngot);
}
}
Define your own class that inherits from ʻItemGroup. Set the tab icon with
createIcon(this method is required). Note that the
" example_mod "` specified here is not the ModID, but the internal ID of this ItemGroup.
Modify existing additional item settings to use this tab.
ItemList.java
// ...
import jp.koteko.example_mod.ExampleItemGroup; //add to
//import net.minecraft.item.ItemGroup; //Delete
// ...
@Mod.EventBusSubscriber(modid = ExampleMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ItemList {
//Change the argument of group
public static Item ExampleIngot = new Item(new Item.Properties().group(ExampleItemGroup.DEFAULT))
.setRegistryName(new ResourceLocation(ExampleMod.MOD_ID, "example_ingot"));
// ...
}
BlockList.java
// ...
import jp.koteko.example_mod.ExampleItemGroup; //add to
//import net.minecraft.item.ItemGroup; //Delete
// ...
@Mod.EventBusSubscriber(modid = ExampleMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class BlockList {
// ...
//Change the argument of group
@SubscribeEvent
public static void registerBlockItems(RegistryEvent.Register<Item> event) {
event.getRegistry().registerAll(
new BlockItem(ExampleBlock, new Item.Properties().group(ExampleItemGroup.DEFAULT))
.setRegistryName(new ResourceLocation(ExampleMod.MOD_ID, "example_block"))
);
}
}
Next, since the display name is not set as it is, add it to the lang file.
en_us.json
{
"itemGroup.example_mod": "Example Mod",
"item.example_mod.example_ingot": "Example Ingot",
"block.example_mod.example_block": "Example Block"
}
ja_jp.json
{
"itemGroup.example_mod": "Example Mod",
"item.example_mod.example_ingot": "Example ingot",
"block.example_mod.example_block": "Example block"
}
Start the game. ** You have added a new tab just for your mod. ** **
Creating Minecraft 1.14.4 Forge Mod Part 5 [Adding Creative Tab]
[^ 1]: A plain Minecraft without mods