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

Hi I'm creating a Minecraft mode, andI'm trying to add silver ingot to the game as a test.

Unfortunately it doesn't work.

package com.lightning.lightningmod.setup;

import net.minecraft.world.item.Item;
import net.minecraftforge.registries.DeferredRegister;

public class ModItems {
    public static final DeferredRegister<Item> SILVER_INGOT = Registration.ITEMS.register("silver_ingot", () ->
            new Item(new Item.Properties().tab(ItemGroup.MATERIALS)));
}

It just doesn't recognize it as a class, with no option to import, any solutions?

  • Author
5 minutes ago, diesieben07 said:

"ModItems" holds your item, but the DeferrdRegister is in the "Registration" class.

So I need to change the item to be in registration?

 

  • Author
Just now, diesieben07 said:

Please refer to the linked documentation. It shows you exactly how do do it correctly.

What?

I referred to the documentation, and tried the example with blocks, didn't work, I 'm using IntelliJ, so I can let you collaborate

 

  • Author
1 minute ago, diesieben07 said:

Please refer to the linked documentation. It shows you exactly how do do it correctly.

What?

I referred to the documentation, and tried the example with blocks, didn't work, I 'm using IntelliJ, so I can let you collaborate

 

  • Author

Main:

package com.lightning.lightningmod;

import com.lightning.lightningmod.setup.Registration;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fmlserverevents.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.stream.Collectors;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("lightningmod")
public class Main
{
    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();
    public static final String MODID = "lightningmod";
    public Main() {
        Registration.register();
        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the enqueueIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event)
    {
        // some preinit code
        LOGGER.info("HELLO FROM PREINIT");
        LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
    }

    private void enqueueIMC(final InterModEnqueueEvent event)
    {
        // some example code to dispatch IMC to another mod
        InterModComms.sendTo("lightningmod", "helloworld", () -> { LOGGER.info("Hello world from the MDK and Itamar"); return "Hello world";});
    }

    private void processIMC(final InterModProcessEvent event)
    {
        // some example code to receive and process InterModComms from other mods
        LOGGER.info("Got IMC {}", event.getIMCStream().
                map(m->m.messageSupplier().get()).
                collect(Collectors.toList()));
    }
    // You can use SubscribeEvent and let the Event Bus discover methods to call
    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        // do something when the server starts
        LOGGER.info("HELLO from server starting");
    }

    // You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
    // Event bus for receiving Registry Events)
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
            // register a new block here
            LOGGER.info("HELLO from Register Block");
        }
    }
}

 

Registration:

package com.lightning.lightningmod.setup;

import com.lightning.lightningmod.Main;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class Registration {
    public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Main.MODID);
    public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Main.MODID);


    public static void register() {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
        BLOCKS.register(modEventBus);
        ITEMS.register(modEventBus);
    }
}

ModItems:

package com.lightning.lightningmod.setup;

import net.minecraft.world.item.Item;
import net.minecraft.world.item.*;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.registries.DeferredRegister;


public class ModItems {
    public static final DeferredRegister<Item> SILVER_INGOT = Registration.ITEMS.register("silver_ingot", () -> new Item(new Item.Properties().tab(ItemGroup.MATERIALS)));
}

The error is in the ModItems Class.

Cannot resolve symbol 'ItemGroup'

It's not giving an option to import it.

  • Author
Just now, diesieben07 said:
  • You still have the DeferredRegister and its entries in separate classes. This will cause problems.
  • What version of Minecraft are you using?

1.17.1

 

  • Author
Just now, ItamarCohen said:

1.17.1

 

I changed the registration file to:

package com.lightning.lightningmod.setup;

import com.lightning.lightningmod.Main;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class Registration {
    public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, Main.MODID);
    public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, Main.MODID);
    public static final DeferredRegister<Item> SILVER_INGOT = Registration.ITEMS.register("silver_ingot", () -> new Item(new Item.Properties().tab(ItemGroup.MATERIALS)));


    public static void register() {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
        BLOCKS.register(modEventBus);
        ITEMS.register(modEventBus);
    }
}

 

Code should look something like this:

public class ModItems {

	public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, ExampleMod.MODID);
	
	public static void initItems() {
		ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
	}
	
	public static final RegistryObject<Item> COPPER_INGOT = ITEMS.register("copper_ingot", ()->
		new Item(new Item.Properties().tab(CreativeModeTab.TAB_MATERIALS))
	);
}

Not an expert myself, but the main things here are:

1.- A deferred register must be in the same class as it's RegistryObjects (it's entries)

2.- The method register(name, supplier) of a DeferredRegister (the one you call when you need to register something) returns a RegistryObject, not a DeferredRegister. In your code you incorrectly assign it to a DeferredRegister.

3.- About the ItemGroup problem, at some point ItemGroup must've changed to CreativeModeTab (like in my example which i've tested and it works). I don't know if that's the case for the version of forge you're using. In any case, just check what argument the method 'tab' wants, and give it that. Like in the image.

image.png.97726cfd09e1100ba8c1732575df7809.png

 

idk if i messed up on something, hope this helps.

 

  • Author
15 hours ago, Tryhard said:

Code should look something like this:


public class ModItems {

	public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, ExampleMod.MODID);
	
	public static void initItems() {
		ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
	}
	
	public static final RegistryObject<Item> COPPER_INGOT = ITEMS.register("copper_ingot", ()->
		new Item(new Item.Properties().tab(CreativeModeTab.TAB_MATERIALS))
	);
}

Not an expert myself, but the main things here are:

1.- A deferred register must be in the same class as it's RegistryObjects (it's entries)

2.- The method register(name, supplier) of a DeferredRegister (the one you call when you need to register something) returns a RegistryObject, not a DeferredRegister. In your code you incorrectly assign it to a DeferredRegister.

3.- About the ItemGroup problem, at some point ItemGroup must've changed to CreativeModeTab (like in my example which i've tested and it works). I don't know if that's the case for the version of forge you're using. In any case, just check what argument the method 'tab' wants, and give it that. Like in the image.

image.png.97726cfd09e1100ba8c1732575df7809.png

 

idk if i messed up on something, hope this helps.

 

But, how do I get the item now? and add texture to it?

  • Author
15 hours ago, Tryhard said:

Code should look something like this:


public class ModItems {

	public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, ExampleMod.MODID);
	
	public static void initItems() {
		ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
	}
	
	public static final RegistryObject<Item> COPPER_INGOT = ITEMS.register("copper_ingot", ()->
		new Item(new Item.Properties().tab(CreativeModeTab.TAB_MATERIALS))
	);
}

Not an expert myself, but the main things here are:

1.- A deferred register must be in the same class as it's RegistryObjects (it's entries)

2.- The method register(name, supplier) of a DeferredRegister (the one you call when you need to register something) returns a RegistryObject, not a DeferredRegister. In your code you incorrectly assign it to a DeferredRegister.

3.- About the ItemGroup problem, at some point ItemGroup must've changed to CreativeModeTab (like in my example which i've tested and it works). I don't know if that's the case for the version of forge you're using. In any case, just check what argument the method 'tab' wants, and give it that. Like in the image.

image.png.97726cfd09e1100ba8c1732575df7809.png

 

idk if i messed up on something, hope this helps.

 

Do I need to call the initiates function?

  • Author
4 minutes ago, diesieben07 said:

Of course? If you never call a function it doesn't do anything...?

To "get to the item" you just access the RegistryObject you got when registering it.

To add a texture, you just need to create a model for it in the correct folder in assets. Refer to vanilla blocks for more info.

OK

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.