Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MyRecipeSerializer implements RecipeSerializer<MyRecipe> {
- private MyRecipeSerializer() {}
- public static final MyRecipeSerializer INSTANCE = new <MyRecipeSerializer();
- public static final Identifier ID = new Identifier("modid:my_recipe");
- @Override
- public MyRecipe read(Identifier id, JsonObject json) {
- MyRecipeJsonFormat recipeJson = new Gson().fromJson(json, MyRecipeJsonFormat.class);
- if(recipeJson.input == null || recipeJson.outputItem == null) { throw new JsonSyntaxException("Missing Attributes in Recipe!"); }
- Ingredient input = Ingredient.fromJson(recipeJson.getInput());
- Item outputItem = Registry.ITEM.getOrEmpty(new Identifier(recipeJson.getOutputItemId())).orElseThrow(() -> new JsonSyntaxException("The Item " + recipeJson.outputItem + " does not exist!"));
- ItemStack outputStack = new ItemStack(outputItem, recipeJson.getOutputCount());
- return new MyRecipe(input, outputStack, id);
- }
- @Override
- public MyRecipe read(Identifier id, PacketByteBuf buf) {
- Ingredient input = Ingredient.fromPacket(buf);
- ItemStack output = buf.readItemStack();
- return new MyRecipe(input, output, id);
- }
- @Override
- public void write(PacketByteBuf buf, MyRecipe recipe) {
- recipe.getInput().write(buf);
- buf.writeItemStack(recipe.getOutput());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement