package com.raoulvdberge.refinedstorage.integration.forgeenergy;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.energy.EnergyStorage;

public class ItemEnergyForge extends EnergyStorage {
    private static final String NBT_ENERGY = "Energy";

    private ItemStack stack;

    public ItemEnergyForge(ItemStack stack, int capacity) {
        super(capacity, Integer.MAX_VALUE, Integer.MAX_VALUE);

        this.stack = stack;
        this.energy = stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_ENERGY) ? stack.getTagCompound().getInteger(NBT_ENERGY) : 0;
    }

    @Override
    public int receiveEnergy(int maxReceive, boolean simulate) {
        int received = super.receiveEnergy(maxReceive, simulate);

        if (received > 0 && !simulate) {
            if (!stack.hasTagCompound()) {
                stack.setTagCompound(new NBTTagCompound());
            }

            stack.getTagCompound().setInteger(NBT_ENERGY, getEnergyStored());
        }

        return received;
    }

    @Override
    public int extractEnergy(int maxExtract, boolean simulate) {
        int extracted = super.extractEnergy(maxExtract, simulate);

        if (extracted > 0 && !simulate) {
            if (!stack.hasTagCompound()) {
                stack.setTagCompound(new NBTTagCompound());
            }

            stack.getTagCompound().setInteger(NBT_ENERGY, getEnergyStored());
        }

        return extracted;
    }
}

@@ -121,30 +121,24 @@
 aft.nbt.
-NBTTag
 Compound
 ;%0Aimport
@@ -129,16 +129,19 @@
 Compound
+NBT
 ;%0Aimport
@@ -508,24 +508,16 @@
 k.hasTag
-Compound
 () && st
@@ -530,25 +530,19 @@
 tTag
-Compound().hasKey
+().contains
 (NBT
@@ -564,24 +564,16 @@
 k.getTag
-Compound
 ().getIn
@@ -569,28 +569,24 @@
 Tag().getInt
-eger
 (NBT_ENERGY)
@@ -810,32 +810,24 @@
 stack.hasTag
-Compound
 ()) %7B%0A      
@@ -852,35 +852,21 @@
 tTag
-Compound(new NBTTag
+(new 
 Compound
 ());
@@ -853,32 +853,35 @@
 Tag(new Compound
+NBT
 ());%0A           
@@ -908,37 +908,25 @@
 k.getTag
-Compound
 ().
-se
+pu
 tInt
-eger
 (NBT_ENE
@@ -1211,24 +1211,16 @@
 k.hasTag
-Compound
 ()) %7B%0A  
@@ -1249,35 +1249,21 @@
 tTag
-Compound(new NBTTag
+(new 
 Compound
 ());
@@ -1258,16 +1258,19 @@
 Compound
+NBT
 ());%0A   
@@ -1309,29 +1309,17 @@
 tTag
-Compound
 ().
-se
+pu
 tInt
-eger
 (NBT

Fix errors in integration pkg