Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello, 

I am creating a mod in 1.20

There are some methods I don't have such as the tab method. When I create my item and in the properties I try to call the tab method, the IDE doesn't propose it and if I force it, it doesn't exist. However, I installed the forge MDK for Minecraft version 1.20. It also did it for me on earlier versions, I didn't have the SetRequiresTools method and so on. I don't understand why it's doing this to me.

I've made my code available to you. I'd like to have a way to put my items in Itemgroup and above all to understand why I can't access certain functions like tab.

Thank you for your answers in advance ^^.
 

Click to open Screenshoot

ModItems :

package fr.lixnew.noidea.init;

import fr.lixnew.noidea.NoIdea;
import net.minecraft.world.item.Item;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

public class ModItems
{
    public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, NoIdea.MODID);

    public static final RegistryObject<Item> ENERGIZER_CRYSTAL = ITEMS.register("energizer_crystal", () -> new Item(new Item.Properties()));
}

NoIdea (Main) :
 

package fr.lixnew.noidea;

import fr.lixnew.noidea.init.ModItems;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

@Mod(NoIdea.MODID)
public class NoIdea
{
    public static final String MODID = "noidea";

    public NoIdea()
    {
        var modBus = FMLJavaModLoadingContext.get().getModEventBus();
        ModItems.ITEMS.register(modBus);
    }
}

 

Edited by LixNew

I don't think there is a "tab" method. You have to create a separate file in the folder "init" and then add the items. here's an example from my mod:

Spoiler

public class FlamesAdditionsTabs {

    public static final DeferredRegister<CreativeModeTab> REGISTRY = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, FlamesAdditions.MODID);

    public static final RegistryObject<CreativeModeTab> flamesadditions = REGISTRY.register("flamesadditions",

            () -> CreativeModeTab.builder().title(Component.translatable("item_group.flamesadditions.flamesadditions")).icon(() -> new ItemStack(FlamesAdditionsItems.SINGULARITY_UPGRADE.get())).displayItems((parameters, tabData) -> {

                tabData.accept(FlamesAdditionsItems.SINGULARITY_UPGRADE.get());

                tabData.accept(FlamesAdditionsItems.SMALL_SINGULARITY.get());

                tabData.accept(FlamesAdditionsItems.MEDIUM_SINGULARITY.get());

                tabData.accept(FlamesAdditionsItems.LARGE_SINGULARITY.get());

                tabData.accept(FlamesAdditionsItems.SMALL_DENSE_SINGULARITY.get());

                tabData.accept(FlamesAdditionsItems.MEDIUM_DENSE_SINGULARITY.get());

                tabData.accept(FlamesAdditionsItems.LARGE_DENSE_SINGULARITY.get());

                tabData.accept(FlamesAdditionsItems.FINAL_SINGULARITY.get());

                tabData.accept(FlamesAdditionsItems.INCOMPLETE_TRUE_SINGULARITY.get());

                tabData.accept(FlamesAdditionsItems.TRUE_SINGULARITY.get());

                tabData.accept(FlamesAdditionsBlocks.SINGULARITY_BLOCK.get().asItem());

                tabData.accept(FlamesAdditionsItems.COIN_TEMPLATE.get());

                tabData.accept(FlamesAdditionsItems.COPPER_COIN.get());

                tabData.accept(FlamesAdditionsItems.COPPER_COIN_STACK.get());

                tabData.accept(FlamesAdditionsBlocks.COPPER_COIN_BLOCK.get().asItem());

                tabData.accept(FlamesAdditionsItems.SILVER_COIN.get());

                tabData.accept(FlamesAdditionsItems.SILVER_COIN_STACK.get());

                tabData.accept(FlamesAdditionsBlocks.SILVER_COIN_BLOCK.get().asItem());

                tabData.accept(FlamesAdditionsItems.GOLD_COIN.get());

                tabData.accept(FlamesAdditionsItems.GOLD_COIN_STACK.get());

                tabData.accept(FlamesAdditionsBlocks.GOLD_COIN_BLOCK.get().asItem());

                tabData.accept(FlamesAdditionsItems.DIAMOND_COIN.get());

                tabData.accept(FlamesAdditionsItems.DIAMOND_COIN_STACK.get());

                tabData.accept(FlamesAdditionsBlocks.DIAMOND_COIN_BLOCK.get().asItem());

                tabData.accept(FlamesAdditionsItems.NETHERITE_COIN.get());

                tabData.accept(FlamesAdditionsItems.NETHERITE_COIN_STACK.get());

                tabData.accept(FlamesAdditionsBlocks.NETHERITE_COIN_BLOCK.get().asItem());

                tabData.accept(FlamesAdditionsBlocks.ULTIMATIUM_ORE.get().asItem());

                tabData.accept(FlamesAdditionsItems.RAW_ULTIMATIUM.get());

                tabData.accept(FlamesAdditionsBlocks.RAW_ULTIMATIUM_BLOCK.get().asItem());

                tabData.accept(FlamesAdditionsItems.ULTIMATIUM.get());

            })

 

                    .build());

}

 

If you want all of your items/blocks to appear in your creative tab, then a simpler way is

    public static final RegistryObject<CreativeModeTab> SOME_TAB = TABS.register("your_tab_id",
            () -> CreativeModeTab.builder()
                    .title(Component.translatable("item_group." + Main.MOD_ID + ".items"))
                    .icon(() -> new ItemStack(Items.WHATEVER_ICON_ITEM))
                    .displayItems((parameters, output) -> {
                      	YourItemsClass.YOUR_ITEMS_REGISTRY.getEntries().forEach(reg -> output.accept(reg.get()));
                        YourBlocksClass.YOUR_BLOCKS_REGISTRY.getEntries().forEach(reg -> output.accept(reg.get()));
                    })
                    .build());

where TABS is a deferred register with key Registries.CREATIVE_MODE_TAB.

If you don't want every single item in the tab, or you want them split among multiple tabs, just put them in a list as you register them depending on which tab you want them in and iterate over that list instead of the entire registry.

The reason for these changes is that now vanilla allows an item to be in more than one tab. So, for example, you could put a weapon from your mod in your own custom tab, but also make it appear in the combat tab with other weapons. If you want to add to an existing tab, listen to BuildCreativeModeTabContentsEvent, check which tab it's for with event.getTab, and then use event.accept to send it your item.

Edited by itzer
include adding to vanilla tabs.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.