package net.minecraft.world.item.crafting;

import net.minecraft.world.Container;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.DyeItem;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.ShulkerBoxBlock;
import net.minecraft.world.level.Level;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.resources.ResourceLocation;

public class ShulkerBoxColoring extends CustomRecipe {
    public ShulkerBoxColoring(final ResourceLocation uh) {
        super(uh);
    }
    
    @Override
    public boolean matches(final CraftingContainer bgu, final Level bqb) {
        int integer4 = 0;
        int integer5 = 0;
        for (int integer6 = 0; integer6 < bgu.getContainerSize(); ++integer6) {
            final ItemStack bki7 = bgu.getItem(integer6);
            if (!bki7.isEmpty()) {
                if (Block.byItem(bki7.getItem()) instanceof ShulkerBoxBlock) {
                    ++integer4;
                }
                else {
                    if (!(bki7.getItem() instanceof DyeItem)) {
                        return false;
                    }
                    ++integer5;
                }
                if (integer5 > 1 || integer4 > 1) {
                    return false;
                }
            }
        }
        return integer4 == 1 && integer5 == 1;
    }
    
    @Override
    public ItemStack assemble(final CraftingContainer bgu) {
        ItemStack bki3 = ItemStack.EMPTY;
        DyeItem bjf4 = (DyeItem)Items.WHITE_DYE;
        for (int integer5 = 0; integer5 < bgu.getContainerSize(); ++integer5) {
            final ItemStack bki4 = bgu.getItem(integer5);
            if (!bki4.isEmpty()) {
                final Item bke7 = bki4.getItem();
                if (Block.byItem(bke7) instanceof ShulkerBoxBlock) {
                    bki3 = bki4;
                }
                else if (bke7 instanceof DyeItem) {
                    bjf4 = (DyeItem)bke7;
                }
            }
        }
        final ItemStack bki5 = ShulkerBoxBlock.getColoredItemStack(bjf4.getDyeColor());
        if (bki3.hasTag()) {
            bki5.setTag(bki3.getTag().copy());
        }
        return bki5;
    }
    
    @Override
    public boolean canCraftInDimensions(final int integer1, final int integer2) {
        return integer1 * integer2 >= 2;
    }
    
    @Override
    public RecipeSerializer<?> getSerializer() {
        return RecipeSerializer.SHULKER_BOX_COLORING;
    }
}
