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 sm) {
        super(sm);
    }
    
    @Override
    public boolean matches(final CraftingContainer baz, final Level bjw) {
        int integer4 = 0;
        int integer5 = 0;
        for (int integer6 = 0; integer6 < baz.getContainerSize(); ++integer6) {
            final ItemStack ben7 = baz.getItem(integer6);
            if (!ben7.isEmpty()) {
                if (Block.byItem(ben7.getItem()) instanceof ShulkerBoxBlock) {
                    ++integer4;
                }
                else {
                    if (!(ben7.getItem() instanceof DyeItem)) {
                        return false;
                    }
                    ++integer5;
                }
                if (integer5 > 1 || integer4 > 1) {
                    return false;
                }
            }
        }
        return integer4 == 1 && integer5 == 1;
    }
    
    @Override
    public ItemStack assemble(final CraftingContainer baz) {
        ItemStack ben3 = ItemStack.EMPTY;
        DyeItem bdk4 = (DyeItem)Items.WHITE_DYE;
        for (int integer5 = 0; integer5 < baz.getContainerSize(); ++integer5) {
            final ItemStack ben4 = baz.getItem(integer5);
            if (!ben4.isEmpty()) {
                final Item bei7 = ben4.getItem();
                if (Block.byItem(bei7) instanceof ShulkerBoxBlock) {
                    ben3 = ben4;
                }
                else if (bei7 instanceof DyeItem) {
                    bdk4 = (DyeItem)bei7;
                }
            }
        }
        final ItemStack ben5 = ShulkerBoxBlock.getColoredItemStack(bdk4.getDyeColor());
        if (ben3.hasTag()) {
            ben5.setTag(ben3.getTag().copy());
        }
        return ben5;
    }
    
    @Override
    public boolean canCraftInDimensions(final int integer1, final int integer2) {
        return integer1 * integer2 >= 2;
    }
    
    @Override
    public RecipeSerializer<?> getSerializer() {
        return RecipeSerializer.SHULKER_BOX_COLORING;
    }
}
