Example usage for net.minecraftforge.items.wrapper PlayerInvWrapper PlayerInvWrapper

List of usage examples for net.minecraftforge.items.wrapper PlayerInvWrapper PlayerInvWrapper

Introduction

In this page you can find the example usage for net.minecraftforge.items.wrapper PlayerInvWrapper PlayerInvWrapper.

Prototype

public PlayerInvWrapper(PlayerInventory inv) 

Source Link

Usage

From source file:com.teambrmodding.neotech.common.blocks.storage.ItemBlockEnergyStorage.java

License:Creative Commons License

/**
 * Called each tick as long the item is on a player inventory. Uses by maps to check if is on a player hand and
 * update it's contents.//from  w w  w  . java2s.  com
 *
 * @param stack
 * @param worldIn
 * @param entityIn
 * @param itemSlot
 * @param isSelected
 */
@Override
public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
    // Make sure we have a tag
    if (!stack.hasTagCompound()) {
        NBTTagCompound compound = new NBTTagCompound();
        compound.setBoolean(ACTIVE, false);
        stack.setTagCompound(compound);
    }

    // Make sure we are a player and should even charge
    if (stack.getTagCompound().getBoolean(ACTIVE) && entityIn instanceof EntityPlayer) {
        // Cast
        EntityPlayer player = (EntityPlayer) entityIn;
        // Wrap all inventory including armor and offhand
        PlayerInvWrapper playerInventory = new PlayerInvWrapper(player.inventory);
        for (int slot = 0; slot < playerInventory.getSlots(); slot++) {
            if (!(playerInventory.getStackInSlot(slot).getItem() instanceof ItemBlockEnergyStorage) && // Don't charge each other
                    playerInventory.getStackInSlot(slot).hasCapability(CapabilityEnergy.ENERGY, null)) {
                // Get our energy
                IEnergyStorage source = stack.getCapability(CapabilityEnergy.ENERGY, null);
                // Get their energy
                IEnergyStorage energyItem = playerInventory.getStackInSlot(slot)
                        .getCapability(CapabilityEnergy.ENERGY, null);
                // Transfer
                EnergyUtils.transferPower(source, energyItem, source.getMaxEnergyStored() / 200, false);
            }
        }
    }
}

From source file:de.ellpeck.actuallyadditions.mod.tile.TileEntityPlayerInterface.java

@Override
public IItemHandler getItemHandler(EnumFacing facing) {
    EntityPlayer player = this.getPlayer();

    if (this.oldPlayer != player) {
        this.oldPlayer = player;

        this.playerHandler = player == null ? null : new PlayerInvWrapper(player.inventory);
    }// ww w .  j  a va 2 s  . com

    return this.playerHandler;
}