Jump to content

[1.16.4] Registry Object not present


RustedSkies

Recommended Posts

I've been trying to make a mod with a grass block slab but I keep getting an error saying "Registry Object not present: mod:grass_slab" when I try to do the coloring.

 

RegistryHandler: 

public class RegistryHandler {
	public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MyMod.MOD_ID);
	public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MyMod.MOD_ID);
	
	public static void init() {
		BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
		ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());

        ColorHandler.init();
	}

	public static final RegistryObject<Block> GRASS_SLAB = BLOCKS.register("grass_slab", () -> 
 		new SlabBlock(Block.Properties.create(Material.EARTH).hardnessAndResistance(0.5f, 0.5f).sound(SoundType.GROUND).harvestLevel(0).harvestTool(ToolType.SHOVEL)));
	
	public static final RegistryObject<Item> GRASS_SLAB_ITEM = ITEMS.register("grass_slab", () ->
	   new BlockItem(GRASS_SLAB.get(), new Item.Properties().group(ItemGroup.BUILDING_BLOCKS)));
}

 

ColorHandler:

public class ColorHandler {
	private final java.util.Map<net.minecraftforge.registries.IRegistryDelegate<Block>, IBlockColor> colors = new java.util.HashMap<>();
	
	public static ColorHandler init() {
		ColorHandler colorhandler = new ColorHandler();
		
		colorhandler.register((state, reader, pos, color) -> {
	         return reader != null && pos != null ? BiomeColors.getGrassColor(reader, pos) : GrassColors.get(0.5D, 1.0D);
	    }, RegistryHandler.GRASS_SLAB.get()); // Line 16
	    return colorhandler;
	}
	
	public void register(IBlockColor blockColor, Block... blocksIn) {
		for(Block block : blocksIn) {
			this.colors.put(block.delegate, blockColor);
	    }
	}
}

 

And this is the crash report:

A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Render thread
Stacktrace:
	at java.util.Objects.requireNonNull(Objects.java:290) ~[?:1.8.0_275] {}
-- MOD mod --
Details:
	Mod File: main
	Failure message: Mod (mod) has failed to load correctly
		java.lang.NullPointerException: Registry Object not present: mod:grass_slab
	Mod Version: NONE
	Mod Issue URL: http://my.issue.tracker/
	Exception message: java.lang.NullPointerException: Registry Object not present: mod:grass_slab
Stacktrace:
	at java.util.Objects.requireNonNull(Objects.java:290) ~[?:1.8.0_275] {}
	at net.minecraftforge.fml.RegistryObject.get(RegistryObject.java:120) ~[forge:?] {re:classloading}
	at dev.rustedskies.mod.utils.ColorHandler.init(ColorHandler.java:16) ~[?:?] {re:classloading}
	at dev.rustedskies.mod.utils.RegistryHandler.init(RegistryHandler.java:25) ~[?:?] {re:classloading}
	at dev.rustedskies.mod.MyMod.<init>(MyMod.java:42) ~[?:?] {re:classloading}
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_275] {}
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[?:1.8.0_275] {}
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:1.8.0_275] {}
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[?:1.8.0_275] {}
	at java.lang.Class.newInstance(Class.java:442) ~[?:1.8.0_275] {}
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.constructMod(FMLModContainer.java:81) ~[forge:35.1] {re:classloading}
	at net.minecraftforge.fml.ModContainer.lambda$buildTransitionHandler$4(ModContainer.java:120) ~[forge:?] {re:classloading}
	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1640) ~[?:1.8.0_275] {}
	at java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1632) ~[?:1.8.0_275] {}
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) ~[?:1.8.0_275] {}
	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) ~[?:1.8.0_275] {}
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) ~[?:1.8.0_275] {}
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:175) ~[?:1.8.0_275] {}

 

I've tried everything to get this to work, but I just can't figure it out.

Thank you!

Edited by RustedSkies
Link to comment
Share on other sites

5 hours ago, ChampionAsh5357 said:

Color handlers are registered in ColorHandlerEvent and should be isolated in some client only class as this will crash on the logical server. If you want an explanation of the error. You're registering color handlers before the registry events are fired which results in an NPE since the block doesn't exist yet.

How would I go about making the class client only, and making it fire after the registry events are?

I've tried putting @Onlyin(Dist.CLIENT) like the vanilla BlockColors class did to no avail.

Link to comment
Share on other sites

1 minute ago, RustedSkies said:

How would I go about making the class client only, and making it fire after the registry events are?

You can isolate the event in a separate class and attach it using one of the many event bus listener methods. Access to client only classes should be checked via DistExecutor. As for after registry events, I already answered that, use the ColorHandlerEvent and register using that.

2 minutes ago, RustedSkies said:

I've tried putting @Onlyin(Dist.CLIENT) like the vanilla BlockColors class did to no avail.

Don't use OnlyIn, its a hack for separating the client and server jars and does nothing to what you're dealing with.

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



×
×
  • Create New...

Important Information

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