blob: d94222cfba176807e822b0f474d4a2c12fb418cf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package lv.enes.mc.eris_alchemy.recipe;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import lv.enes.mc.eris_alchemy.utils.IngredientProvider;
import net.minecraft.world.item.crafting.Ingredient;
import java.lang.reflect.Type;
import java.util.function.Supplier;
public record BannedRecipe(Supplier<Ingredient> input, Supplier<Ingredient> output) {
public static BannedRecipe deserialize(JsonElement el) {
if (el.isJsonPrimitive() && el.getAsJsonPrimitive().isString()) {
return deserialize(el.getAsString());
} else {
// TODO: Verbose object representation
throw new JsonParseException("Banned recipes should all be strings");
}
}
public static BannedRecipe deserialize(String str) {
var split = str.indexOf("->");
var input = IngredientProvider.deserialize(str.substring(0, split).trim());
var output = IngredientProvider.deserialize(str.substring(split + 2).trim());
return new BannedRecipe(input, output);
}
public static class Deserializer implements JsonDeserializer<BannedRecipe> {
@Override
public BannedRecipe deserialize(
JsonElement el,
Type t,
JsonDeserializationContext ctx
) throws JsonParseException {
return BannedRecipe.deserialize(el);
}
}
}
|