Fix loading recipe jsons from jar files.

This commit is contained in:
LexManos 2017-06-19 17:18:53 -07:00
parent f7831fbe99
commit a2749e4507
1 changed files with 11 additions and 12 deletions

View File

@ -606,16 +606,15 @@ public class CraftingHelper {
try try
{ {
JsonContext ctx = new JsonContext(mod.getModId()); JsonContext ctx = new JsonContext(mod.getModId());
URI source = mod.getSource().toURI();
Path fPath = null; Path fPath = null;
if ("jar".equals(source.getScheme())) if (mod.getSource().isFile())
{ {
fs = FileSystems.newFileSystem(source, Maps.newHashMap()); fs = FileSystems.newFileSystem(mod.getSource().toPath(), null);
fPath = fs.getPath("/assets/" + ctx.getModId() + "/recipes/_factories.json"); fPath = fs.getPath("/assets/" + ctx.getModId() + "/recipes/_factories.json");
} }
else if ("file".equals(source.getScheme())) else if (mod.getSource().isDirectory())
{ {
fPath = Paths.get(source).resolve("assets/" + ctx.getModId() + "/recipes/_factories.json"); fPath = mod.getSource().toPath().resolve("assets/" + ctx.getModId() + "/recipes/_factories.json");
} }
if (fPath != null && Files.exists(fPath)) if (fPath != null && Files.exists(fPath))
{ {
@ -642,14 +641,14 @@ public class CraftingHelper {
try try
{ {
JsonContext ctx = new JsonContext(mod.getModId()); JsonContext ctx = new JsonContext(mod.getModId());
URI source = mod.getSource().toURI(); File source = mod.getSource();
if ("minecraft".equals(mod.getModId()) && DEBUG_LOAD_MINECRAFT) if ("minecraft".equals(mod.getModId()) && DEBUG_LOAD_MINECRAFT)
{ {
try try
{ {
source = CraftingManager.class.getResource("/assets/.mcassetsroot").toURI(); URI tmp = CraftingManager.class.getResource("/assets/.mcassetsroot").toURI();
source = source.resolve(".."); source = new File(tmp.resolve("..").getPath());
} }
catch (URISyntaxException e) catch (URISyntaxException e)
{ {
@ -659,11 +658,11 @@ public class CraftingHelper {
} }
Path root = null; Path root = null;
if ("jar".equals(source.getScheme())) if (source.isFile())
{ {
try try
{ {
fs = FileSystems.newFileSystem(source, Maps.newHashMap()); fs = FileSystems.newFileSystem(source.toPath(), null);
root = fs.getPath("/assets/" + ctx.getModId() + "/recipes/"); root = fs.getPath("/assets/" + ctx.getModId() + "/recipes/");
} }
catch (IOException e) catch (IOException e)
@ -672,9 +671,9 @@ public class CraftingHelper {
return false; return false;
} }
} }
else if ("file".equals(source.getScheme())) else if (source.isDirectory())
{ {
root = Paths.get(source).resolve("assets/" + ctx.getModId() + "/recipes/"); root = source.toPath().resolve("assets/" + ctx.getModId() + "/recipes/");
} }
if (root == null || !Files.exists(root)) if (root == null || !Files.exists(root))