package net.minecraft.world.item.crafting;

import net.minecraft.network.FriendlyByteBuf;
import com.google.gson.JsonElement;
import net.minecraft.util.GsonHelper;
import com.google.gson.JsonObject;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.Level;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.Container;

public class UpgradeRecipe implements Recipe<Container> {
    private final Ingredient base;
    private final Ingredient addition;
    private final ItemStack result;
    private final ResourceLocation id;
    
    public UpgradeRecipe(final ResourceLocation uh, final Ingredient bmr2, final Ingredient bmr3, final ItemStack bki) {
        this.id = uh;
        this.base = bmr2;
        this.addition = bmr3;
        this.result = bki;
    }
    
    @Override
    public boolean matches(final Container amz, final Level bqb) {
        return this.base.test(amz.getItem(0)) && this.addition.test(amz.getItem(1));
    }
    
    @Override
    public ItemStack assemble(final Container amz) {
        final ItemStack bki3 = this.result.copy();
        final CompoundTag le4 = amz.getItem(0).getTag();
        if (le4 != null) {
            bki3.setTag(le4.copy());
        }
        return bki3;
    }
    
    @Override
    public boolean canCraftInDimensions(final int integer1, final int integer2) {
        return integer1 * integer2 >= 2;
    }
    
    @Override
    public ItemStack getResultItem() {
        return this.result;
    }
    
    public boolean isAdditionIngredient(final ItemStack bki) {
        return this.addition.test(bki);
    }
    
    @Override
    public ItemStack getToastSymbol() {
        return new ItemStack(Blocks.SMITHING_TABLE);
    }
    
    @Override
    public ResourceLocation getId() {
        return this.id;
    }
    
    @Override
    public RecipeSerializer<?> getSerializer() {
        return RecipeSerializer.SMITHING;
    }
    
    @Override
    public RecipeType<?> getType() {
        return RecipeType.SMITHING;
    }
    
    public static class Serializer implements RecipeSerializer<UpgradeRecipe> {
        @Override
        public UpgradeRecipe fromJson(final ResourceLocation uh, final JsonObject jsonObject) {
            final Ingredient bmr4 = Ingredient.fromJson(GsonHelper.getAsJsonObject(jsonObject, "base"));
            final Ingredient bmr5 = Ingredient.fromJson(GsonHelper.getAsJsonObject(jsonObject, "addition"));
            final ItemStack bki6 = ShapedRecipe.itemFromJson(GsonHelper.getAsJsonObject(jsonObject, "result"));
            return new UpgradeRecipe(uh, bmr4, bmr5, bki6);
        }
        
        @Override
        public UpgradeRecipe fromNetwork(final ResourceLocation uh, final FriendlyByteBuf mg) {
            final Ingredient bmr4 = Ingredient.fromNetwork(mg);
            final Ingredient bmr5 = Ingredient.fromNetwork(mg);
            final ItemStack bki6 = mg.readItem();
            return new UpgradeRecipe(uh, bmr4, bmr5, bki6);
        }
        
        @Override
        public void toNetwork(final FriendlyByteBuf mg, final UpgradeRecipe bnl) {
            bnl.base.toNetwork(mg);
            bnl.addition.toNetwork(mg);
            mg.writeItem(bnl.result);
        }
    }
}
