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.Container;

public class LecternMenu extends AbstractContainerMenu {
    private final Container lectern;
    private final ContainerData lecternData;
    
    public LecternMenu(final int integer) {
        this(integer, new SimpleContainer(1), new SimpleContainerData(1));
    }
    
    public LecternMenu(final int integer, final Container amz, final ContainerData bgr) {
        super(MenuType.LECTERN, integer);
        AbstractContainerMenu.checkContainerSize(amz, 1);
        AbstractContainerMenu.checkContainerDataCount(bgr, 1);
        this.lectern = amz;
        this.lecternData = bgr;
        this.addSlot(new Slot(amz, 0, 0, 0) {
            @Override
            public void setChanged() {
                super.setChanged();
                LecternMenu.this.slotsChanged(this.container);
            }
        });
        this.addDataSlots(bgr);
    }
    
    @Override
    public boolean clickMenuButton(final Player bec, final int integer) {
        if (integer >= 100) {
            final int integer2 = integer - 100;
            this.setData(0, integer2);
            return true;
        }
        switch (integer) {
            case 2: {
                final int integer2 = this.lecternData.get(0);
                this.setData(0, integer2 + 1);
                return true;
            }
            case 1: {
                final int integer2 = this.lecternData.get(0);
                this.setData(0, integer2 - 1);
                return true;
            }
            case 3: {
                if (!bec.mayBuild()) {
                    return false;
                }
                final ItemStack bki4 = this.lectern.removeItemNoUpdate(0);
                this.lectern.setChanged();
                if (!bec.inventory.add(bki4)) {
                    bec.drop(bki4, false);
                }
                return true;
            }
            default: {
                return false;
            }
        }
    }
    
    @Override
    public void setData(final int integer1, final int integer2) {
        super.setData(integer1, integer2);
        this.broadcastChanges();
    }
    
    @Override
    public boolean stillValid(final Player bec) {
        return this.lectern.stillValid(bec);
    }
    
    public ItemStack getBook() {
        return this.lectern.getItem(0);
    }
    
    public int getPage() {
        return this.lecternData.get(0);
    }
}
