package net.minecraft.world.inventory;

import net.minecraft.world.entity.player.StackedContents;
import net.minecraft.world.entity.player.Player;
import java.util.List;
import net.minecraft.world.ContainerHelper;
import java.util.Iterator;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.NonNullList;
import net.minecraft.world.Container;

public class CraftingContainer implements Container, StackedContentsCompatible {
    private final NonNullList<ItemStack> items;
    private final int width;
    private final int height;
    private final AbstractContainerMenu menu;
    
    public CraftingContainer(final AbstractContainerMenu ban, final int integer2, final int integer3) {
        this.items = NonNullList.<ItemStack>withSize(integer2 * integer3, ItemStack.EMPTY);
        this.menu = ban;
        this.width = integer2;
        this.height = integer3;
    }
    
    @Override
    public int getContainerSize() {
        return this.items.size();
    }
    
    @Override
    public boolean isEmpty() {
        for (final ItemStack ben3 : this.items) {
            if (!ben3.isEmpty()) {
                return false;
            }
        }
        return true;
    }
    
    @Override
    public ItemStack getItem(final int integer) {
        if (integer >= this.getContainerSize()) {
            return ItemStack.EMPTY;
        }
        return this.items.get(integer);
    }
    
    @Override
    public ItemStack removeItemNoUpdate(final int integer) {
        return ContainerHelper.takeItem(this.items, integer);
    }
    
    @Override
    public ItemStack removeItem(final int integer1, final int integer2) {
        final ItemStack ben4 = ContainerHelper.removeItem(this.items, integer1, integer2);
        if (!ben4.isEmpty()) {
            this.menu.slotsChanged(this);
        }
        return ben4;
    }
    
    @Override
    public void setItem(final int integer, final ItemStack ben) {
        this.items.set(integer, ben);
        this.menu.slotsChanged(this);
    }
    
    @Override
    public void setChanged() {
    }
    
    @Override
    public boolean stillValid(final Player ayj) {
        return true;
    }
    
    @Override
    public void clearContent() {
        this.items.clear();
    }
    
    public int getHeight() {
        return this.height;
    }
    
    public int getWidth() {
        return this.width;
    }
    
    @Override
    public void fillStackedContents(final StackedContents ayl) {
        for (final ItemStack ben4 : this.items) {
            ayl.accountSimpleStack(ben4);
        }
    }
}
