package net.minecraft.world.inventory;

import net.minecraft.world.item.ItemStack;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.Container;

public class ShulkerBoxMenu extends AbstractContainerMenu {
    private final Container container;
    
    public ShulkerBoxMenu(final int integer, final Inventory beb) {
        this(integer, beb, new SimpleContainer(27));
    }
    
    public ShulkerBoxMenu(final int integer, final Inventory beb, final Container amz) {
        super(MenuType.SHULKER_BOX, integer);
        AbstractContainerMenu.checkContainerSize(amz, 27);
        (this.container = amz).startOpen(beb.player);
        final int integer2 = 3;
        final int integer3 = 9;
        for (int integer4 = 0; integer4 < 3; ++integer4) {
            for (int integer5 = 0; integer5 < 9; ++integer5) {
                this.addSlot(new ShulkerBoxSlot(amz, integer5 + integer4 * 9, 8 + integer5 * 18, 18 + integer4 * 18));
            }
        }
        for (int integer4 = 0; integer4 < 3; ++integer4) {
            for (int integer5 = 0; integer5 < 9; ++integer5) {
                this.addSlot(new Slot(beb, integer5 + integer4 * 9 + 9, 8 + integer5 * 18, 84 + integer4 * 18));
            }
        }
        for (int integer4 = 0; integer4 < 9; ++integer4) {
            this.addSlot(new Slot(beb, integer4, 8 + integer4 * 18, 142));
        }
    }
    
    @Override
    public boolean stillValid(final Player bec) {
        return this.container.stillValid(bec);
    }
    
    @Override
    public ItemStack quickMoveStack(final Player bec, final int integer) {
        ItemStack bki4 = ItemStack.EMPTY;
        final Slot bhw5 = this.slots.get(integer);
        if (bhw5 != null && bhw5.hasItem()) {
            final ItemStack bki5 = bhw5.getItem();
            bki4 = bki5.copy();
            if (integer < this.container.getContainerSize()) {
                if (!this.moveItemStackTo(bki5, this.container.getContainerSize(), this.slots.size(), true)) {
                    return ItemStack.EMPTY;
                }
            }
            else if (!this.moveItemStackTo(bki5, 0, this.container.getContainerSize(), false)) {
                return ItemStack.EMPTY;
            }
            if (bki5.isEmpty()) {
                bhw5.set(ItemStack.EMPTY);
            }
            else {
                bhw5.setChanged();
            }
        }
        return bki4;
    }
    
    @Override
    public void removed(final Player bec) {
        super.removed(bec);
        this.container.stopOpen(bec);
    }
}
