Guest User

Untitled

a guest
Jun 19th, 2021
65
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.kup.burgercraft.crafting.recipe;
  2.  
  3. import com.google.gson.JsonObject;
  4. import com.kup.burgercraft.setup.ModRecipes;
  5. import net.minecraft.inventory.IInventory;
  6. import net.minecraft.item.ItemStack;
  7. import net.minecraft.item.crafting.*;
  8. import net.minecraft.network.PacketBuffer;
  9. import net.minecraft.util.JSONUtils;
  10. import net.minecraft.util.ResourceLocation;
  11. import net.minecraft.world.World;
  12. import net.minecraftforge.registries.ForgeRegistries;
  13. import net.minecraftforge.registries.ForgeRegistryEntry;
  14.  
  15. import javax.annotation.Nullable;
  16.  
  17. public class MeatGrindingRecipe extends SingleItemRecipe{
  18.     public MeatGrindingRecipe(ResourceLocation recipeId,
  19.                               Ingredient ingredient,
  20.                               ItemStack result) {
  21.         super(ModRecipes.Types.MEAT_GRINDING_TYPE, ModRecipes.Serializers.MEAT_GRINDING.get(), recipeId, "", ingredient, result);
  22.     }
  23.  
  24.     @Override
  25.     public boolean matches(IInventory inventory, World world) {
  26.         return this.ingredient.test(inventory.getItem(0));
  27.     }
  28.  
  29.  
  30.     public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<MeatGrindingRecipe> {
  31.         @Override
  32.         public MeatGrindingRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
  33.             Ingredient ingredient = Ingredient.fromJson(json.get("ingredient"));
  34.             ResourceLocation itemId = new ResourceLocation(JSONUtils.getAsString(json, "result"));
  35.             int count = JSONUtils.getAsInt(json, "count", 1);
  36.  
  37.             ItemStack result = new ItemStack(ForgeRegistries.ITEMS.getValue(itemId), count);
  38.  
  39.             return new MeatGrindingRecipe(recipeId, ingredient, result);
  40.         }
  41.  
  42.         @Nullable
  43.         @Override
  44.         public MeatGrindingRecipe fromNetwork(ResourceLocation recipeId, PacketBuffer buffer) {
  45.             Ingredient ingredient = Ingredient.fromNetwork(buffer);
  46.             ItemStack result = buffer.readItem();
  47.             return new MeatGrindingRecipe(recipeId, ingredient, result);
  48.         }
  49.  
  50.         @Override
  51.         public void toNetwork(PacketBuffer buffer, MeatGrindingRecipe recipe) {
  52.             recipe.ingredient.toNetwork(buffer);
  53.             buffer.writeItem(recipe.result);
  54.         }
  55.     }
  56. }
RAW Paste Data