package com.mcgoodtime.productionline.common.items;

import ic2.api.energy.EnergyNet;
import ic2.api.item.ElectricItem;
import ic2.api.item.IElectricItem;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nullable;
import java.util.List;

/**
 * Created by BestOwl on 2015.12.8.0008.
 *
 * @author BestOwl
 */
public class ItemElectricPL extends ItemPL implements IElectricItem {

    protected int maxPowerTick;
    protected int maxEnergy;
    protected int tier;

    public ItemElectricPL(String name, int tier, int maxEnergy) {
        super(name);
        this.setMaxDamage(27);
        this.setHasSubtypes(true);
        this.setMaxStackSize(1);
        this.tier = tier;
        this.maxEnergy = maxEnergy;
        this.maxPowerTick = (int) EnergyNet.instance.getPowerFromTier(tier);
        this.addPropertyOverrides();
    }

    protected void addPropertyOverrides() {
        this.addPropertyOverride(new ResourceLocation("energy"), new IItemPropertyGetter() {
            @Override
            public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn) {
                int meta = stack.getMetadata();
                if (meta < 3) {
                    return 0;
                }
                else if (meta < 10) {
                    return 1;
                }
                else if (meta < 17) {
                    return 2;
                }
                else if (meta < 24) {
                    return 3;
                }
                else {
                    return 4;
                }
            }
        });
    }

    @SuppressWarnings({"NumericOverflow", "unchecked"})
    @Override
    @SideOnly(Side.CLIENT)
    public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
        ItemStack itemStack = new ItemStack(this, 1);
        ElectricItem.manager.charge(itemStack, 0.0D, Integer.MAX_VALUE, true, false);
        itemList.add(itemStack);

        ItemStack charged = new ItemStack(this, 1);
        ElectricItem.manager.charge(charged, Double.POSITIVE_INFINITY, Integer.MAX_VALUE, true, false);
        itemList.add(charged);
    }

    /**
     * Determine if the item can be used in a machine or as an armor part to supply energy.
     *
     * @return Whether the item can supply energy
     */
    @Override
    public boolean canProvideEnergy(ItemStack itemStack) {
        return false;
    }

    /**
     * Get the item's maximum charge energy in EU.
     *
     * @return Maximum charge energy
     */
    @Override
    public double getMaxCharge(ItemStack itemStack) {
        return this.maxEnergy;
    }

    /**
     * Get the item's tier, lower tiers can't send energy to higher ones.
     * Batteries are Tier 1, Energy Crystals are Tier 2, Lapotron Crystals are Tier 3.
     *
     * @return Item's tier
     */
    @Override
    public int getTier(ItemStack itemStack) {
        return this.tier;
    }

    /**
     * Get the item's transfer limit in EU per transfer operation.
     *
     * @return Transfer limit
     */
    @Override
    public double getTransferLimit(ItemStack itemStack) {
        return this.maxPowerTick;
    }

}

@@ -1302,157 +1302,24 @@
 %22), 
-new IItemPropertyGetter() %7B%0A            @Override%0A            public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase
+(stack, worldIn,
  ent
@@ -1325,22 +1325,21 @@
 tityIn) 
-%7B%0A    
+-%3E %7B%0A
         
@@ -1386,20 +1386,16 @@
         
-    
 if (meta
@@ -1399,11 +1399,12 @@
 eta 
-%3C 3
+%3E 24
 ) %7B%0A
@@ -1423,20 +1423,16 @@
     
-    
 return 
-0
+1
 ;%0A  
@@ -1433,36 +1433,32 @@
  1;%0A            
-    
 %7D%0A              
@@ -1447,36 +1447,32 @@
   %7D%0A            
-    
 else if (meta %3C 
@@ -1473,12 +1473,12 @@
 eta 
-%3C 10
+%3E 17
 ) %7B%0A
@@ -1489,36 +1489,32 @@
             
-    
 return 
-1
+2
 ;%0A          
@@ -1511,34 +1511,26 @@
             
-    %7D%0A    
+%7D%0A
             
@@ -1547,20 +1547,16 @@
 eta 
-%3C 17
+%3E 10
 ) %7B%0A
-    
     
@@ -1566,39 +1566,35 @@
          return 
-2
+3
 ;%0A
-    
             %7D%0A  
@@ -1595,36 +1595,32 @@
   %7D%0A            
-    
 else if (meta %3C 
@@ -1621,12 +1621,11 @@
 eta 
-%3C 24
+%3E 3
 ) %7B%0A
@@ -1636,36 +1636,32 @@
             
-    
 return 
-3
+4
 ;%0A          
@@ -1658,34 +1658,26 @@
             
-    %7D%0A    
+%7D%0A
             
@@ -1703,39 +1703,17 @@
     
-    
 return 
-4;%0A                %7D
+0;
 %0A   

Fix ItemCEU textures.