Minecraftforge: Recipes not loaded from jars

Created on 17 Jun 2017  路  8Comments  路  Source: MinecraftForge/MinecraftForge

It seems the loading mechanism for loading JSON recipes is currently broken. JSON recipes work just fine in dev, but as soon as you try running it from a jar, the recipes no longer get loaded.

This issue has been replicated with multiple mods available on curseforge.

I was able to track down the issue to the CraftingHelper.loadRecipes() method. It seems this check always fails - even if its a jar file.

Tested with Forge 2333

example

1.12 Bug

All 8 comments

I toyed around with the code a bit and I was able to load the jar, recipes work!
The issue is the URI source = mod.getSource().toURI(); in https://github.com/MinecraftForge/MinecraftForge/blob/1.12.x/src/main/java/net/minecraftforge/common/crafting/CraftingHelper.java#L645
This always returns an URI with the file:/ scheme.
I simply added the following code afterwards, the jar is loaded just fine, recipes are working:

if(mod.getSource().exists() && mod.getSource().toString().endsWith(".jar"))
    source = new URI("jar:" + source);

Since I'm not sure if this is the proper approach to fix this, I wont do a PR. Maybe someone else can pick this up tho :)

yup, looks like File.toURI() is defined to always return a file:// uri.

javadoc

Alternative patch that also appears to work (no idea about dev tho, don't know how to test that) would be to add this before the if ("jar"..., feels somewhat hacky due to the getClass(), though:


            if (mod.getMod() != null && mod.getMod().getClass().getResource("/assets/" + ctx.getModId() + "/recipes/") != null)
            {
                try
                {
                    source = mod.getMod().getClass().getResource("/assets/" + ctx.getModId() + "/recipes/").toURI();
                }
                catch (URISyntaxException e)
                {
                    FMLLog.log(Level.ERROR, e, "Error accessing mod jar: " + e.toString());
                    return false;
                }
            }

I personally prefer the former :P

Humm interesting, oh well.
I was just trying to mimic vanilla's loading.
The solution is simple, mod.getSource().isFile()/isDirectory() like everything else does.

the subtle difference is that vanilla uses Class.getResource().toURI which is URL -> URI. the call being made here is File -> URI

any way around this until patch gets merged?

Was this page helpful?
0 / 5 - 0 ratings