Tech Reborn

Tech Reborn

34M Downloads

Recipe viewers fail to load Fluid Generator recipes on server

Timardo opened this issue ยท 4 comments

commented

Describe the bug
When joining a server with freshly started Minecraft client, recipe viewers (REI and EMI with addon tested) fail with an NPE when trying to get Fluid Generator recipes.

Steps to Reproduce

  • Download the newest version of TechReborn (5.8.13) and REI for Minecraft 1.20.1 including all dependencies
  • Start a server with these mods
  • Start a client with these mods
  • Join the server without joining a singleplayer world first
  • An error occurs on client failing to register fluid generator recipes

Environment:

  • Minecraft: 1.20.1 (other versions might have this problem as well, I have not tested them or looked at their code)
  • Mod Loader: Fabric

Logs
The relevant part:

[16:18:11] [REI-ReloadPlugins/ERROR]: [REI] ReiPlugin of ReiPlugin [techreborn] plugin failed to reloadable-plugin/DisplayRegistryImpl/!
java.lang.NullPointerException: Cannot invoke "techreborn.api.generator.FluidGeneratorRecipeList.getRecipes()" because the return value of "techreborn.api.generator.GeneratorRecipeHelper.getFluidRecipesForGenerator(techreborn.api.generator.EFluidGenerator)" is null
	at techreborn.client.compat.rei.ReiPlugin.registerFluidGeneratorDisplays(ReiPlugin.java:248) ~[TechReborn-5.8.13.jar:?]
	at techreborn.client.compat.rei.ReiPlugin.registerDisplays(ReiPlugin.java:196) ~[TechReborn-5.8.13.jar:?]
	at me.shedaniel.rei.impl.client.registry.display.DisplayRegistryImpl.acceptPlugin(DisplayRegistryImpl.java:63) ~[RoughlyEnoughItems-12.1.785-fabric.jar:?]
	at me.shedaniel.rei.impl.client.registry.display.DisplayRegistryImpl.acceptPlugin(DisplayRegistryImpl.java:53) ~[RoughlyEnoughItems-12.1.785-fabric.jar:?]
	at me.shedaniel.rei.api.common.registry.Reloadable.acceptPlugin(Reloadable.java:78) ~[RoughlyEnoughItems-12.1.785-fabric.jar:?]
	at me.shedaniel.rei.impl.common.plugins.PluginManagerImpl.lambda$reload$12(PluginManagerImpl.java:430) ~[RoughlyEnoughItems-12.1.785-fabric.jar:?]
	at me.shedaniel.rei.impl.common.plugins.PluginManagerImpl.lambda$pluginSection$4(PluginManagerImpl.java:193) ~[RoughlyEnoughItems-12.1.785-fabric.jar:?]
	at me.shedaniel.rei.impl.common.plugins.PluginManagerImpl.lambda$reload$13(PluginManagerImpl.java:420) ~[RoughlyEnoughItems-12.1.785-fabric.jar:?]
	at me.shedaniel.rei.impl.common.plugins.PluginManagerImpl.pluginSection(PluginManagerImpl.java:191) ~[RoughlyEnoughItems-12.1.785-fabric.jar:?]
	at me.shedaniel.rei.impl.common.plugins.PluginManagerImpl.reload(PluginManagerImpl.java:418) ~[RoughlyEnoughItems-12.1.785-fabric.jar:?]
	at me.shedaniel.rei.api.common.plugins.PluginView$1.reload(PluginView.java:71) ~[RoughlyEnoughItems-12.1.785-fabric.jar:?]
	at me.shedaniel.rei.impl.common.plugins.ReloadManagerImpl.reloadPlugins0(ReloadManagerImpl.java:155) ~[RoughlyEnoughItems-12.1.785-fabric.jar:?]
	at me.shedaniel.rei.impl.common.plugins.ReloadManagerImpl.reloadPlugins0(ReloadManagerImpl.java:144) ~[RoughlyEnoughItems-12.1.785-fabric.jar:?]
	at me.shedaniel.rei.impl.common.plugins.ReloadManagerImpl.lambda$reloadPlugins$7(ReloadManagerImpl.java:122) ~[RoughlyEnoughItems-12.1.785-fabric.jar:?]
	at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804) ~[?:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
	at java.lang.Thread.run(Thread.java:842) ~[?:?]

Full log: https://pastebin.com/8rSCj3ZB

Additional context
Probably caused by changes in 4c7e8ce. Joining a singleplayer world before joining a server populates the map that contains the Fluid Generator recipes as they are added only on server start. After that joining a server has no issues.

ServerLifecycleEvents.SERVER_STARTING.register(server -> {
for (EFluidGenerator generator : EFluidGenerator.values()) {
FluidGeneratorRecipeList list = GeneratorRecipeHelper.fluidRecipes.computeIfAbsent(generator, g -> new FluidGeneratorRecipeList());
server.getRecipeManager().getAllOfType(generator.getType()).values().forEach(list::addRecipe);
}
});

The NPE is caused by this line:

GeneratorRecipeHelper.getFluidRecipesForGenerator(generator).getRecipes().forEach(recipe ->

The solution might be to register recipes on world join instead of server start. However I'm not skilled enough to know if that is correct or even viable.

commented

Thank you for such quick resolution. It seems to have fixed the problem with EMI recipe viewer as well.

commented

Yes, the SERVER_STARTING event cannot be executed when joining a proprietary server.
What event do you suggest to use? To be able to call it after the third party recipe registration is completed.

commented

Imaget
I can update the REI plugin to support viewing recipes, but if other recipe viewers use GeneratorRecipeHelper, the corresponding json recipe needs to be added.

commented

Thanks for reporting this bug.
You can download the latest version to fix it.