How to properly register electric tool in IC2V2

  • Here is a code:

    Display Spoiler

    public class IHLMod {
    public static IHLMod instance;
    public static Item ic2_handpump = (new IHLHandPump().setUnlocalizedName("handpump"));
    public static Item ic2_handpump_discharged = (new IHLHandPump().setUnlocalizedName("handpump_discharged"));

    @EventHandler
    public void preInit(FMLPreInitializationEvent evt) {
    MinecraftForge.EVENT_BUS.register(new IHLEventHandler());
    GameRegistry.registerItem(ic2_handpump, "Handpump");
    GameRegistry.registerItem(ic2_handpump_discharged, "Discharged handpump");
    }


    Display Spoiler


    public class IHLHandPump extends Item implements IElectricItem {

    public static int maxCharge = 10000;

    @Override
    @SideOnly(Side.CLIENT)
    public void registerIcons(IIconRegister par1IconRegister)
    {
    this.itemIcon = par1IconRegister.registerIcon(IHLModInfo.MODID + ":itemElectricHandpump");
    this.setMaxDamage(2);
    }

    public IHLHandPump()
    {
    super();
    this.maxStackSize = 1;
    this.setCreativeTab(CreativeTabs.tabMisc);
    }


    @Override
    public boolean canProvideEnergy(ItemStack itemStack) {
    return false;
    }

    @Override
    public Item getChargedItem(ItemStack itemStack) {
    return IHLMod.ic2_handpump;
    }

    @Override
    public Item getEmptyItem(ItemStack itemStack) {
    return IHLMod.ic2_handpump_discharged;
    }

    @Override
    public int getMaxCharge(ItemStack itemStack) {
    return maxCharge;
    }

    @Override
    public int getTier(ItemStack itemStack) {
    return 1;
    }

    @Override
    public int getTransferLimit(ItemStack itemStack) {
    return 0;
    }

    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
    ElectricItem.manager.discharge(par1ItemStack,40,1,false,false);
    return par1ItemStack;
    }
    }

    And it seems, that in creative tab both items are have no charge. On click with "charged" version of item it becomes discharged instantly.

  • - I'd use only 1 item, not 2 unless there's special requirements e.g. for stacking -> getChargedItem and getEmptyItem are the same.
    - getTransferLimit returning 0 makes it useless, you can't charge it then. It's the max amount of eu to charge per tick.
    - setMaxDamage(2) is a bit low, that won't allow displaying the charge level well using the damage bar, ic2 uses 27
    - for the creative page, you'll have to add your item manually, once discharged and once fully charged. You have to charge it yourself while doing so. To implement this override getSubItems and add 2 stacks of this item after passing each through ElectricItem.manager.charge with charge = 0 and Integer.MAX_VALUE (or maxCharge, same effect) respectively. Set ignoreTrasnferLimit to true in those charge calls.
    - Don't instantiate your items like that. It's recommend to do so in preInit, not while declaring them, which would create them way too early.

    Extending ElectricItem isn't required/recommended, it just needs to implement IElectricItem properly