From 9c35df02a14fd0c5b850560081f708d71fc20f9d Mon Sep 17 00:00:00 2001 From: Abbie Date: Mon, 23 Dec 2024 16:02:29 +0000 Subject: [PATCH] deserialize plain arrays as list ingredients --- .../emi/registry/EmiIngredientSerializers.java | 2 ++ .../ListEmiIngredientSerializer.java | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/xplat/src/main/java/dev/emi/emi/registry/EmiIngredientSerializers.java b/xplat/src/main/java/dev/emi/emi/registry/EmiIngredientSerializers.java index 6c2bc4b9..af9b6f42 100644 --- a/xplat/src/main/java/dev/emi/emi/registry/EmiIngredientSerializers.java +++ b/xplat/src/main/java/dev/emi/emi/registry/EmiIngredientSerializers.java @@ -64,6 +64,8 @@ public static EmiIngredient deserialize(JsonElement element) { } } type = json.get("type").getAsString(); + } else if (element.isJsonArray()) { + type = "list"; } else { String[] split = element.getAsString().split(":"); type = split[0]; diff --git a/xplat/src/main/java/dev/emi/emi/stack/serializer/ListEmiIngredientSerializer.java b/xplat/src/main/java/dev/emi/emi/stack/serializer/ListEmiIngredientSerializer.java index 780fc312..bc1f6c07 100644 --- a/xplat/src/main/java/dev/emi/emi/stack/serializer/ListEmiIngredientSerializer.java +++ b/xplat/src/main/java/dev/emi/emi/stack/serializer/ListEmiIngredientSerializer.java @@ -22,13 +22,21 @@ public String getType() { @Override public EmiIngredient deserialize(JsonElement element) { - if (!element.isJsonObject()) { + JsonArray ingredientsArray; + long amount; + float chance; + if (element.isJsonObject()) { + JsonObject json = element.getAsJsonObject(); + amount = JsonHelper.getLong(json, "amount", 1); + chance = JsonHelper.getFloat(json, "chance", 1); + ingredientsArray = JsonHelper.getArray(json, "ingredients"); + } else if (element.isJsonArray()) { + ingredientsArray = element.getAsJsonArray(); + amount = 1; + chance = 1; + } else { return EmiStack.EMPTY; } - JsonObject json = element.getAsJsonObject(); - long amount = JsonHelper.getLong(json, "amount", 1); - float chance = JsonHelper.getFloat(json, "chance", 1); - JsonArray ingredientsArray = JsonHelper.getArray(json, "ingredients"); List ingredients = new ArrayList<>(); for (JsonElement ingredientElement : ingredientsArray) { ingredients.add(EmiIngredientSerializers.deserialize(ingredientElement));