Creating your own Electric Item

  • Hello,


    I've been trying to implement Electric Shears for my Unidye mod but I am having trouble. Currently with the 'Electric' part of all this, although by looking at the class IteamShear and EntitySheep let me know that implementing the shear function to my custom item might be a little harder than what I have done until now.
    But now, to my problem:
    First of all, I am still using Minecraft 1.5.2 and IC2/IC2 API on version 1.116.


    I have pretty much followed this tutorial by AGKz about making your own electric Item and it works pretty well so far, it drains EU by a dummy function (using 100 EU on Right Click with the Item in your active Slot) and recharges on its assigned transferLimit, but it seems the bar on the icon in your hotbar does not seem to update. I have looked a bit into the item part of the api and did not really find what I was looking for. How can I force updates to the bar so it actually shows the current EU stored? (Note: There is also no text on the current Charge Status when hovering over the icon.) I am guessing it will have to do something with metadata like the electricWrench uses, but I am a little lost.


    I uploaded the ItemElectricShears class here. Any help would be gladly appreciated!

  • 1) Don't forget to register your item in MinecraftForge tooldict.
    Just add this:

    Code
    MinecraftForge.setToolClass(this, "shears", 2);


    To your item's constructor.
    2) Your onItemRightclick is incorrectly coded. You check for !world.isRemote after you drain energy from your electric tool, however you MUST do it the other way around.
    Better solution:


    3) If it still doesn't appear to drain energy, take off your lappack/batpack. ElectricItem.manager.use() checks for Lappack/Batpack existence before draining energy from electric item and if lappack/batpack exists and has enough energy, it drains energy from batpack.


    4) Some basic tips on modding, solution for problems you will most likely struggle with in near future:
    1. ALWAYS check for !world.isRemote/!FMLCommonHandler.instance().getEffectiveSide().isClient() (if you don't, it will do SO weird things that you won't even be able to tell what's going on)
    2. Don't mess with GUIs without making your mod @NetworkMod (if you do not do this... once again weird things will happen)
    5) Highly recommend looking at https://github.com/mak326428/L…em/ItemBasicElectric.java
    6) Why do you need to add electric shears? Chainsaw already has that functionality!

  • 1) I do this in the main class of my mod, in the load method
    2) Corrected.
    3) I did not use a Batpack in my test world, but silly me was in creative mode all along. In Survival it drains properly. Now it works correctly.


    4.1) My mod so far only registers items, loads recipes, registers icons, has some constructors and stuff to do with the config file in the preinit method of my main class..these don't need the !world.isRemote check, do they?
    I see why other methods, such as destroying a block or shearing a sheep would.
    4.2) I really have not planned to take on new machines or GUI as long as I don't know what I am doing (well I won't 100% know what I am doing on my first try, but you know what I mean), will look into a tutorial and source code and mess a bit with it to see what everything does.
    5) Will use it for other electric items in the future, thanks.
    6) Well now I feel like an idiot always crafting my shears :D Then I might need to add a little goodie, such as a random chance of dropping Unidye when shearing a sheep ;)


    Thanks for your reply and help!


    P.S. Oh, one question: If both world.isRemote and FMLCommonHandler...isClient() do the same thing, why use the longer one? There must be a difference :P


  • @Why use longer form:
    There is no difference between them at all. (like at all), however there are some situations where you don't have an access to World, and that's where you want to use it.
    If it's too long for you, just create a simple utility method your modclass.

    Code
    public static boolean isSimulating() {
         return !FMLCommonHandler.instance().getEffectiveSide().isClient();
    }
  • One last thing: How do I implement a decription to the item that shows the current charge, like the elctric Wrench does? (like 12000/12000 EU, then 11500/12000 EU)

  • Then something messed that up, because it isn't. The Shears have a durability bar which gets depleted by the current dummy method but there is no tooltip when hovering over its icon. Also, the tool is destroyed when its durability is depleted.
    I took a quick look at IC2's coding of the ElectricWrench and did not notice a significant difference or any methods which hint that I have forgotten something.


    And good too see Greg joining the mortals :P


    EDIT: The second problem has most likely to do with me messing around with the methods of ItemShear, so nevermind. The only problem is the Tooltip.

  • You dont need to add that Tooltip. It is added automatically.


    You forgot to say that it does so when NEI IS INSTALLED.


    Then something messed that up, because it isn't. The Shears have a durability bar which gets depleted by the current dummy method but there is no tooltip when hovering over its icon. Also, the tool is destroyed when its durability is depleted.
    I took a quick look at IC2's coding of the ElectricWrench and did not notice a significant difference or any methods which hint that I have forgotten something.


    And good too see Greg joining the mortals :P


    EDIT: The second problem has most likely to do with me messing around with the methods of ItemShear, so nevermind. The only problem is the Tooltip.

    He is mortal too BTW :P
    That is what you think. ~Greg
    No! That's not what I think! That's what nature thinks!
    According to statistics, if I take the times I died, and put them together with the times I didn't die, the probability of Death decreases every Day I stay alive. Also only 93% of all People died so not everyone dies. :P
    Wrong Math! Waaaaaay wrong! *shakes head in disapproval*
    The Math was right, just the interpretation could need some more citation

  • Then something messed that up, because it isn't. The Shears have a durability bar which gets depleted by the current dummy method but there is no tooltip when hovering over its icon. Also, the tool is destroyed when its durability is depleted.
    I took a quick look at IC2's coding of the ElectricWrench and did not notice a significant difference or any methods which hint that I have forgotten something.


    And good too see Greg joining the mortals :P


    EDIT: The second problem has most likely to do with me messing around with the methods of ItemShear, so nevermind. The only problem is the Tooltip.


    Ah, so that's why it doesn't show when testing it in my workspace. Thanks for your help you two :)


    http://www.minecraftforum.net/…62-smp-chickenbones-mods/
    Read "For Mod Developers". You're going to be extremely happy (at least I was).