Minecraft Registryobject Not Present

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.

1

2 Answers

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(...)
2

Before beginning, it would be beneficial to those wishing to assist you if you were to mention the version of Forge that you are targeting. That said, as it appears you are using DeferredRegistry and RegistryObject to register your entities, etc, I believe that the following information will be correct for your version.

The problem that is occurring, is that the deferred registration is attempting to eagerly construct MobBucketItem when it is time to register your bucket item. As Items are registered before Entities, this leads to the RegistryObject for EntityInit.EEL being empty, hence calling get() crashing the mod loading process.

The solution is to use the MobBucketItem's other constructor, which takes a supplier to the entity as its first argument and not an EntityType. A Supplier is either a class that implements the supplier interface, or a lambda that returns a value of the form () -> value. This will look familiar as that is how you provide the value to return to the registry once Forge begins building the Item Registry

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

Internally, Forge deprecates the constructor you were using to make the MobBucketItem and wraps the first 3 arguments in suppliers, then calls the form of the constructor which accepts those suppliers. This is specifically to allow the use of modded entities, fluids, and sounds, even if their registries haven't been built yet.

So to wrap up, take the first three arguments you were previously passing into the constructor, and turn them into suppliers. If that version of the constructor does not exist in the version of Forge you are targeting, then I recommend updating your version of Forge to one that does provide that overload.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sophia Al-Mansoor
Author

Sophia Al-Mansoor

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.