'Minecraft RegistryObject not present

I'm a new minecraft modder, and I'm trying to make a new mob bucket item.

Everytime I run the game, the game crashes saying that the RegistryObject for my modded entity isn't present.

Here is the code in question:

public class ItemInit {
    
    private ItemInit() {}
    
    public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, TheDeepBlue.MODID);
    
    public static final RegistryObject<MobBucketItem> EEL_BUCKET = 
        ITEMS.register("eel_bucket", () -> new MobBucketItem(EntityInit.EEL.get(), Fluids.WATER, SoundEvents.BUCKET_EMPTY_FISH, new Item.Properties().stacksTo(1).tab(CreativeModeTab.TAB_MISC)));
    
             
}

I would really appreciate some help on this. Please let me know if I need to provide anything else. Thank you.



Solution 1:[1]

Your entity will load after your item. So EntityInit.EEL is not loaded. You should not use RegistryObject for your entity, but you can directly instantiate it instead.

For example:

public static final EntityType<Entity> FOO = EntityType.Builder.of(...)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 0x3f