Fix vanilla trying to load the constants json as an recipe. Closes #5388
Force constant names to use namespace of their json file. To prevent conflicts.
This commit is contained in:
parent
a15c4dc9b0
commit
7b867d0069
2 changed files with 18 additions and 8 deletions
|
@ -9,14 +9,18 @@
|
|||
private static final Logger field_199521_c = LogManager.getLogger();
|
||||
public static final int field_199519_a = "recipes/".length();
|
||||
public static final int field_199520_b = ".json".length();
|
||||
@@ -36,6 +36,7 @@
|
||||
@@ -36,9 +36,10 @@
|
||||
Gson gson = (new GsonBuilder()).setPrettyPrinting().disableHtmlEscaping().create();
|
||||
this.field_199523_e = false;
|
||||
this.field_199522_d.clear();
|
||||
+ super.func_195410_a(p_195410_1_);
|
||||
|
||||
for(ResourceLocation resourcelocation : p_195410_1_.func_199003_a("recipes", (p_199516_0_) -> {
|
||||
return p_199516_0_.endsWith(".json");
|
||||
- return p_199516_0_.endsWith(".json");
|
||||
+ return p_199516_0_.endsWith(".json") && !p_199516_0_.startsWith("_"); //Forge filter anything beginning with "_" as it's used for metadata.
|
||||
})) {
|
||||
String s = resourcelocation.func_110623_a();
|
||||
ResourceLocation resourcelocation1 = new ResourceLocation(resourcelocation.func_110624_b(), s.substring(field_199519_a, s.length() - field_199520_b));
|
||||
@@ -47,6 +48,8 @@
|
||||
JsonObject jsonobject = (JsonObject)JsonUtils.func_188178_a(gson, IOUtils.toString(iresource.func_199027_b(), StandardCharsets.UTF_8), JsonObject.class);
|
||||
if (jsonobject == null) {
|
||||
|
|
|
@ -291,7 +291,7 @@ public class CraftingHelper
|
|||
}
|
||||
|
||||
public static void reloadConstants(IResourceManager manager) {
|
||||
Map<ResourceLocation, IItemList> ret = new HashMap<>();
|
||||
Map<ResourceLocation, IItemList> tmp = new HashMap<>();
|
||||
for(ResourceLocation key : manager.getAllResourceLocations("recipes", filename -> filename.equals("_constants.json")))
|
||||
{
|
||||
String path = key.getPath();
|
||||
|
@ -304,11 +304,17 @@ public class CraftingHelper
|
|||
for (int x = 0; x < elements.length; x++)
|
||||
{
|
||||
JsonObject json = elements[x];
|
||||
//Force namespace to the directory that this constants file is in, to prevent modders from overriding other's sneakily
|
||||
//TODO: Move back to a resource pack/mod specific constant list?
|
||||
ResourceLocation name = json.has("name") ? new ResourceLocation(JsonUtils.getString(json, "name")) : null;
|
||||
if (name != null)
|
||||
name = new ResourceLocation(key.getNamespace(), name.getPath());
|
||||
|
||||
if (json == null || json.size() == 0)
|
||||
LOGGER.error(CRAFTHELPER, "Couldn't load constant #{} from {} as it's null or empty", x, key);
|
||||
else if (json.has("conditions") && !processConditions(JsonUtils.getJsonArray(json, "conditions")))
|
||||
LOGGER.info(CRAFTHELPER, "Skipping loading constant #{} from {} as it's conditions were not met", x, key);
|
||||
else if (!json.has("name"))
|
||||
else if (name == null)
|
||||
LOGGER.error(CRAFTHELPER, "Couldn't load constant #{} from {} as it's missing `name`", x, key);
|
||||
else if (json.has("items"))
|
||||
{
|
||||
|
@ -325,12 +331,12 @@ public class CraftingHelper
|
|||
}
|
||||
}
|
||||
if (!items.isEmpty())
|
||||
ret.put(new ResourceLocation(JsonUtils.getString(json, "name")), new StackList(items));
|
||||
tmp.put(name, new StackList(items));
|
||||
}
|
||||
else if (json.has("tag"))
|
||||
ret.put(new ResourceLocation(JsonUtils.getString(json, "name")), Ingredient.deserializeItemList(json));
|
||||
tmp.put(name, Ingredient.deserializeItemList(json));
|
||||
else if (json.has("item"))
|
||||
ret.put(new ResourceLocation(JsonUtils.getString(json, "name")), new StackList(Lists.newArrayList(getItemStack(JsonUtils.getJsonObject(json, "item"), true))));
|
||||
tmp.put(name, new StackList(Lists.newArrayList(getItemStack(JsonUtils.getJsonObject(json, "item"), true))));
|
||||
else
|
||||
LOGGER.error(CRAFTHELPER, "Couldn't load constant #{} from {} as it's missing `item` or `items` element", x, key);
|
||||
}
|
||||
|
@ -345,6 +351,6 @@ public class CraftingHelper
|
|||
LOGGER.error(CRAFTHELPER, "Couldn't read constants from {}", key, e);
|
||||
}
|
||||
}
|
||||
constants = ret;
|
||||
constants = tmp;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue