Jump to content

I don't have a "tab" method


LixNew

Recommended Posts

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
Link to comment
Share on other sites

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());

}

 

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

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