Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12] NullPointerException populating the SearchTree
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
TheA13X

[1.12] NullPointerException populating the SearchTree

By TheA13X, November 29, 2017 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

TheA13X    0

TheA13X

TheA13X    0

  • Tree Puncher
  • TheA13X
  • Members
  • 0
  • 30 posts
Posted November 29, 2017

Hi there!

 

I'm currently updating one of my mods to 1.12 (and 1.12.2). While doing that I ran into this exception:

Quote

---- Minecraft Crash Report ----
// But it works on my machine. Oh wait, no it doesn't :(

Time: 11/29/17 1:30 PM
Description: Initializing game

java.lang.NullPointerException: Initializing game
    at net.minecraft.client.util.SearchTree.lambda$index$0(SearchTree.java:91)
    at java.util.Collections$SingletonSet.forEach(Collections.java:4767)
    at net.minecraft.client.util.SearchTree.index(SearchTree.java:89)
    at net.minecraft.client.util.SearchTree.add(SearchTree.java:78)
    at java.lang.Iterable.forEach(Iterable.java:75)
    at net.minecraft.client.Minecraft.populateSearchTreeManager(Minecraft.java:634)
    at net.minecraft.client.Minecraft.init(Minecraft.java:570)
    at net.minecraft.client.Minecraft.run(Minecraft.java:416)
    at net.minecraft.client.main.Main.main(Main.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
    at GradleStart.main(GradleStart.java:26)

 

Here's what I found out so far:

 

The exception is caused, because the Lambda Functions, given to the Search Tree as an argument, returned null:

//Citing Minecraft.java
/*618*/SearchTree<ItemStack> searchtree = new SearchTree<ItemStack>(
/*   */(p_193988_0_) ->
/*619*/{
/*620*/  return (List)p_193988_0_.getTooltip((EntityPlayer)null, ITooltipFlag.TooltipFlags.NORMAL).stream().map(TextFormatting::getTextWithoutFormattingCodes).map(String::trim).filter((p_193984_0_) -> {
/*621*/    return !p_193984_0_.isEmpty();
/*622*/  }).collect(Collectors.toList());
/*623*/}, 
/*    */(p_193985_0_) ->
/*624*/{
/*625*/  return Collections.singleton(Item.REGISTRY.getNameForObject(p_193985_0_.getItem()));
/*626*/});

-> Item.REGISTRY.getNameForObject(ItemStack.getItem) returned null.

The question that remains is, why?

It must have something to do with the registration process. Therefore I have to tell you

How the Registration works:

1.Loading

When the FMLPreInitializationEvent is fired, all blocks/"pure" Items get constructed and loaded into static lists located in my ModBlocks/ModItems class

 

2. Registering

On the Register<Item>-Event the following code is executed:

//Citing Registrator.java
/*17*/@SubscribeEvent
/*18*/public static void registerItems(RegistryEvent.Register<Item> event){
/*19*/  event.getRegistry().register(ModItems.parcelInstance()); //Register the only "pure" Item in this Mod. Does not throw the NullPointerException in the Search Tree
/*20*/  ModBlocks.registerAllItems(event.getRegistry());//Register all the Block Items in this Mod
}

RegisterAllItems:

public static void registerAllItems(IForgeRegistry<Item> reg)
{
  	registerAllLogItems(reg);
  	registerAllLeavesItems(reg);
  	registerAllSaplingItems(reg);
  	registerAllWoodItems(reg);
  	registerAllStairsItems(reg);
  	registerAllDoorItems(reg);
  	registerAllSingleSlabItems(reg);
}

Example for a Registering function:

//Citing ModBlocks.java
/*208*/private static void registerAllLogItems(IForgeRegistry<Item> reg) //It crashed on the Log Block Item btw.
/*209*/{
/*210*/  int logCount = 0;
/*211*/  for (final LogBlock block : logBlocks)//for every Log Block...
/*212*/  {
/*213*/    String name = String.format("log%d", logCount);//...define registry name...
/*214*/    ImmutableList<String> subblockNames = block.getSubBlockNames();//...get all the Subblock names... 
/*215*/    if(block instanceof  ModLogBlock){//... if type 1...
/*216*/      reg.register(new ModLogItem(block,(ModLogBlock)block,subblockNames.toArray(new String[subblockNames.size()])).setRegistryName(name));//...register Item using the Type 1 item constructor after setting the registry name  
/*217*/    }
/*218*/    else if(block instanceof  ModLog2Block){//... if type 2...
/*219*/      reg.register(new ModLogItem(block,(ModLog2Block)block,subblockNames.toArray(new String[subblockNames.size()])).setRegistryName(name));//...register Item using the Type 2 item constructor after setting the registry name  
/*220*/    }
/*221*/    else if(block instanceof  ModLog3Block){//... if type 3...
/*222*/      reg.register(new ModLogItem(block,(ModLog3Block)block,subblockNames.toArray(new String[subblockNames.size()])).setRegistryName(name));//...register Item using the Type 3 item constructor after setting the registry name  
/*223*/    }
/*224*/    else{//... if type 4...
/*225*/      reg.register(new ModLogItem(block,(ModLog4Block)block,subblockNames.toArray(new String[subblockNames.size()])).setRegistryName(name));//...register Item using the Type 4 item constructor after setting the registry name  
/*226*/    }
/*227*/    logCount++;
/*228*/  }
/*229*/}

The Block registration works in the same way, only with on the Register<Block>-Event, instead of the item one.

I guess it's also important

How the Block Classes look like

Essentially I have a mod (Koresample) containing all the "basic" block/item classes and my specialized Mod (Dendrology) containing Classes with logic for the specific tree types.

Pasting all of them would be way to much so I'll just link my GitHub.

Koresample

Dendrology:

 

I know it's a bit much, but this problem seems quite unusual...

Thanks for trying and help me out. I got nothin'

 

  • Quote

Sincerely,

A13XIS

Share this post


Link to post
Share on other sites

XFactHD    16

XFactHD

XFactHD    16

  • Diamond Finder
  • XFactHD
  • Members
  • 16
  • 372 posts
Posted December 1, 2017 (edited)

You can't populate those static list's of Blocks and Items in FMLPreInitializationEvent and then expect them to be populated in the RegistryEvent as the registry events are fired before the FMLPreInitializationEvent.

Edited December 1, 2017 by XFactHD
  • Quote

Share this post


Link to post
Share on other sites

TheA13X    0

TheA13X

TheA13X    0

  • Tree Puncher
  • TheA13X
  • Members
  • 0
  • 30 posts
Posted December 1, 2017 (edited)
12 hours ago, XFactHD said:

[...] registry events are fired before the FMLPreInitializationEvent.

No. No they are not.

 

I Debugged Forge's building process line by line, so I know that the all registry events are fired after the FMLPreInitializationEvent.

Also if the Registry Events were fired before the lists are populated, there would be no exception in the first place.

Edited December 1, 2017 by TheA13X
  • Quote

Sincerely,

A13XIS

Share this post


Link to post
Share on other sites

ScottKillen    17

ScottKillen

ScottKillen    17

  • Creeper Killer
  • ScottKillen
  • Forge Modder
  • 17
  • 144 posts
Posted December 5, 2017

I had to change my ways for 1.12. This works:

 

Blocks

Items

 

I hope that helps.

 

I'm glad to see you updating this!

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Asleep365
      [1.15.2] Generating/replacing resources in biomes

      By Asleep365 · Posted 6 minutes ago

      I figured out how to avoid the ore generation timing; by setting GenerationStage.Decoration.UNDERGROUND_ORES to RAW_GENERATION, the ores will only show up on stone. Still can't figure out how to generate over the limestone yet
    • JeffMan
      [1.15] replacing chunks

      By JeffMan · Posted 23 minutes ago

      I am familiar with java and other oop languages, but not familiar with how forge + Minecraft works.    I am trying to port Bobby [fabric] to forge: https://www.curseforge.com/minecraft/mc-mods/bobby   Goal: ----------  - Load chunks from a saved singleplayer world into array?  - replace chunks in player current world (connected to server but only show for client) with a chunk from the array outside of server view distance. - unload chunks from client side as needed as player moves.   Is this possible with version 1.15 forge api or is there a library addon that I can use ?  
    • diesieben07
      Server Console errors

      By diesieben07 · Posted 26 minutes ago

      Please post the server debug.log.
    • diesieben07
      1.16.4 "The Vanilla Experience" Server problem

      By diesieben07 · Posted 31 minutes ago

      Looks like you have a client-only mod ("Omega Mute") installed on the server. If this is a pre-made modpack, make sure it does not have a dedicated server pack. If it doesn't, report this to the pack owners.
    • diesieben07
      Minecraft forge server login problem

      By diesieben07 · Posted 32 minutes ago

      User was banned for supporting piracy. Buy the game.
  • Topics

    • Asleep365
      1
      [1.15.2] Generating/replacing resources in biomes

      By Asleep365
      Started 15 hours ago

    • JeffMan
      0
      [1.15] replacing chunks

      By JeffMan
      Started 23 minutes ago

    • chuckdie5el
      1
      Server Console errors

      By chuckdie5el
      Started 35 minutes ago

    • Gęsioł
      1
      1.16.4 "The Vanilla Experience" Server problem

      By Gęsioł
      Started 34 minutes ago

    • Greenshark3D
      5
      Minecraft forge server login problem

      By Greenshark3D
      Started 1 hour ago

  • Who's Online (See full list)

    • LeoBeliik
    • diesieben07
    • JeffMan
    • D0XY
    • Asleep365
    • DaemonUmbra
    • Jason_Whittaker
    • MetalMetagross
    • Sr_endi
    • Klarks
    • Caleb949
    • monkeysHK
    • Will11690
    • MrLoop95
    • Chumbanotz
    • ambermarsh
    • Talp1
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.12] NullPointerException populating the SearchTree
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community