diff --git a/src/main/java/com/minelittlepony/unicopia/item/UItems.java b/src/main/java/com/minelittlepony/unicopia/item/UItems.java index 3d4f6429..1485dbd7 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/UItems.java +++ b/src/main/java/com/minelittlepony/unicopia/item/UItems.java @@ -57,6 +57,7 @@ public interface UItems { static void bootstrap() { Toxics.bootstrap(); + URecipes.bootstrap(); FabricItemGroupBuilder.create(new Identifier("unicopia", "items")).appendItems(list -> { list.addAll(VanillaOverrides.REGISTRY.stream().map(Item::getStackForRender).collect(Collectors.toList())); diff --git a/src/main/java/com/minelittlepony/unicopia/item/URecipes.java b/src/main/java/com/minelittlepony/unicopia/item/URecipes.java new file mode 100644 index 00000000..9ddef924 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/URecipes.java @@ -0,0 +1,28 @@ +package com.minelittlepony.unicopia.item; + +import net.minecraft.recipe.Recipe; +import net.minecraft.recipe.RecipeSerializer; +import net.minecraft.recipe.RecipeType; +import net.minecraft.recipe.ShapelessRecipe; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; + +public interface URecipes { + + RecipeSerializer ZAP_APPLE_SERIALIZER = register("crafting_zap_apple", new ZapAppleRecipe.Serializer()); + + static > RecipeType register(final String id) { + return Registry.register(Registry.RECIPE_TYPE, new Identifier("unicopia", id), new RecipeType() { + @Override + public String toString() { + return id; + } + }); + } + + static , T extends Recipe> S register(String id, S serializer) { + return Registry.register(Registry.RECIPE_SERIALIZER, new Identifier("unicopia", id), serializer); + } + + static void bootstrap() {} +} \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/item/ZapAppleRecipe.java b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleRecipe.java new file mode 100644 index 00000000..a90f2618 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/ZapAppleRecipe.java @@ -0,0 +1,65 @@ +package com.minelittlepony.unicopia.item; + +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; + +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.recipe.Ingredient; +import net.minecraft.recipe.ShapelessRecipe; +import net.minecraft.util.Identifier; +import net.minecraft.util.JsonHelper; +import net.minecraft.util.collection.DefaultedList; + +public class ZapAppleRecipe extends ShapelessRecipe { + + public ZapAppleRecipe(Identifier id, String group, ItemStack output, DefaultedList input) { + super(id, group, output, input); + } + + public static class Serializer extends ShapelessRecipe.Serializer { + @Override + public ShapelessRecipe read(Identifier identifier, JsonObject json) { + String group = JsonHelper.getString(json, "group", ""); + DefaultedList ingredients = getIngredients(JsonHelper.getArray(json, "ingredients")); + + if (ingredients.isEmpty()) { + throw new JsonParseException("No ingredients for shapeless recipe"); + } else if (ingredients.size() > 9) { + throw new JsonParseException("Too many ingredients for shapeless recipe"); + } + + ItemStack stack = UItems.ZAP_APPLE.getStackForRender(); + stack.getOrCreateTag().putString("appearance", JsonHelper.getString(json, "appearance")); + + return new ZapAppleRecipe(identifier, group, stack, ingredients); + } + + @Override + public ShapelessRecipe read(Identifier identifier, PacketByteBuf input) { + String group = input.readString(32767); + + DefaultedList ingredients = DefaultedList.ofSize(input.readVarInt(), Ingredient.EMPTY); + + for(int j = 0; j < ingredients.size(); ++j) { + ingredients.set(j, Ingredient.fromPacket(input)); + } + + return new ZapAppleRecipe(identifier, group, input.readItemStack(), ingredients); + } + + private static DefaultedList getIngredients(JsonArray json) { + DefaultedList defaultedList = DefaultedList.of(); + + for (int i = 0; i < json.size(); ++i) { + Ingredient ingredient = Ingredient.fromJson(json.get(i)); + if (!ingredient.isEmpty()) { + defaultedList.add(ingredient); + } + } + + return defaultedList; + } + } +} diff --git a/src/main/resources/data/unicopia/recipes/cooked_zap_apple.json b/src/main/resources/data/unicopia/recipes/cooked_zap_apple.json new file mode 100644 index 00000000..4a37347e --- /dev/null +++ b/src/main/resources/data/unicopia/recipes/cooked_zap_apple.json @@ -0,0 +1,9 @@ +{ + "type": "smelting", + "ingredient": { + "item": "unicopia:zap_apple" + }, + "result": "unicopia:cooked_zap_apple", + "experience": 0.2, + "cookingtime": 430 +} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/recipes/trick_green_apple.json b/src/main/resources/data/unicopia/recipes/trick_green_apple.json new file mode 100644 index 00000000..b914d534 --- /dev/null +++ b/src/main/resources/data/unicopia/recipes/trick_green_apple.json @@ -0,0 +1,8 @@ +{ + "type": "unicopia:crafting_zap_apple", + "ingredients": [ + { "item": "unicopia:zap_apple" }, + { "item": "minecraft:green_dye" } + ], + "appearance": "unicopia:green_apple" +} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/recipes/trick_red_apple.json b/src/main/resources/data/unicopia/recipes/trick_red_apple.json new file mode 100644 index 00000000..cd5095ea --- /dev/null +++ b/src/main/resources/data/unicopia/recipes/trick_red_apple.json @@ -0,0 +1,8 @@ +{ + "type": "unicopia:crafting_zap_apple", + "ingredients": [ + { "item": "unicopia:zap_apple" }, + { "item": "minecraft:red_dye" } + ], + "appearance": "minecraft:apple" +} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/recipes/trick_sour_apple.json b/src/main/resources/data/unicopia/recipes/trick_sour_apple.json new file mode 100644 index 00000000..f5be4b69 --- /dev/null +++ b/src/main/resources/data/unicopia/recipes/trick_sour_apple.json @@ -0,0 +1,8 @@ +{ + "type": "unicopia:crafting_zap_apple", + "ingredients": [ + { "item": "unicopia:zap_apple" }, + { "item": "minecraft:yellow_dye" } + ], + "appearance": "unicopia:sour_apple" +} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/recipes/trick_sweet_apple.json b/src/main/resources/data/unicopia/recipes/trick_sweet_apple.json new file mode 100644 index 00000000..48794044 --- /dev/null +++ b/src/main/resources/data/unicopia/recipes/trick_sweet_apple.json @@ -0,0 +1,8 @@ +{ + "type": "unicopia:crafting_zap_apple", + "ingredients": [ + { "item": "unicopia:zap_apple" }, + { "item": "minecraft:orange_dye" } + ], + "appearance": "unicopia:sweet_apple" +} \ No newline at end of file diff --git a/src/main/resources/data/unicopia/recipes/trick_zap_apple.json b/src/main/resources/data/unicopia/recipes/trick_zap_apple.json new file mode 100644 index 00000000..38555616 --- /dev/null +++ b/src/main/resources/data/unicopia/recipes/trick_zap_apple.json @@ -0,0 +1,8 @@ +{ + "type": "unicopia:crafting_zap_apple", + "ingredients": [ + { "item": "unicopia:zap_apple" }, + { "item": "minecraft:rotten_flesh" } + ], + "appearance": "unicopia:cooked_zap_apple" +} \ No newline at end of file