Search in sources :

Example 71 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project Armourers-Workshop by RiskyKen.

the class UtilPlayer method getNumberOfItemInInventory.

public static int getNumberOfItemInInventory(EntityPlayer player, Item item) {
    int itemCount = 0;
    InventoryPlayer inventory = player.inventory;
    for (int i = 0; i < inventory.mainInventory.length; i++) {
        if (inventory.mainInventory[i].getItem() == item) {
            itemCount += inventory.mainInventory[i].stackSize;
        }
    }
    return itemCount;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer)

Example 72 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project ArsMagica2 by Mithion.

the class AM2Container method slotClickGhost.

public ItemStack slotClickGhost(Slot slot, int mouseButton, int modifier, EntityPlayer player) {
    ItemStack stack = null;
    if (mouseButton == 2) {
        if (((IGhostSlot) slot).canAdjust()) {
            slot.putStack(null);
        }
    } else if (mouseButton == 0 || mouseButton == 1) {
        InventoryPlayer playerInv = player.inventory;
        slot.onSlotChanged();
        ItemStack stackSlot = slot.getStack();
        ItemStack stackHeld = playerInv.getItemStack();
        if (stackSlot != null) {
            stack = stackSlot.copy();
        }
        if (stackSlot == null) {
            if (stackHeld != null && slot.isItemValid(stackHeld)) {
                fillGhostSlot(slot, stackHeld, mouseButton, modifier);
            }
        } else if (stackHeld == null) {
            adjustGhostSlot(slot, mouseButton, modifier);
            slot.onPickupFromSlot(player, playerInv.getItemStack());
        } else if (slot.isItemValid(stackHeld)) {
            if (InventoryUtilities.canStacksMerge(stackSlot, stackHeld)) {
                adjustGhostSlot(slot, mouseButton, modifier);
            } else {
                fillGhostSlot(slot, stackHeld, mouseButton, modifier);
            }
        }
    }
    return stack;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 73 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project Armourers-Workshop by RiskyKen.

the class EntityEquipmentDataManager method updateWeaponNBT.

private void updateWeaponNBT(EntityPlayer player, ExPropsPlayerSkinData props) {
    InventoryPlayer inventory = player.inventory;
    EntityEquipmentData equipmentData = props.getEquipmentData();
    ItemStack stack = inventory.getCurrentItem();
    if (stack != null) {
        if (isRenderItem(ItemOverrideType.SWORD, stack.getItem())) {
            if (equipmentData.haveEquipment(SkinTypeRegistry.skinSword, 0)) {
                SkinNBTHelper.addSkinPointerToStack(stack, (SkinPointer) equipmentData.getSkinPointer(SkinTypeRegistry.skinSword, 0));
            } else {
                SkinNBTHelper.removeRenderIdFromStack(stack);
            }
        }
        if (isRenderItem(ItemOverrideType.BOW, stack.getItem())) {
            if (equipmentData.haveEquipment(SkinTypeRegistry.skinBow, 0)) {
                SkinNBTHelper.addSkinPointerToStack(stack, (SkinPointer) equipmentData.getSkinPointer(SkinTypeRegistry.skinBow, 0));
            } else {
                SkinNBTHelper.removeRenderIdFromStack(stack);
            }
        }
        if (isRenderItem(ItemOverrideType.PICKAXE, stack.getItem())) {
            if (equipmentData.haveEquipment(SkinTypeRegistry.skinSword, 1)) {
                SkinNBTHelper.addSkinPointerToStack(stack, (SkinPointer) equipmentData.getSkinPointer(SkinTypeRegistry.skinSword, 1));
            } else {
                SkinNBTHelper.removeRenderIdFromStack(stack);
            }
        }
        if (isRenderItem(ItemOverrideType.AXE, stack.getItem())) {
            if (equipmentData.haveEquipment(SkinTypeRegistry.skinSword, 2)) {
                SkinNBTHelper.addSkinPointerToStack(stack, (SkinPointer) equipmentData.getSkinPointer(SkinTypeRegistry.skinSword, 2));
            } else {
                SkinNBTHelper.removeRenderIdFromStack(stack);
            }
        }
        if (isRenderItem(ItemOverrideType.SHOVEL, stack.getItem())) {
            if (equipmentData.haveEquipment(SkinTypeRegistry.skinSword, 3)) {
                SkinNBTHelper.addSkinPointerToStack(stack, (SkinPointer) equipmentData.getSkinPointer(SkinTypeRegistry.skinSword, 3));
            } else {
                SkinNBTHelper.removeRenderIdFromStack(stack);
            }
        }
        if (isRenderItem(ItemOverrideType.HOE, stack.getItem())) {
            if (equipmentData.haveEquipment(SkinTypeRegistry.skinSword, 4)) {
                SkinNBTHelper.addSkinPointerToStack(stack, (SkinPointer) equipmentData.getSkinPointer(SkinTypeRegistry.skinSword, 4));
            } else {
                SkinNBTHelper.removeRenderIdFromStack(stack);
            }
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemStack(net.minecraft.item.ItemStack)

Example 74 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project PneumaticCraft by MineMaarten.

the class TileEntityAerialInterface method tickRF.

private void tickRF() {
    if (getEnergyStored(null) > 0) {
        InventoryPlayer inv = getPlayerInventory();
        if (inv != null) {
            for (int i = 0; i < inv.getSizeInventory(); i++) {
                ItemStack stack = inv.getStackInSlot(i);
                if (stack != null && stack.getItem() instanceof IEnergyContainerItem) {
                    IEnergyContainerItem chargingItem = (IEnergyContainerItem) stack.getItem();
                    int energyLeft = getEnergyStored(null);
                    if (energyLeft > 0) {
                        getEnergy().extractEnergy(chargingItem.receiveEnergy(stack, energyLeft, false), false);
                    } else {
                        break;
                    }
                }
            }
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemStack(net.minecraft.item.ItemStack) IEnergyContainerItem(cofh.api.energy.IEnergyContainerItem)

Example 75 with InventoryPlayer

use of net.minecraft.entity.player.InventoryPlayer in project Minechem by iopleke.

the class MinechemUtil method scanForMoreStacks.

public static void scanForMoreStacks(ItemStack current, EntityPlayer player) {
    int getMore = 8 - current.stackSize;
    InventoryPlayer inventory = player.inventory;
    int maxSlot = player.inventory.getSizeInventory() - 4;
    int slot = 0;
    do {
        if (slot != inventory.currentItem) {
            ItemStack slotStack = inventory.getStackInSlot(slot);
            if (slotStack != null && slotStack.isItemEqual(current)) {
                ItemStack addStack = inventory.decrStackSize(slot, getMore);
                current.stackSize += addStack.stackSize;
                getMore -= addStack.stackSize;
            }
        }
        slot++;
    } while (getMore > 0 && slot < maxSlot);
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) ItemStack(net.minecraft.item.ItemStack)

Aggregations

InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)83 ItemStack (net.minecraft.item.ItemStack)57 Slot (net.minecraft.inventory.Slot)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)9 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)7 Item (net.minecraft.item.Item)6 ArrayList (java.util.ArrayList)5 Nonnull (javax.annotation.Nonnull)4 IFuzzySlot (logisticspipes.interfaces.IFuzzySlot)4 Button (com.minecolonies.blockout.controls.Button)3 EntityItem (net.minecraft.entity.item.EntityItem)3 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)3 IPhantomSlot (buildcraft.lib.gui.slot.IPhantomSlot)2 TileProjectTable (com.bluepowermod.tile.tier1.TileProjectTable)2 ItemIcon (com.minecolonies.blockout.controls.ItemIcon)2 Label (com.minecolonies.blockout.controls.Label)2 BuildingBuilderResource (com.minecolonies.coremod.colony.buildings.utils.BuildingBuilderResource)2 GameProfile (com.mojang.authlib.GameProfile)2 LinkedList (java.util.LinkedList)2