Skip to content

Commit

Permalink
allow inherit arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
sisby-folk committed Jul 9, 2023
1 parent c804fed commit 8993e93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public void generateItemSmithingData(@NotNull MinecraftServer server) {
Set<ArmorMaterial> armorMats = new HashSet<>(WARN_DEFAULT_MATERIAL_ARMOR.values());
TinkerersSmithing.LOGGER.warn("[Tinkerer's Smithing] Found {} unregistered armor materials with {} armor items: [{}] items: [{}]", armorMats.size(), WARN_DEFAULT_MATERIAL_ARMOR.size(), armorMats.stream().map(Object::toString).collect(Collectors.joining(", ")), WARN_DEFAULT_MATERIAL_ARMOR.entrySet().stream()
.collect(Collectors.groupingBy(Map.Entry::getValue, Collectors.mapping(Map.Entry::getKey, Collectors.toList()))).entrySet().stream() // Invert Map
.map(e -> "%s[%s]".formatted(e.getKey().toString(), e.getValue().stream().map(Identifier::toString).collect(Collectors.joining(", ")))).collect(Collectors.joining(", "))); // Stringify
.map(e -> "%s[%s]".formatted(e.getKey().getName(), e.getValue().stream().map(Identifier::toString).collect(Collectors.joining(", ")))).collect(Collectors.joining(", "))); // Stringify
}
if (!WARN_DEFAULT_MATERIAL_TOOL.isEmpty()) {
Set<ToolMaterial> toolMats = new HashSet<>(WARN_DEFAULT_MATERIAL_TOOL.values());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,18 @@ protected void apply(Map<Identifier, Collection<Pair<JsonElement, String>>> prep
for (Pair<JsonElement, String> entry : jsons) {
JsonObject baseObject = entry.getLeft().getAsJsonObject();
if (baseObject.has(KEY_INHERIT_FROM_ITEM)) {
Identifier inheritItemId = Identifier.tryParse(baseObject.get(KEY_INHERIT_FROM_ITEM).getAsString());
if (inheritItemId != null) {
Item inheritItem = getOrWarnItem(inheritItemId, id);
if (inheritItem != null) {
repairMaterials.add(getDefaultRepairIngredient(inheritItem));
Registry.ITEM.forEach(matchingItem -> {
if (matchingMaterials(inheritItem, matchingItem)) items.add(matchingItem);
});
baseObject.get(KEY_INHERIT_FROM_ITEM).getAsJsonArray().forEach(inheritElement -> {
Identifier inheritItemId = Identifier.tryParse(inheritElement.getAsString());
if (inheritItemId != null) {
Item inheritItem = getOrWarnItem(inheritItemId, id);
if (inheritItem != null) {
repairMaterials.add(getDefaultRepairIngredient(inheritItem));
Registry.ITEM.forEach(matchingItem -> {
if (matchingMaterials(inheritItem, matchingItem)) items.add(matchingItem);
});
}
}
}
});
}
if (baseObject.has(KEY_REPAIR_MATERIALS)) {
baseObject.get(KEY_REPAIR_MATERIALS).getAsJsonArray().forEach(jsonIngredient -> repairMaterials.add(Ingredient.fromJson(jsonIngredient)));
Expand All @@ -83,9 +85,7 @@ protected void apply(Map<Identifier, Collection<Pair<JsonElement, String>>> prep
baseObject.get(KEY_REMOVE_ITEM).getAsJsonArray().forEach(jsonItemId -> removeOrWarnItem(items, new Identifier(jsonItemId.getAsString()), id));
}
if (baseObject.has(KEY_UPGRADES_FROM)) {
baseObject.get(KEY_UPGRADES_FROM).getAsJsonArray().forEach(jsonMaterialId -> {
upgradeFromMap.computeIfAbsent(new Identifier(jsonMaterialId.getAsString()), k -> new ArrayList<>()).add(id);
});
baseObject.get(KEY_UPGRADES_FROM).getAsJsonArray().forEach(jsonMaterialId -> upgradeFromMap.computeIfAbsent(new Identifier(jsonMaterialId.getAsString()), k -> new ArrayList<>()).add(id));
}
if (baseObject.has(KEY_UPGRADES_TO)) {
baseObject.get(KEY_UPGRADES_TO).getAsJsonArray().forEach(jsonMaterialId -> upgradesTo.add(new Identifier(jsonMaterialId.getAsString())));
Expand Down

0 comments on commit 8993e93

Please sign in to comment.