    001    package net.minecraft.inventory;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import net.minecraft.entity.player.EntityPlayer;
    006    import net.minecraft.entity.player.InventoryPlayer;
    007    import net.minecraft.item.ItemStack;
    008    import net.minecraft.tileentity.TileEntityBeacon;
    009
    010    public 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 var3 = 36;
    027            short var4 = 137;
    028            int var5;
    029
    030            for (var5 = 0; var5 < 3; ++var5)
    031            {
    032                for (int var6 = 0; var6 < 9; ++var6)
    033                {
    034                    this.addSlotToContainer(new Slot(par1InventoryPlayer, var6 + var5 * 9 + 9, var3 + var6 * 18, var4 + var5 * 18));
    035                }
    036            }
    037
    038            for (var5 = 0; var5 < 9; ++var5)
    039            {
    040                this.addSlotToContainer(new Slot(par1InventoryPlayer, var5, var3 + var5 * 18, 58 + var4));
    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         * Updates crafting matrix; called from onCraftMatrixChanged. Args: none
    058         */
    059        public void updateCraftingResults()
    060        {
    061            super.updateCraftingResults();
    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.func_82128_d(par2);
    075            }
    076
    077            if (par1 == 2)
    078            {
    079                this.theBeacon.func_82127_e(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 var3 = null;
    102            Slot var4 = (Slot)this.inventorySlots.get(par2);
    103
    104            if (var4 != null && var4.getHasStack())
    105            {
    106                ItemStack var5 = var4.getStack();
    107                var3 = var5.copy();
    108
    109                if (par2 == 0)
    110                {
    111                    if (!this.mergeItemStack(var5, 1, 37, true))
    112                    {
    113                        return null;
    114                    }
    115
    116                    var4.onSlotChange(var5, var3);
    117                }
    118                else if (!this.beaconSlot.getHasStack() && this.beaconSlot.isItemValid(var5) && var5.stackSize == 1)
    119                {
    120                    if (!this.mergeItemStack(var5, 0, 1, false))
    121                    {
    122                        return null;
    123                    }
    124                }
    125                else if (par2 >= 1 && par2 < 28)
    126                {
    127                    if (!this.mergeItemStack(var5, 28, 37, false))
    128                    {
    129                        return null;
    130                    }
    131                }
    132                else if (par2 >= 28 && par2 < 37)
    133                {
    134                    if (!this.mergeItemStack(var5, 1, 28, false))
    135                    {
    136                        return null;
    137                    }
    138                }
    139                else if (!this.mergeItemStack(var5, 1, 37, false))
    140                {
    141                    return null;
    142                }
    143
    144                if (var5.stackSize == 0)
    145                {
    146                    var4.putStack((ItemStack)null);
    147                }
    148                else
    149                {
    150                    var4.onSlotChanged();
    151                }
    152
    153                if (var5.stackSize == var3.stackSize)
    154                {
    155                    return null;
    156                }
    157
    158                var4.onPickupFromSlot(par1EntityPlayer, var5);
    159            }
    160
    161            return var3;
    162        }
    163    }