[Feature] Allow nbt-Tag for Input Slot in Infusion Recipe .json-Files (#83)

This commit is contained in:
Frank 2022-11-18 21:29:30 +01:00
parent 0ef3b7e11e
commit 4715ea0df8

View file

@ -216,7 +216,18 @@ public class InfusionRecipe implements Recipe<InfusionRitual>, UnknownReceipBook
@Override @Override
public InfusionRecipe fromJson(ResourceLocation id, JsonObject json) { public InfusionRecipe fromJson(ResourceLocation id, JsonObject json) {
InfusionRecipe recipe = new InfusionRecipe(id); InfusionRecipe recipe = new InfusionRecipe(id);
recipe.input = Ingredient.fromJson(json.get("input")); JsonObject inputObject = GsonHelper.getAsJsonObject(json, "input");
recipe.input = Ingredient.fromJson(inputObject);
if (inputObject.has("nbt") && !recipe.input.isEmpty()) {
try {
String nbtData = GsonHelper.getAsString(inputObject, "nbt");
CompoundTag nbt = TagParser.parseTag(nbtData);
recipe.input.getItems()[0].setTag(nbt);
} catch (CommandSyntaxException ex) {
BetterEnd.LOGGER.warning("Error parse nbt data for input.", ex);
}
}
JsonObject result = GsonHelper.getAsJsonObject(json, "result"); JsonObject result = GsonHelper.getAsJsonObject(json, "result");
recipe.output = ItemUtil.fromJsonRecipe(result); recipe.output = ItemUtil.fromJsonRecipe(result);
if (recipe.output == null) { if (recipe.output == null) {