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