    001package net.minecraft.inventory;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import java.util.ArrayList;
    006import java.util.HashSet;
    007import java.util.Iterator;
    008import java.util.List;
    009import java.util.Set;
    010import net.minecraft.entity.player.EntityPlayer;
    011import net.minecraft.entity.player.InventoryPlayer;
    012import net.minecraft.item.ItemStack;
    013import net.minecraft.util.MathHelper;
    014
    015public abstract class Container
    016{
    017    /** the list of all items(stacks) for the corresponding slot */
    018    public List inventoryItemStacks = new ArrayList();
    019
    020    /** the list of all slots in the inventory */
    021    public List inventorySlots = new ArrayList();
    022    public int windowId = 0;
    023    private short transactionID = 0;
    024    private int field_94535_f = -1;
    025    private int field_94536_g = 0;
    026    private final Set field_94537_h = new HashSet();
    027
    028    /**
    029     * list of all people that need to be notified when this craftinventory changes
    030     */
    031    protected List crafters = new ArrayList();
    032    private Set playerList = new HashSet();
    033
    034    /**
    035     * the slot is assumed empty
    036     */
    037    protected Slot addSlotToContainer(Slot par1Slot)
    038    {
    039        par1Slot.slotNumber = this.inventorySlots.size();
    040        this.inventorySlots.add(par1Slot);
    041        this.inventoryItemStacks.add((Object)null);
    042        return par1Slot;
    043    }
    044
    045    public void addCraftingToCrafters(ICrafting par1ICrafting)
    046    {
    047        if (this.crafters.contains(par1ICrafting))
    048        {
    049            throw new IllegalArgumentException("Listener already listening");
    050        }
    051        else
    052        {
    053            this.crafters.add(par1ICrafting);
    054            par1ICrafting.sendContainerAndContentsToPlayer(this, this.getInventory());
    055            this.detectAndSendChanges();
    056        }
    057    }
    058
    059    /**
    060     * returns a list if itemStacks, for each slot.
    061     */
    062    public List getInventory()
    063    {
    064        ArrayList arraylist = new ArrayList();
    065
    066        for (int i = 0; i < this.inventorySlots.size(); ++i)
    067        {
    068            arraylist.add(((Slot)this.inventorySlots.get(i)).getStack());
    069        }
    070
    071        return arraylist;
    072    }
    073
    074    @SideOnly(Side.CLIENT)
    075
    076    /**
    077     * Remove this crafting listener from the listener list.
    078     */
    079    public void removeCraftingFromCrafters(ICrafting par1ICrafting)
    080    {
    081        this.crafters.remove(par1ICrafting);
    082    }
    083
    084    /**
    085     * Looks for changes made in the container, sends them to every listener.
    086     */
    087    public void detectAndSendChanges()
    088    {
    089        for (int i = 0; i < this.inventorySlots.size(); ++i)
    090        {
    091            ItemStack itemstack = ((Slot)this.inventorySlots.get(i)).getStack();
    092            ItemStack itemstack1 = (ItemStack)this.inventoryItemStacks.get(i);
    093
    094            if (!ItemStack.areItemStacksEqual(itemstack1, itemstack))
    095            {
    096                itemstack1 = itemstack == null ? null : itemstack.copy();
    097                this.inventoryItemStacks.set(i, itemstack1);
    098
    099                for (int j = 0; j < this.crafters.size(); ++j)
    100                {
    101                    ((ICrafting)this.crafters.get(j)).sendSlotContents(this, i, itemstack1);
    102                }
    103            }
    104        }
    105    }
    106
    107    /**
    108     * enchants the item on the table using the specified slot; also deducts XP from player
    109     */
    110    public boolean enchantItem(EntityPlayer par1EntityPlayer, int par2)
    111    {
    112        return false;
    113    }
    114
    115    public Slot getSlotFromInventory(IInventory par1IInventory, int par2)
    116    {
    117        for (int j = 0; j < this.inventorySlots.size(); ++j)
    118        {
    119            Slot slot = (Slot)this.inventorySlots.get(j);
    120
    121            if (slot.isSlotInInventory(par1IInventory, par2))
    122            {
    123                return slot;
    124            }
    125        }
    126
    127        return null;
    128    }
    129
    130    public Slot getSlot(int par1)
    131    {
    132        return (Slot)this.inventorySlots.get(par1);
    133    }
    134
    135    /**
    136     * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
    137     */
    138    public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    139    {
    140        Slot slot = (Slot)this.inventorySlots.get(par2);
    141        return slot != null ? slot.getStack() : null;
    142    }
    143
    144    public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer)
    145    {
    146        ItemStack itemstack = null;
    147        InventoryPlayer inventoryplayer = par4EntityPlayer.inventory;
    148        int l;
    149        ItemStack itemstack1;
    150
    151        if (par3 == 5)
    152        {
    153            int i1 = this.field_94536_g;
    154            this.field_94536_g = func_94532_c(par2);
    155
    156            if ((i1 != 1 || this.field_94536_g != 2) && i1 != this.field_94536_g)
    157            {
    158                this.func_94533_d();
    159            }
    160            else if (inventoryplayer.getItemStack() == null)
    161            {
    162                this.func_94533_d();
    163            }
    164            else if (this.field_94536_g == 0)
    165            {
    166                this.field_94535_f = func_94529_b(par2);
    167
    168                if (func_94528_d(this.field_94535_f))
    169                {
    170                    this.field_94536_g = 1;
    171                    this.field_94537_h.clear();
    172                }
    173                else
    174                {
    175                    this.func_94533_d();
    176                }
    177            }
    178            else if (this.field_94536_g == 1)
    179            {
    180                Slot slot = (Slot)this.inventorySlots.get(par1);
    181
    182                if (slot != null && func_94527_a(slot, inventoryplayer.getItemStack(), true) && slot.isItemValid(inventoryplayer.getItemStack()) && inventoryplayer.getItemStack().stackSize > this.field_94537_h.size() && this.func_94531_b(slot))
    183                {
    184                    this.field_94537_h.add(slot);
    185                }
    186            }
    187            else if (this.field_94536_g == 2)
    188            {
    189                if (!this.field_94537_h.isEmpty())
    190                {
    191                    itemstack1 = inventoryplayer.getItemStack().copy();
    192                    l = inventoryplayer.getItemStack().stackSize;
    193                    Iterator iterator = this.field_94537_h.iterator();
    194
    195                    while (iterator.hasNext())
    196                    {
    197                        Slot slot1 = (Slot)iterator.next();
    198
    199                        if (slot1 != null && func_94527_a(slot1, inventoryplayer.getItemStack(), true) && slot1.isItemValid(inventoryplayer.getItemStack()) && inventoryplayer.getItemStack().stackSize >= this.field_94537_h.size() && this.func_94531_b(slot1))
    200                        {
    201                            ItemStack itemstack2 = itemstack1.copy();
    202                            int j1 = slot1.getHasStack() ? slot1.getStack().stackSize : 0;
    203                            func_94525_a(this.field_94537_h, this.field_94535_f, itemstack2, j1);
    204
    205                            if (itemstack2.stackSize > itemstack2.getMaxStackSize())
    206                            {
    207                                itemstack2.stackSize = itemstack2.getMaxStackSize();
    208                            }
    209
    210                            if (itemstack2.stackSize > slot1.getSlotStackLimit())
    211                            {
    212                                itemstack2.stackSize = slot1.getSlotStackLimit();
    213                            }
    214
    215                            l -= itemstack2.stackSize - j1;
    216                            slot1.putStack(itemstack2);
    217                        }
    218                    }
    219
    220                    itemstack1.stackSize = l;
    221
    222                    if (itemstack1.stackSize <= 0)
    223                    {
    224                        itemstack1 = null;
    225                    }
    226
    227                    inventoryplayer.setItemStack(itemstack1);
    228                }
    229
    230                this.func_94533_d();
    231            }
    232            else
    233            {
    234                this.func_94533_d();
    235            }
    236        }
    237        else if (this.field_94536_g != 0)
    238        {
    239            this.func_94533_d();
    240        }
    241        else
    242        {
    243            Slot slot2;
    244            int k1;
    245            ItemStack itemstack3;
    246
    247            if ((par3 == 0 || par3 == 1) && (par2 == 0 || par2 == 1))
    248            {
    249                if (par1 == -999)
    250                {
    251                    if (inventoryplayer.getItemStack() != null && par1 == -999)
    252                    {
    253                        if (par2 == 0)
    254                        {
    255                            par4EntityPlayer.dropPlayerItem(inventoryplayer.getItemStack());
    256                            inventoryplayer.setItemStack((ItemStack)null);
    257                        }
    258
    259                        if (par2 == 1)
    260                        {
    261                            par4EntityPlayer.dropPlayerItem(inventoryplayer.getItemStack().splitStack(1));
    262
    263                            if (inventoryplayer.getItemStack().stackSize == 0)
    264                            {
    265                                inventoryplayer.setItemStack((ItemStack)null);
    266                            }
    267                        }
    268                    }
    269                }
    270                else if (par3 == 1)
    271                {
    272                    if (par1 < 0)
    273                    {
    274                        return null;
    275                    }
    276
    277                    slot2 = (Slot)this.inventorySlots.get(par1);
    278
    279                    if (slot2 != null && slot2.canTakeStack(par4EntityPlayer))
    280                    {
    281                        itemstack1 = this.transferStackInSlot(par4EntityPlayer, par1);
    282
    283                        if (itemstack1 != null)
    284                        {
    285                            l = itemstack1.itemID;
    286                            itemstack = itemstack1.copy();
    287
    288                            if (slot2 != null && slot2.getStack() != null && slot2.getStack().itemID == l)
    289                            {
    290                                this.retrySlotClick(par1, par2, true, par4EntityPlayer);
    291                            }
    292                        }
    293                    }
    294                }
    295                else
    296                {
    297                    if (par1 < 0)
    298                    {
    299                        return null;
    300                    }
    301
    302                    slot2 = (Slot)this.inventorySlots.get(par1);
    303
    304                    if (slot2 != null)
    305                    {
    306                        itemstack1 = slot2.getStack();
    307                        ItemStack itemstack4 = inventoryplayer.getItemStack();
    308
    309                        if (itemstack1 != null)
    310                        {
    311                            itemstack = itemstack1.copy();
    312                        }
    313
    314                        if (itemstack1 == null)
    315                        {
    316                            if (itemstack4 != null && slot2.isItemValid(itemstack4))
    317                            {
    318                                k1 = par2 == 0 ? itemstack4.stackSize : 1;
    319
    320                                if (k1 > slot2.getSlotStackLimit())
    321                                {
    322                                    k1 = slot2.getSlotStackLimit();
    323                                }
    324
    325                                slot2.putStack(itemstack4.splitStack(k1));
    326
    327                                if (itemstack4.stackSize == 0)
    328                                {
    329                                    inventoryplayer.setItemStack((ItemStack)null);
    330                                }
    331                            }
    332                        }
    333                        else if (slot2.canTakeStack(par4EntityPlayer))
    334                        {
    335                            if (itemstack4 == null)
    336                            {
    337                                k1 = par2 == 0 ? itemstack1.stackSize : (itemstack1.stackSize + 1) / 2;
    338                                itemstack3 = slot2.decrStackSize(k1);
    339                                inventoryplayer.setItemStack(itemstack3);
    340
    341                                if (itemstack1.stackSize == 0)
    342                                {
    343                                    slot2.putStack((ItemStack)null);
    344                                }
    345
    346                                slot2.onPickupFromSlot(par4EntityPlayer, inventoryplayer.getItemStack());
    347                            }
    348                            else if (slot2.isItemValid(itemstack4))
    349                            {
    350                                if (itemstack1.itemID == itemstack4.itemID && itemstack1.getItemDamage() == itemstack4.getItemDamage() && ItemStack.areItemStackTagsEqual(itemstack1, itemstack4))
    351                                {
    352                                    k1 = par2 == 0 ? itemstack4.stackSize : 1;
    353
    354                                    if (k1 > slot2.getSlotStackLimit() - itemstack1.stackSize)
    355                                    {
    356                                        k1 = slot2.getSlotStackLimit() - itemstack1.stackSize;
    357                                    }
    358
    359                                    if (k1 > itemstack4.getMaxStackSize() - itemstack1.stackSize)
    360                                    {
    361                                        k1 = itemstack4.getMaxStackSize() - itemstack1.stackSize;
    362                                    }
    363
    364                                    itemstack4.splitStack(k1);
    365
    366                                    if (itemstack4.stackSize == 0)
    367                                    {
    368                                        inventoryplayer.setItemStack((ItemStack)null);
    369                                    }
    370
    371                                    itemstack1.stackSize += k1;
    372                                }
    373                                else if (itemstack4.stackSize <= slot2.getSlotStackLimit())
    374                                {
    375                                    slot2.putStack(itemstack4);
    376                                    inventoryplayer.setItemStack(itemstack1);
    377                                }
    378                            }
    379                            else if (itemstack1.itemID == itemstack4.itemID && itemstack4.getMaxStackSize() > 1 && (!itemstack1.getHasSubtypes() || itemstack1.getItemDamage() == itemstack4.getItemDamage()) && ItemStack.areItemStackTagsEqual(itemstack1, itemstack4))
    380                            {
    381                                k1 = itemstack1.stackSize;
    382
    383                                if (k1 > 0 && k1 + itemstack4.stackSize <= itemstack4.getMaxStackSize())
    384                                {
    385                                    itemstack4.stackSize += k1;
    386                                    itemstack1 = slot2.decrStackSize(k1);
    387
    388                                    if (itemstack1.stackSize == 0)
    389                                    {
    390                                        slot2.putStack((ItemStack)null);
    391                                    }
    392
    393                                    slot2.onPickupFromSlot(par4EntityPlayer, inventoryplayer.getItemStack());
    394                                }
    395                            }
    396                        }
    397
    398                        slot2.onSlotChanged();
    399                    }
    400                }
    401            }
    402            else if (par3 == 2 && par2 >= 0 && par2 < 9)
    403            {
    404                slot2 = (Slot)this.inventorySlots.get(par1);
    405
    406                if (slot2.canTakeStack(par4EntityPlayer))
    407                {
    408                    itemstack1 = inventoryplayer.getStackInSlot(par2);
    409                    boolean flag = itemstack1 == null || slot2.inventory == inventoryplayer && slot2.isItemValid(itemstack1);
    410                    k1 = -1;
    411
    412                    if (!flag)
    413                    {
    414                        k1 = inventoryplayer.getFirstEmptyStack();
    415                        flag |= k1 > -1;
    416                    }
    417
    418                    if (slot2.getHasStack() && flag)
    419                    {
    420                        itemstack3 = slot2.getStack();
    421                        inventoryplayer.setInventorySlotContents(par2, itemstack3);
    422
    423                        if ((slot2.inventory != inventoryplayer || !slot2.isItemValid(itemstack1)) && itemstack1 != null)
    424                        {
    425                            if (k1 > -1)
    426                            {
    427                                inventoryplayer.addItemStackToInventory(itemstack1);
    428                                slot2.decrStackSize(itemstack3.stackSize);
    429                                slot2.putStack((ItemStack)null);
    430                                slot2.onPickupFromSlot(par4EntityPlayer, itemstack3);
    431                            }
    432                        }
    433                        else
    434                        {
    435                            slot2.decrStackSize(itemstack3.stackSize);
    436                            slot2.putStack(itemstack1);
    437                            slot2.onPickupFromSlot(par4EntityPlayer, itemstack3);
    438                        }
    439                    }
    440                    else if (!slot2.getHasStack() && itemstack1 != null && slot2.isItemValid(itemstack1))
    441                    {
    442                        inventoryplayer.setInventorySlotContents(par2, (ItemStack)null);
    443                        slot2.putStack(itemstack1);
    444                    }
    445                }
    446            }
    447            else if (par3 == 3 && par4EntityPlayer.capabilities.isCreativeMode && inventoryplayer.getItemStack() == null && par1 >= 0)
    448            {
    449                slot2 = (Slot)this.inventorySlots.get(par1);
    450
    451                if (slot2 != null && slot2.getHasStack())
    452                {
    453                    itemstack1 = slot2.getStack().copy();
    454                    itemstack1.stackSize = itemstack1.getMaxStackSize();
    455                    inventoryplayer.setItemStack(itemstack1);
    456                }
    457            }
    458            else if (par3 == 4 && inventoryplayer.getItemStack() == null && par1 >= 0)
    459            {
    460                slot2 = (Slot)this.inventorySlots.get(par1);
    461
    462                if (slot2 != null && slot2.getHasStack())
    463                {
    464                    itemstack1 = slot2.decrStackSize(par2 == 0 ? 1 : slot2.getStack().stackSize);
    465                    slot2.onPickupFromSlot(par4EntityPlayer, itemstack1);
    466                    par4EntityPlayer.dropPlayerItem(itemstack1);
    467                }
    468            }
    469            else if (par3 == 6 && par1 >= 0)
    470            {
    471                slot2 = (Slot)this.inventorySlots.get(par1);
    472                itemstack1 = inventoryplayer.getItemStack();
    473
    474                if (itemstack1 != null && (slot2 == null || !slot2.getHasStack() || !slot2.canTakeStack(par4EntityPlayer)))
    475                {
    476                    l = par2 == 0 ? 0 : this.inventorySlots.size() - 1;
    477                    k1 = par2 == 0 ? 1 : -1;
    478
    479                    for (int l1 = 0; l1 < 2; ++l1)
    480                    {
    481                        for (int i2 = l; i2 >= 0 && i2 < this.inventorySlots.size() && itemstack1.stackSize < itemstack1.getMaxStackSize(); i2 += k1)
    482                        {
    483                            Slot slot3 = (Slot)this.inventorySlots.get(i2);
    484
    485                            if (slot3.getHasStack() && func_94527_a(slot3, itemstack1, true) && slot3.canTakeStack(par4EntityPlayer) && this.func_94530_a(itemstack1, slot3) && (l1 != 0 || slot3.getStack().stackSize != slot3.getStack().getMaxStackSize()))
    486                            {
    487                                int j2 = Math.min(itemstack1.getMaxStackSize() - itemstack1.stackSize, slot3.getStack().stackSize);
    488                                ItemStack itemstack5 = slot3.decrStackSize(j2);
    489                                itemstack1.stackSize += j2;
    490
    491                                if (itemstack5.stackSize <= 0)
    492                                {
    493                                    slot3.putStack((ItemStack)null);
    494                                }
    495
    496                                slot3.onPickupFromSlot(par4EntityPlayer, itemstack5);
    497                            }
    498                        }
    499                    }
    500                }
    501
    502                this.detectAndSendChanges();
    503            }
    504        }
    505
    506        return itemstack;
    507    }
    508
    509    public boolean func_94530_a(ItemStack par1ItemStack, Slot par2Slot)
    510    {
    511        return true;
    512    }
    513
    514    protected void retrySlotClick(int par1, int par2, boolean par3, EntityPlayer par4EntityPlayer)
    515    {
    516        this.slotClick(par1, par2, 1, par4EntityPlayer);
    517    }
    518
    519    /**
    520     * Callback for when the crafting gui is closed.
    521     */
    522    public void onCraftGuiClosed(EntityPlayer par1EntityPlayer)
    523    {
    524        InventoryPlayer inventoryplayer = par1EntityPlayer.inventory;
    525
    526        if (inventoryplayer.getItemStack() != null)
    527        {
    528            par1EntityPlayer.dropPlayerItem(inventoryplayer.getItemStack());
    529            inventoryplayer.setItemStack((ItemStack)null);
    530        }
    531    }
    532
    533    /**
    534     * Callback for when the crafting matrix is changed.
    535     */
    536    public void onCraftMatrixChanged(IInventory par1IInventory)
    537    {
    538        this.detectAndSendChanges();
    539    }
    540
    541    /**
    542     * args: slotID, itemStack to put in slot
    543     */
    544    public void putStackInSlot(int par1, ItemStack par2ItemStack)
    545    {
    546        this.getSlot(par1).putStack(par2ItemStack);
    547    }
    548
    549    @SideOnly(Side.CLIENT)
    550
    551    /**
    552     * places itemstacks in first x slots, x being aitemstack.lenght
    553     */
    554    public void putStacksInSlots(ItemStack[] par1ArrayOfItemStack)
    555    {
    556        for (int i = 0; i < par1ArrayOfItemStack.length; ++i)
    557        {
    558            this.getSlot(i).putStack(par1ArrayOfItemStack[i]);
    559        }
    560    }
    561
    562    @SideOnly(Side.CLIENT)
    563    public void updateProgressBar(int par1, int par2) {}
    564
    565    @SideOnly(Side.CLIENT)
    566
    567    /**
    568     * Gets a unique transaction ID. Parameter is unused.
    569     */
    570    public short getNextTransactionID(InventoryPlayer par1InventoryPlayer)
    571    {
    572        ++this.transactionID;
    573        return this.transactionID;
    574    }
    575
    576    /**
    577     * NotUsing because adding a player twice is an error
    578     */
    579    public boolean isPlayerNotUsingContainer(EntityPlayer par1EntityPlayer)
    580    {
    581        return !this.playerList.contains(par1EntityPlayer);
    582    }
    583
    584    /**
    585     * adds or removes the player from the container based on par2
    586     */
    587    public void setPlayerIsPresent(EntityPlayer par1EntityPlayer, boolean par2)
    588    {
    589        if (par2)
    590        {
    591            this.playerList.remove(par1EntityPlayer);
    592        }
    593        else
    594        {
    595            this.playerList.add(par1EntityPlayer);
    596        }
    597    }
    598
    599    public abstract boolean canInteractWith(EntityPlayer entityplayer);
    600
    601    /**
    602     * merges provided ItemStack with the first avaliable one in the container/player inventory
    603     */
    604    protected boolean mergeItemStack(ItemStack par1ItemStack, int par2, int par3, boolean par4)
    605    {
    606        boolean flag1 = false;
    607        int k = par2;
    608
    609        if (par4)
    610        {
    611            k = par3 - 1;
    612        }
    613
    614        Slot slot;
    615        ItemStack itemstack1;
    616
    617        if (par1ItemStack.isStackable())
    618        {
    619            while (par1ItemStack.stackSize > 0 && (!par4 && k < par3 || par4 && k >= par2))
    620            {
    621                slot = (Slot)this.inventorySlots.get(k);
    622                itemstack1 = slot.getStack();
    623
    624                if (itemstack1 != null && itemstack1.itemID == par1ItemStack.itemID && (!par1ItemStack.getHasSubtypes() || par1ItemStack.getItemDamage() == itemstack1.getItemDamage()) && ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1))
    625                {
    626                    int l = itemstack1.stackSize + par1ItemStack.stackSize;
    627
    628                    if (l <= par1ItemStack.getMaxStackSize())
    629                    {
    630                        par1ItemStack.stackSize = 0;
    631                        itemstack1.stackSize = l;
    632                        slot.onSlotChanged();
    633                        flag1 = true;
    634                    }
    635                    else if (itemstack1.stackSize < par1ItemStack.getMaxStackSize())
    636                    {
    637                        par1ItemStack.stackSize -= par1ItemStack.getMaxStackSize() - itemstack1.stackSize;
    638                        itemstack1.stackSize = par1ItemStack.getMaxStackSize();
    639                        slot.onSlotChanged();
    640                        flag1 = true;
    641                    }
    642                }
    643
    644                if (par4)
    645                {
    646                    --k;
    647                }
    648                else
    649                {
    650                    ++k;
    651                }
    652            }
    653        }
    654
    655        if (par1ItemStack.stackSize > 0)
    656        {
    657            if (par4)
    658            {
    659                k = par3 - 1;
    660            }
    661            else
    662            {
    663                k = par2;
    664            }
    665
    666            while (!par4 && k < par3 || par4 && k >= par2)
    667            {
    668                slot = (Slot)this.inventorySlots.get(k);
    669                itemstack1 = slot.getStack();
    670
    671                if (itemstack1 == null)
    672                {
    673                    slot.putStack(par1ItemStack.copy());
    674                    slot.onSlotChanged();
    675                    par1ItemStack.stackSize = 0;
    676                    flag1 = true;
    677                    break;
    678                }
    679
    680                if (par4)
    681                {
    682                    --k;
    683                }
    684                else
    685                {
    686                    ++k;
    687                }
    688            }
    689        }
    690
    691        return flag1;
    692    }
    693
    694    public static int func_94529_b(int par0)
    695    {
    696        return par0 >> 2 & 3;
    697    }
    698
    699    public static int func_94532_c(int par0)
    700    {
    701        return par0 & 3;
    702    }
    703
    704    @SideOnly(Side.CLIENT)
    705    public static int func_94534_d(int par0, int par1)
    706    {
    707        return par0 & 3 | (par1 & 3) << 2;
    708    }
    709
    710    public static boolean func_94528_d(int par0)
    711    {
    712        return par0 == 0 || par0 == 1;
    713    }
    714
    715    protected void func_94533_d()
    716    {
    717        this.field_94536_g = 0;
    718        this.field_94537_h.clear();
    719    }
    720
    721    public static boolean func_94527_a(Slot par0Slot, ItemStack par1ItemStack, boolean par2)
    722    {
    723        boolean flag1 = par0Slot == null || !par0Slot.getHasStack();
    724
    725        if (par0Slot != null && par0Slot.getHasStack() && par1ItemStack != null && par1ItemStack.isItemEqual(par0Slot.getStack()) && ItemStack.areItemStackTagsEqual(par0Slot.getStack(), par1ItemStack))
    726        {
    727            int i = par2 ? 0 : par1ItemStack.stackSize;
    728            flag1 |= par0Slot.getStack().stackSize + i <= par1ItemStack.getMaxStackSize();
    729        }
    730
    731        return flag1;
    732    }
    733
    734    public static void func_94525_a(Set par0Set, int par1, ItemStack par2ItemStack, int par3)
    735    {
    736        switch (par1)
    737        {
    738            case 0:
    739                par2ItemStack.stackSize = MathHelper.floor_float((float)par2ItemStack.stackSize / (float)par0Set.size());
    740                break;
    741            case 1:
    742                par2ItemStack.stackSize = 1;
    743        }
    744
    745        par2ItemStack.stackSize += par3;
    746    }
    747
    748    public boolean func_94531_b(Slot par1Slot)
    749    {
    750        return true;
    751    }
    752
    753    public static int func_94526_b(IInventory par0IInventory)
    754    {
    755        if (par0IInventory == null)
    756        {
    757            return 0;
    758        }
    759        else
    760        {
    761            int i = 0;
    762            float f = 0.0F;
    763
    764            for (int j = 0; j < par0IInventory.getSizeInventory(); ++j)
    765            {
    766                ItemStack itemstack = par0IInventory.getStackInSlot(j);
    767
    768                if (itemstack != null)
    769                {
    770                    f += (float)itemstack.stackSize / (float)Math.min(par0IInventory.getInventoryStackLimit(), itemstack.getMaxStackSize());
    771                    ++i;
    772                }
    773            }
    774
    775            f /= (float)par0IInventory.getSizeInventory();
    776            return MathHelper.floor_float(f * 14.0F) + (i > 0 ? 1 : 0);
    777        }
    778    }
    779}