Jump to content

Item DeferredRegister Issue


Caffeinated Pinkie

Recommended Posts

Here is most of my mod class:

public class Circuitry {
    public static final String MODID = "circuitry";

    private static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>(ForgeRegistries.BLOCKS, MODID);
    public static final RegistryObject<Block> IN_NODE = BLOCKS.register("in_node", InNodeBlock::new), OUT_NODE = BLOCKS.register("out_node", OutNodeBlock::new);

    public Circuitry() {
		DeferredRegister<Item> items = new DeferredRegister<>(ForgeRegistries.ITEMS, MODID);
		BLOCKS.getEntries().forEach(block -> items.register(block.getId().getPath(), () -> new BlockItem(block.get(), new Properties().group(ItemGroup.REDSTONE))));

		IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
		bus.register(BLOCKS);
		bus.register(items);
	}
}

 

I have the Item DeferredRegister and RegistryObjects in the constructor rather than statically declaring it because I never need to retrieve the Item objects anywhere else in my code. However, upon loading a world, I am unable to find any of the added Blocks in the Redstone tab of the creative menu. The following commands don't work either:

/give Dev circuitry:in_node
/give Dev circuitry:out_node

 

Declaring the Item DeferredRegister and RegistryObjects statically doesn't seem to fix the problem either. Printing the Item DeferredRegistry shows two entries with the correct names.

 

No error messages are thrown and I can't determine why this is occurring.

Link to comment
Share on other sites

8 hours ago, Caffeinated Pinkie said:

No error messages are thrown and I can't determine why this is occurring.

Because when this line runs:

8 hours ago, Caffeinated Pinkie said:

BLOCKS.getEntries().forEach(block -> items.register(block.getId().getPath(), () -> new BlockItem(block.get(), new Properties().group(ItemGroup.REDSTONE))));

Your BLOCKS contains no entries because block registration hasn't happened yet.

Register your stuff properly.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

3 hours ago, Draco18s said:

Because when this line runs:

Your BLOCKS contains no entries because block registration hasn't happened yet.

Register your stuff properly.

Well, when I iterate through the BLOCKS entries, it shows two RegistryObjects in it. After running the command to create items as I did, there are two RegistryObjects in the items entries. They all have the correct names as well. It seems functionally identical to defining them as so:

public Circuitry() {
	DeferredRegister<Item> items = new DeferredRegister<>(ForgeRegistries.ITEMS, MODID);
	items.register("in_node", () -> new BlockItem(IN_NODE.get(), new Properties().group(ItemGroup.REDSTONE)));
	items.register("out_node", () -> new BlockItem(OUT_NODE.get(), new Properties().group(ItemGroup.REDSTONE)));

	IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
	bus.register(BLOCKS);
	bus.register(items);
}

and even doing this statically like so:

public class Circuitry {
	private static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>(ForgeRegistries.BLOCKS, MODID);
	private static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, MODID);

	public static final RegistryObject<Block> IN_NODE = BLOCKS.register("in_node", InNodeBlock::new), OUT_NODE = BLOCKS.register("out_node", OutNodeBlock::new);

	static {
		ITEMS.register("in_node", () -> new BlockItem(IN_NODE.get(), new Properties().group(ItemGroup.REDSTONE)));
		ITEMS.register("out_node", () -> new BlockItem(OUT_NODE.get(), new Properties().group(ItemGroup.REDSTONE)));
	}

	public Circuitry() {
		IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
		bus.register(BLOCKS);
		bus.register(ITEMS);
    }
}

Even writing it identical to how the documentation does it doesn't help:

public class Circuitry {
    private static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>(ForgeRegistries.BLOCKS, MODID);
    private static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, MODID);

    public static final RegistryObject<Block> IN_NODE_BLOCK = BLOCKS.register("in_node", InNodeBlock::new), OUT_NODE_BLOCK = BLOCKS.register("out_node", OutNodeBlock::new);
    public static final RegistryObject<Item> IN_NODE_ITEM = ITEMS.register("in_node", () -> new BlockItem(IN_NODE_BLOCK.get(), new Properties().group(ItemGroup.REDSTONE))), OUT_NODE_ITEM = ITEMS.register("out_node", () -> new BlockItem(OUT_NODE_BLOCK.get(), new Properties().group(ItemGroup.REDSTONE)));

    public Circuitry() {
		IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
		bus.register(BLOCKS);
		bus.register(ITEMS);
    }
}

 

Link to comment
Share on other sites

3 minutes ago, Caffeinated Pinkie said:

It seems functionally identical to defining them as so:

It is not.

 

This:

image.png.9864634970c01cb9e2abb4367cb2a75d.png

Runs immediately.

 

This:

image.png.68c82e1350d10ee8163320bac176daa4.png

Runs at a deferred time.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.