Advertisement
Scouter456

Untitled

Jun 26th, 2023
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.52 KB | None | 0 0
  1. public class AnalyzerRecipe implements Recipe<SimpleContainer> {
  2.  
  3.  
  4.     private final ResourceLocation id;
  5.     //private final ResourceLocation output;
  6.     private final NonNullList<Ingredient> recipeItems;
  7.  
  8.     public AnalyzerRecipe(ResourceLocation id,
  9.                           NonNullList<Ingredient> recipeItems) {
  10.         this.id = id;
  11.         //this.output = output;
  12.         this.recipeItems = recipeItems;
  13.     }
  14.  
  15.     @Override
  16.     public boolean matches(SimpleContainer pContainer, Level pLevel) {
  17.         return !recipeItems.isEmpty() && recipeItems.get(0).test(pContainer.getItem(1));
  18.     }
  19.  
  20.     @Override
  21.     public ItemStack assemble(SimpleContainer pContainer) {
  22.         //This does nothing
  23.         return ItemStack.EMPTY;
  24.     }
  25.  
  26.  
  27.  
  28.     @Override
  29.     public boolean canCraftInDimensions(int pWidth, int pHeight) {
  30.         return true;
  31.     }
  32.  
  33.     @Override
  34.     public ItemStack getResultItem() {
  35.         return ItemStack.EMPTY;
  36.     }
  37.  
  38.     @Override
  39.     public ResourceLocation getId() {
  40.         return id;
  41.     }
  42.  
  43.     @Override
  44.     public RecipeSerializer<?> getSerializer() {
  45.         return Serializer.INSTANCE;
  46.     }
  47.  
  48.     @Override
  49.     public RecipeType<?> getType() {
  50.         return Type.INSTANCE;
  51.     }
  52.  
  53.  
  54.     public static class Type implements RecipeType<AnalyzerRecipe> {
  55.         private Type() { }
  56.         public static final Type INSTANCE = new Type();
  57.     }
  58.  
  59.     @Override
  60.     public NonNullList<Ingredient> getIngredients() {
  61.         return recipeItems;
  62.     }
  63.  
  64.     public static class Serializer implements RecipeSerializer<AnalyzerRecipe> {
  65.         public static final Serializer INSTANCE = new Serializer();
  66.         public static final ResourceLocation ID = new ResourceLocation(UnusualPrehistory.MODID,"analyzing");
  67.  
  68.         @Override
  69.         public AnalyzerRecipe fromJson(ResourceLocation id, JsonObject json) {
  70.             JsonArray ingredients = GsonHelper.getAsJsonArray(json, "ingredients");
  71.             NonNullList<Ingredient> inputs = NonNullList.withSize(1, Ingredient.EMPTY);
  72.  
  73.             for (int i = 0; i < inputs.size(); i++) {
  74.                 inputs.set(i, Ingredient.fromJson(ingredients.get(i)));
  75.             }
  76.  
  77.             return new AnalyzerRecipe(id, inputs);
  78.         }
  79.  
  80.         @Override
  81.         public AnalyzerRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
  82.             NonNullList<Ingredient> inputs = NonNullList.withSize(buf.readInt(), Ingredient.EMPTY);
  83.  
  84.             for (int i = 0; i < inputs.size(); i++) {
  85.                 inputs.set(i, Ingredient.fromNetwork(buf));
  86.             }
  87.  
  88.             ResourceLocation output = buf.readResourceLocation();
  89.             return new AnalyzerRecipe(id, inputs);
  90.         }
  91.  
  92.         @Override
  93.         public void toNetwork(FriendlyByteBuf buf, AnalyzerRecipe recipe) {
  94.             buf.writeInt(recipe.getIngredients().size());
  95.             for (Ingredient ing : recipe.getIngredients()) {
  96.                 ing.toNetwork(buf);
  97.             }
  98.         }
  99.  
  100.  
  101.         public RecipeSerializer<?> setRegistryName(ResourceLocation name) {
  102.             return INSTANCE;
  103.         }
  104.  
  105.  
  106.         public ResourceLocation getRegistryName() {
  107.             return ID;
  108.         }
  109.  
  110.  
  111.         public Class<RecipeSerializer<?>> getRegistryType() {
  112.             return Serializer.castClass(RecipeSerializer.class);
  113.         }
  114.  
  115.         @SuppressWarnings("unchecked") // Need this wrapper, because generics
  116.         private static <G> Class<G> castClass(Class<?> cls) {
  117.             return (Class<G>)cls;
  118.         }
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement