    001package net.minecraft.inventory;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.entity.player.EntityPlayer;
    006import net.minecraft.entity.player.InventoryPlayer;
    007import net.minecraft.item.ItemStack;
    008import net.minecraft.tileentity.TileEntityBeacon;
    009
    010public class ContainerBeacon extends Container
    011{
    012    private TileEntityBeacon theBeacon;
    013
    014    /**
    015     * This beacon's slot where you put in Emerald, Diamond, Gold or Iron Ingot.
    016     */
    017    private final SlotBeacon beaconSlot;
    018    private int field_82865_g;
    019    private int field_82867_h;
    020    private int field_82868_i;
    021
    022    public ContainerBeacon(InventoryPlayer par1InventoryPlayer, TileEntityBeacon par2TileEntityBeacon)
    023    {
    024        this.theBeacon = par2TileEntityBeacon;
    025        this.addSlotToContainer(this.beaconSlot = new SlotBeacon(this, par2TileEntityBeacon, 0, 136, 110));
    026        byte b0 = 36;
    027        short short1 = 137;
    028        int i;
    029
    030        for (i = 0; i < 3; ++i)
    031        {
    032            for (int j = 0; j < 9; ++j)
    033            {
    034                this.addSlotToContainer(new Slot(par1InventoryPlayer, j + i * 9 + 9, b0 + j * 18, short1 + i * 18));
    035            }
    036        }
    037
    038        for (i = 0; i < 9; ++i)
    039        {
    040            this.addSlotToContainer(new Slot(par1InventoryPlayer, i, b0 + i * 18, 58 + short1));
    041        }
    042
    043        this.field_82865_g = par2TileEntityBeacon.getLevels();
    044        this.field_82867_h = par2TileEntityBeacon.getPrimaryEffect();
    045        this.field_82868_i = par2TileEntityBeacon.getSecondaryEffect();
    046    }
    047
    048    public void addCraftingToCrafters(ICrafting par1ICrafting)
    049    {
    050        super.addCraftingToCrafters(par1ICrafting);
    051        par1ICrafting.sendProgressBarUpdate(this, 0, this.field_82865_g);
    052        par1ICrafting.sendProgressBarUpdate(this, 1, this.field_82867_h);
    053        par1ICrafting.sendProgressBarUpdate(this, 2, this.field_82868_i);
    054    }
    055
    056    /**
    057     * Looks for changes made in the container, sends them to every listener.
    058     */
    059    public void detectAndSendChanges()
    060    {
    061        super.detectAndSendChanges();
    062    }
    063
    064    @SideOnly(Side.CLIENT)
    065    public void updateProgressBar(int par1, int par2)
    066    {
    067        if (par1 == 0)
    068        {
    069            this.theBeacon.setLevels(par2);
    070        }
    071
    072        if (par1 == 1)
    073        {
    074            this.theBeacon.setPrimaryEffect(par2);
    075        }
    076
    077        if (par1 == 2)
    078        {
    079            this.theBeacon.setSecondaryEffect(par2);
    080        }
    081    }
    082
    083    /**
    084     * Returns the Tile Entity behind this beacon inventory / container
    085     */
    086    public TileEntityBeacon getBeacon()
    087    {
    088        return this.theBeacon;
    089    }
    090
    091    public boolean canInteractWith(EntityPlayer par1EntityPlayer)
    092    {
    093        return this.theBeacon.isUseableByPlayer(par1EntityPlayer);
    094    }
    095
    096    /**
    097     * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
    098     */
    099    public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    100    {
    101        ItemStack itemstack = null;
    102        Slot slot = (Slot)this.inventorySlots.get(par2);
    103
    104        if (slot != null && slot.getHasStack())
    105        {
    106            ItemStack itemstack1 = slot.getStack();
    107            itemstack = itemstack1.copy();
    108
    109            if (par2 == 0)
    110            {
    111                if (!this.mergeItemStack(itemstack1, 1, 37, true))
    112                {
    113                    return null;
    114                }
    115
    116                slot.onSlotChange(itemstack1, itemstack);
    117            }
    118            else if (!this.beaconSlot.getHasStack() && this.beaconSlot.isItemValid(itemstack1) && itemstack1.stackSize == 1)
    119            {
    120                if (!this.mergeItemStack(itemstack1, 0, 1, false))
    121                {
    122                    return null;
    123                }
    124            }
    125            else if (par2 >= 1 && par2 < 28)
    126            {
    127                if (!this.mergeItemStack(itemstack1, 28, 37, false))
    128                {
    129                    return null;
    130                }
    131            }
    132            else if (par2 >= 28 && par2 < 37)
    133            {
    134                if (!this.mergeItemStack(itemstack1, 1, 28, false))
    135                {
    136                    return null;
    137                }
    138            }
    139            else if (!this.mergeItemStack(itemstack1, 1, 37, false))
    140            {
    141                return null;
    142            }
    143
    144            if (itemstack1.stackSize == 0)
    145            {
    146                slot.putStack((ItemStack)null);
    147            }
    148            else
    149            {
    150                slot.onSlotChanged();
    151            }
    152
    153            if (itemstack1.stackSize == itemstack.stackSize)
    154            {
    155                return null;
    156            }
    157
    158            slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
    159        }
    160
    161        return itemstack;
    162    }
    163}