Jump to content

Recommended Posts

Posted (edited)

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
Posted

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

}

 

Posted (edited)

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

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

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So, I have a minecraft world hosted with essential on forge 1.20.1, there's 149 mods, and the forge version is 47.3.0, and it's been like that for a good 2-3 weeks, and all of a sudden, it stopped loading, and I have 0 clue as to why, and this world means A LOT to me, so if anyone out there is able to help, I would GLADLY appreciate it. here's the link if ya wanna help:   [04Dec2024 22:42:24.552] [Worker-ResourceReload-3/ERROR][net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener/]: Couldn't parse data file slabsexpanded:snow_blockblocktoslab from slabsexpanded:recipes/snow_blockblocktoslab.json com.google.gson.JsonParseException: com.google.gson.stream.MalformedJsonException: Expected name at line 16 column 4 path $.result.item at net.minecraft.util.GsonHelper.m_13780_(GsonHelper.java:526) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.util.GsonHelper.m_263475_(GsonHelper.java:531) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.util.GsonHelper.m_13776_(GsonHelper.java:581) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener.m_278771_(SimpleJsonResourceReloadListener.java:41) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener.m_5944_(SimpleJsonResourceReloadListener.java:29) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener.m_5944_(SimpleJsonResourceReloadListener.java:17) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at net.minecraft.server.packs.resources.SimplePreparableReloadListener.m_10786_(SimplePreparableReloadListener.java:11) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?] at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768) ~[?:?] at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760) ~[?:?] at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] Caused by: com.google.gson.stream.MalformedJsonException: Expected name at line 16 column 4 path $.result.item at com.google.gson.stream.JsonReader.syntaxError(JsonReader.java:1657) ~[gson-2.10.jar%23107!/:?] at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:514) ~[gson-2.10.jar%23107!/:?] at com.google.gson.stream.JsonReader.hasNext(JsonReader.java:422) ~[gson-2.10.jar%23107!/:?] at com.google.gson.internal.bind.TypeAdapters$28.read(TypeAdapters.java:779) ~[gson-2.10.jar%23107!/:?] at com.google.gson.internal.bind.TypeAdapters$28.read(TypeAdapters.java:725) ~[gson-2.10.jar%23107!/:?] at com.google.gson.internal.bind.TypeAdapters$34$1.read(TypeAdapters.java:1007) ~[gson-2.10.jar%23107!/:?] at net.minecraft.util.GsonHelper.m_13780_(GsonHelper.java:524) ~[client-1.20.1-20230612.114412-srg.jar%23490!/:?]
    • Hello! I have been having a problem with Forgematica, Embeddium, Oculus, and create. I wanted to download litematica so I could see which blocks are in my creative mode build, so that I could collect them all in survival. However, litematica is a fabric mod. I found a port called forgematica, which I added (along with it's dependency) to my mods folder. I loaded into a new world, and built a structure. Then, I added a part from the create mod, and the game crashed instantly, with exit code -1. Thanks for any help! Crash Report and mods list: https://pastebin.com/rtzh6LAi
    • Have you found a modder for this vehicle project? Because it will be really hard and I want to know that hero who can create all this
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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