Posted August 25, 20214 yr 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?
August 25, 20214 yr Author 58 minutes ago, diesieben07 said: Refer to the documentation on how to register things: https://mcforge.readthedocs.io/en/latest/concepts/registries/. Note that you should not put a DeferredRegister and its entries in separate classes like you've done here. I'm just following a tutorial... Edited August 25, 20214 yr by ItamarCohen
August 25, 20214 yr 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?
August 25, 20214 yr Author Just now, ItamarCohen said: So I need to change the item to be in registration? And how do you know that?
August 25, 20214 yr 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
August 25, 20214 yr 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
August 25, 20214 yr 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.
August 25, 20214 yr 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
August 25, 20214 yr 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); } }
August 25, 20214 yr 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. idk if i messed up on something, hope this helps.
August 26, 20214 yr 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. idk if i messed up on something, hope this helps. But, how do I get the item now? and add texture to it?
August 26, 20214 yr 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. idk if i messed up on something, hope this helps. Do I need to call the initiates function?
August 26, 20214 yr 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.