I'm trying to code a mod, which adds a new Item to the game and I'm following a tutorial on youtube. I also looked everything up on the fabric website, but the code doesn't work.
Here is the code I used. It is from the fabric wiki:
public static final Item CUSTOM_ITEM = new Item(new FabricItemSettings().group(ItemGroup.MISC));
@Override
public void onInitialize() {
Registry.register(Registry.ITEM, new Identifier("tutorial", "custom_item"), CUSTOM_ITEM);
}
Somehow in my library the .group() function doesn't exist and that's the same with other functions.
Do I have to download something or how can I fix this?
I tried adding a new Item to my mod, but it didn't work.
The .group
method was removed in version 1.19.3
To add your item to an item group, you must use the ItemGroupEvents.modifyEntriesEvent(ItemGroup group)
event provided by Fabric API.
In your case, you'll need to store the result of the Registry.register
method in the CUSTOM_ITEM
field if you want to pass it to the modifyEntries
event:
public static final Item CUSTOM_ITEM = Registry.register(Registry.ITEM, new Identifier("tutorial", "custom_item"), new Item(new FabricItemSettings()));
public void onInitialize() {
ItemGroupEvents.modifyEntriesEvent(ItemGroup.MISC).register(itemGroup ->
{
// Add the custom item to the MISC item group.
itemGroup.add(CUSTOM_ITEM);
});
}
You can read more about creating custom items here: