Jump to content

Registry Object not present when registering BlockItem.


Darkorg69

Recommended Posts

So I am getting this error while trying to register a seed blockitem for a crop block.

Spoiler
[18:51:15] [modloading-worker-0/ERROR] [ne.mi.fm.ja.FMLModContainer/LOADING]: Failed to create mod instance. ModID: bettercrops, class darkorg.bettercrops.BetterCrops
java.lang.reflect.InvocationTargetException: null
	at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?] {}
	at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?] {}
	at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?] {}
	at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?] {}
	at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?] {}
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:67) ~[javafmllanguage-1.18.2-40.1.86.jar%2380!/:?] {}
	at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:106) ~[fmlcore-1.18.2-40.1.86.jar%2383!/:?] {}
	at java.util.concurrent.CompletableFuture$AsyncRun.run$$$capture(CompletableFuture.java:1804) [?:?] {}
	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java) [?:?] {}
	at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796) [?:?] {}
	at java.util.concurrent.ForkJoinTask.doExec$$$capture(ForkJoinTask.java:373) [?:?] {}
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java) [?:?] {}
	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: java.lang.ExceptionInInitializerError
	at darkorg.bettercrops.BetterCrops.<init>(BetterCrops.java:22) ~[%2384!/:?] {re:classloading}
	... 16 more
Caused by: java.lang.NullPointerException: Registry Object not present: bettercrops:barley
	at java.util.Objects.requireNonNull(Objects.java:334) ~[?:?] {}
	at net.minecraftforge.registries.RegistryObject.get(RegistryObject.java:320) ~[forge-1.18.2-40.1.86_mapped_parchment_2022.11.06-1.18.2-recomp.jar%2378%2385!/:?] {re:classloading,xf:fml:forge:registry_object_binary_compat}
	at darkorg.bettercrops.registry.ModItems.<clinit>(ModItems.java:17) ~[%2384!/:?] {re:classloading}
	at darkorg.bettercrops.BetterCrops.<init>(BetterCrops.java:22) ~[%2384!/:?] {re:classloading}
	... 16 more
[18:51:16] [main/FATAL] [ne.mi.fm.ModLoader/LOADING]: Failed to complete lifecycle event CONSTRUCT, 1 errors found
Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:39)
	at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53)
	at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71)
	at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.run(Launcher.java:106)
	at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.Launcher.main(Launcher.java:77)
	at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26)
	at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23)
	at [email protected]/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149)
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at MC-BOOTSTRAP/[email protected]/net.minecraftforge.fml.loading.targets.ForgeDataUserdevLaunchHandler.lambda$launchService$0(ForgeDataUserdevLaunchHandler.java:27)
	at MC-BOOTSTRAP/[email protected]/cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)
	... 7 more
Caused by: net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [
	fml.modloading.failedtoloadmod
]
	at LAYER PLUGIN/[email protected]/net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:222)
	at LAYER PLUGIN/[email protected]/net.minecraftforge.fml.ModLoader.lambda$dispatchAndHandleError$21(ModLoader.java:187)
	at java.base/java.util.Optional.ifPresent(Optional.java:178)
	at LAYER PLUGIN/[email protected]/net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:187)
	at LAYER PLUGIN/[email protected]/net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$11(ModLoader.java:164)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at LAYER PLUGIN/[email protected]/net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:164)
	at TRANSFORMER/[email protected]/net.minecraftforge.data.loading.DatagenModLoader.begin(DatagenModLoader.java:38)
	at TRANSFORMER/[email protected]/net.minecraft.data.Main.main(Main.java:67)
	... 13 more
Disconnected from the target VM, address: '127.0.0.1:54565', transport: 'socket'

Process finished with exit code 1

 

Blocks class:

Spoiler
public class ModBlocks {
    public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, BetterCrops.MOD_ID);

    public static final RegistryObject<Block> BARLEY = registerCrop("barley");

    private static RegistryObject<Block> registerCrop(String pName) {
        return BLOCKS.register(pName, ModCropBlock::new);
    }
}

 

Items class:

Spoiler
public class ModItems {
    public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, BetterCrops.MOD_ID);
    
    public static final RegistryObject<Item> BARLEY_SEEDS = registerSeed("barley_seeds", ModBlocks.BARLEY.get());

    private static RegistryObject<Item> registerSeed(String pSeed, Block pCrop) {
        return ITEMS.register(pSeed, () -> new SeedBlockItem(pCrop));
    }
}

 

SeedBlockItem class:

Spoiler
public class SeedBlockItem extends ItemNameBlockItem {
    public SeedBlockItem(Block pBlock) {
        super(pBlock, new Properties().tab(ModCreativeTabs.TAB_SEEDS));
    }
}

 

ModCropBlock class:

Spoiler
public class ModCropBlock extends CropBlock {
    public ModCropBlock() {
        super(BlockBehaviour.Properties.of(Material.PLANT).noCollission().randomTicks().instabreak().sound(SoundType.CROP));
    }

    @Override
    protected @NotNull ItemLike getBaseSeedId() {
        return this.asItem();
    }
}

 

Main class:

Spoiler
@Mod(BetterCrops.MOD_ID)
public class BetterCrops {
    public static final String MOD_ID = "bettercrops";

    IEventBus forgeBus = MinecraftForge.EVENT_BUS;

    IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();

    public BetterCrops() {
        ServerConfig.init();
        ModBlocks.BLOCKS.register(modBus);
        ModItems.ITEMS.register(modBus);
        forgeBus.register(this);
    }
}

 

I have registered the block but the supplier.get() doesn't resolve the block for some reason. Any ideas what is wrong?

Link to comment
Share on other sites

You are trying to access the unregistered block during classloading (static initialisation).

You need to understand how deferred references work (Suppliers, RegistryObject, etc.) and when you can call get()

This is an important pattern within forge/minecraft.

 

Something like:

 
    // Pass the supplier, don't try to get the unregistered block yet
    public static final RegistryObject<Item> BARLEY_SEEDS = registerSeed("barley_seeds", ModBlocks.BARLEY);

    // Method accepts the supplier
    private static RegistryObject<Item> registerSeed(String pSeed, RegistryObject<Block> pCrop) {
        // Retrieve the block object at registration time
        return ITEMS.register(pSeed, () -> new SeedBlockItem(pCrop.get()));
    }

 

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

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

    • If you're seeking an unparalleled solution to recover lost or stolen cryptocurrency, let me introduce you to GearHead Engineers Solutions. Their exceptional team of cybersecurity experts doesn't just restore your funds; they restore your peace of mind. With a blend of cutting-edge technology and unparalleled expertise, GearHead Engineers swiftly navigates the intricate web of the digital underworld to reclaim what's rightfully yours. In your moment of distress, they become your steadfast allies, guiding you through the intricate process of recovery with transparency, trustworthiness, and unwavering professionalism. Their team of seasoned web developers and cyber specialists possesses the acumen to dissect the most sophisticated schemes, leaving no stone unturned in their quest for justice. They don't just stop at recovering your assets; they go the extra mile to identify and track down the perpetrators, ensuring they face the consequences of their deceitful actions. What sets  GearHead Engineers apart is not just their technical prowess, but their unwavering commitment to their clients. From the moment you reach out to them, you're met with compassion, understanding, and a resolute determination to right the wrongs inflicted upon you. It's not just about reclaiming lost funds; it's about restoring faith in the digital landscape and empowering individuals to reclaim control over their financial futures. If you find yourself ensnared in the clutches of cybercrime, don't despair. Reach out to GearHead Engineers and let them weave their magic. With their expertise by your side, you can turn the tide against adversity and emerge stronger than ever before. In the realm of cybersecurity, GearHead Engineers reigns supreme. Don't just take my word for it—experience their unparalleled excellence for yourself. Your journey to recovery starts here.
    • Ok so this specific code freezes the game on world creation. This is what gets me so confused, i get that it might not be the best thing, but is it really so generation heavy?
    • Wizard web recovery has exhibited unparalleled strength in the realm of recovery. They stand out as the premier team to collaborate with if you encounter withdrawal difficulties from the platform where you’ve invested. Recently, I engaged with them to recover over a million dollars trapped in an investment platform I’d been involved with for months. I furnished their team with every detail of the investment, including accounts, names, and wallet addresses to which I sent the funds. This decision proved to be the best I’ve made, especially after realizing the company had scammed me.   Wizard web recovery ensures exemplary service delivery and ensures the perpetrators face justice. They employ advanced techniques to ensure you regain access to your funds. Understandably, many individuals who have fallen victim to investment scams may still regret engaging in online services again due to the trauma of being scammed. However, I implore you to take action. Seek assistance from Wizard Web Recovery today and witness their remarkable capabilities. I am grateful that I resisted their enticements, and despite the time it took me to discover Wizard web recovery, they ultimately fulfilled my primary objective. Without wizard web recovery intervention, I would have remained despondent and perplexed indefinitely.
    • I've tested the same code on three different envionrments (Desktop win10, desktop Linux and Laptop Linux) and it kinda blows up all the same. Gonna try this code and see if i can tune it
  • Topics

×
×
  • Create New...

Important Information

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