Java Code Examples for net.minecraft.entity.EntityLiving#getSlotForItemStack()

The following examples show how to use net.minecraft.entity.EntityLiving#getSlotForItemStack() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemInventorySwapper.java    From enderutilities with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void swapRegularSlot(InventoryItemModular swapperInv, final int slot, final int mainInvSize, final int invMax, EntityPlayer player)
{
    ItemStack stackInSwapper = swapperInv.getStackInSlot(slot);

    // Check if the stack from the swapper can fit and is valid to be put into the player's inventory
    if (stackInSwapper.isEmpty() || (stackInSwapper.getCount() <= Math.min(stackInSwapper.getMaxStackSize(), invMax) &&
        player.inventory.isItemValidForSlot(slot, stackInSwapper)))
    {
        // Armor slots
        if (slot >= mainInvSize && slot < (mainInvSize + 4))
        {
            int pos = -1;

            // Armor present in the swappers's inventory slot, get the corresponding armor slot
            if (stackInSwapper.isEmpty() == false)
            {
                EntityEquipmentSlot equipmentSlot = EntityLiving.getSlotForItemStack(stackInSwapper);

                if (stackInSwapper.getCount() == 1 && equipmentSlot.getSlotType() == EntityEquipmentSlot.Type.ARMOR)
                {
                    pos = equipmentSlot.getIndex();
                }
            }
            else if (player.inventory.getStackInSlot(slot).isEmpty() == false)
            {
                pos = slot - mainInvSize;
            }

            if (pos >= 0 && pos == (slot - mainInvSize))
            {
                swapperInv.setStackInSlot(slot, player.inventory.getStackInSlot(slot));
                player.inventory.setInventorySlotContents(slot, stackInSwapper);
            }
        }
        // Main inventory and Off Hand slot
        else
        {
            swapperInv.setStackInSlot(slot, player.inventory.getStackInSlot(slot));
            player.inventory.setInventorySlotContents(slot, stackInSwapper);
        }
    }
}