Jump to content

[1.16.1] Registering a reloadListener


Tavi007

Recommended Posts

Hello,
I'm updating my mod to 1.16 and I can't find a way to add my reloadListener. Here is a code-snipped:


	@SubscribeEvent
	public void onServerAboutToStart(FMLServerAboutToStartEvent event)
	{
		// worked in 1.15.2
		//event.getServer().getResourcePacks().addReloadListener(DATAMANAGER);
		LOGGER.info("Elemental data registered.");	
	}

DATAMANGER is a class, that extends jsonReloadListener. I looked through the options of ResourcePacks, but I can't find a similar function to addReloadListener.

Link to comment
Share on other sites

MinecraftServer now uses a different system called DataPackRegistries to combine the reload and initialization of the listeners in one place. To access it, use:

((IReloadableResourceManager) event.getServer().getDataPackRegistries().func_240970_h_()).addReloadListener(listener);

Note that the cast is necessary as the function returns an IResourceManager compared to its stored IReloadableResourceManager variable.

Link to comment
Share on other sites

Thank you for your answer!

I got the code to compile and I assume my ReloadListener was added. However none of the data got loaded. I tested a little bit and noticed, that my implemented apply() function of DataManager is never called. Previously this function was called whenever I start playing a world or when I use the /reload-command . That's not happining now. Any idea, what the problem might be?

 

My repo if you want to have a deeper look:

https://github.com/Tavi007/ElementalCombat

Edited by Tavi007
Link to comment
Share on other sites

I bump this thread up, since I still have the same issue. The DataManager never calls the apply() function and therefor never loads the json files. I also look through the forge issue tracker to see, if it is a known issue, but it's not listed.

Link to comment
Share on other sites

  • 2 months later...

I don't know if you still having issues, but I do have a working re-loadable resource myself. I registered it slightly differently though:

public ModConst ()
{
  MinecraftForge.EVENT_BUS.addListener( this::addResourceReload );
}
	
private void addResourceReload ( final AddReloadListenerEvent event )
{
  event.addListener( new CustomReloadListener() );
}

For me, extending JsonReloadListener was all I needed.

I hope this helps someone.

Playing 1.16.2

Forge 33.0.5

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.