List of usage examples for net.minecraftforge.items.wrapper PlayerInvWrapper getStackInSlot
@Override
@Nonnull
public ItemStack getStackInSlot(int slot)
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 ww w . j a v a 2 s .c o m * * @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); } } } }