Jump to content

Recommended Posts

Posted (edited)

I am currently porting all of my former event-based registration to deferred register and I am having some problems with my custom registry. Here is the building of the custom registry (which worked fine with events):
 

@SubscribeEvent
public static void registerRegistries(final RegistryEvent.NewRegistry event) {
		
	// Quest Task
	RegistryBuilder<QuestTask> questTaskBuilder = new RegistryBuilder<QuestTask>();
	questTaskBuilder.setType(QuestTask.class);
	ResourceLocation questTaskLocation = DaBoisMod.modLocation("quest_task");
	questTaskBuilder.setName(questTaskLocation);
	questTaskBuilder.setDefaultKey(questTaskLocation);
	questTaskBuilder.create();
}

 

I'm trying to use deferred register with this:

public class QuestTasks {
  	private static final DeferredRegister<QuestTask> QUEST_TASKS = new DeferredRegister<>(GameRegistry.findRegistry(QuestTask.class), DaBoisMod.MODID);
	
	public static void registerQuestTasks(IEventBus eventBus) {
		QuestTasks.QUEST_TASKS.register(eventBus);
		DaBoisMod.LOGGER.info("Quest tasks registered.");
	}
	
	// Break Blocks
	public static final RegistryObject<BreakBlocksQuestTask> BREAK_DIRT = QUEST_TASKS.register("break_dirt", () -> new BreakBlocksQuestTask(Blocks.DIRT, 30, 200));
}

 

For the most part, all of my other registries work, but my custom one causes the mod to fail to load:
 

  Reveal hidden contents

Am I doing something wrong? Is it not possible to use DeferredRegister with custom registries?

Edited by kaydogz
Posted

I believe it works if you create the registry statically instead of using the NewRegistry event, but that obviously goes against the intended workflow.

I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.

Posted

I actually managed to get DeferredRegister working with a custom registry (created in RegistryEvent.NewRegistry) by using a lazy-loading IForgeRegistry wrapper class. You can see my implementation here.

 

This is for 1.14.4, but I imagine it will work in 1.15.2 as well.

  • Like 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted
  On 5/7/2020 at 7:58 PM, Choonster said:

I actually managed to get DeferredRegister working with a custom registry (created in RegistryEvent.NewRegistry) by using a lazy-loading IForgeRegistry wrapper class. You can see my implementation here.

 

This is for 1.14.4, but I imagine it will work in 1.15.2 as well.

Expand  

This works perfectly, thanks! The only difference between 1.14.4 and 1.15.2 is that LazyLoadBase is now LazyValue.

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.