ElectricItem.manager.discharge

    • Official Post

    This is probably caused by the code getting executed on the client side, then the cooldown timer is set and then it's not executed on the serverside anymore, because the cooldown timer isn't done yet (it just got set on the clientside). You may want to add a "!world.isRemote &&" to the beginning of your if-statement to make it only execute on the serverside. However your timer mechanism will most likely fail, if multiple people on the same server use the tool at the same time.

    You should also avoid using floats for anything time-related, because you lose precision.

  • !world.isRemote &&

    because of no experience in minecraft, i don't know when i need to use code only on serverside and when only on client, your solution makes energy discharging as it need to be, but now it doing nothing (don't summoning entity)

    However your timer mechanism will most likely fail, if multiple people on the same server use the tool at the same time.

    By mine knowledges of minecraft possibilites from code view it's best i can write) if you know better system of cooldown, can you explain it?

    • Official Post

    because of no experience in minecraft, i don't know when i need to use code only on serverside and when only on client, your solution makes energy discharging as it need to be, but now it doing nothing (don't summoning entity)

    You should basically do all the logic and world changing things on the server side (!world.isRemote) and the visuals on the client (world.isRemote).

    If you entity doesn't show up now, where you have the code only executed on the serverside, it's probably not syncing properly (I don't know much about entities myself, but random guess: did you register your entity properly?).

    By mine knowledges of minecraft possibilites from code view it's best i can write) if you know better system of cooldown, can you explain it?

    You should rely on the tick counter rather than the system time and use a per-player rather than per-item counter (itemstack nbt would probably work as well). But don't know a full system that does that right now.

  • You should rely on the tick counter rather than the system time and use a per-player rather than per-item counter (itemstack nbt would probably work as well). But don't know a full system that does that right now.

    you mean something like "TicksExisted"? can't find something like this

    You should basically do all the logic and world changing things on the server side (!world.isRemote) and the visuals on the client (world.isRemote).

    If you entity doesn't show up now, where you have the code only executed on the serverside, it's probably not syncing properly (I don't know much about entities myself, but random guess: did you register your entity properly?).

    register item too easy for doing it not properly)


    Item staticGun = new ItemStaticGun();
    GameRegistry.registerItem(staticGun, "StaticGun");

    and i separate logic and view part, now it's discharging properly, buuut.. now changing charge didn't displaying (line under item don't gets shorter)

    new, separated code: https://yadi.sk/i/oE_e8Zvf3H8Sp5

  • Try either discharging it on both sides or sync the inventory after discharging.

    Already tried first, then it discharging, but line show true value at (i think) one tick and come back to full filled line on next tick.

    about sync, i don't know how to do it and tried find something about it in possible methods (curPlayer.*), but didn't find anything helpful

    • Official Post

    I don't think synchronization can cause much of an issue there, you'll have to use your IDE's debugger to monitor what's happening. Normally the item stack's metadata and nbt tag are being adjusted by the electric item manager.


    For the sphere the collision doesn't matter, you just need an entity with a custom renderer. In Minecraft collision shapes are always separately defined from the model geometry for rendering.

  • Ok, I'll try to debug when comeback home, but I don't know how it helps because I don't how IC2e mechanics works

    About shape: I still haven't work with minecraft much, so I can't even imagine how to do something you discribed, can you give examples? With comments will be best

  • Question. Why dont you store the LastTime used in the ItemNBT?

    Then you compare the current time with the lastTime item used. So you can compare it better. And that allows you also to support fakePlayers.

  • Question. Why dont you store the LastTime used in the ItemNBT?

    Then you compare the current time with the lastTime item used. So you can compare it better. And that allows you also to support fakePlayers.

    i don't even know what it NBT in minecraft and how it works, but i founded my cooldown system (i don't know why) works on every player gun, so if player will shoot from this gun, take other this gun (have 2 of this in inventory) and try to use second, he can't, cooldown is static for every gun of this type (don't know how about different players, but for one player it works like this)

  • ItemNBT is provided in the ItemStack. So you have per ItemStack a cooldown (in other words infinte cooldowns)

    The downside with your 1 Person can only do that is what if you play on a server? That means someone could setup a clock with the item that gets automaticly recharged and ensures that nobody on the server can use that tool. Even worse someone could build a contraption which ensures that he can control who is using the tool and who not. Which is kind of a problem.

    If you make a cooldown bind it to the item and not the entire server.


    to give you infos:

    ItemNBT = ItemStack.getTagCompound().

    That can be null so make a != null check before you make something.


    And a NBTTagCompound is basically a hashMap. you have your Key and you get the value from that.

  • I read something from this site: https://bedrockminer.jimdo.com…etadata-blocks-and-items/

    and, as i understand with my knowing of Eng, it's like item item, maded from one class have different states, but i just need to save somewhere "long lastTimeUsed" to every item, so different instances of my item in inventory(ies) of player(s) will have different value

    for this: if one player crafts two of this item, use one (and it will be on cooldown, so he can't use it at last "float cooldown" seconds), he can switch chosen slot and use another one and it will work (simply i was thinking item's in inventories working like instances of objects in OOP languages, like C#)

  • Hm.. okay, understand, but still don't understand what is NBT and how i can work with it (yes, i read from site, NBT it's something, that saves in damage line of item or something like this, but nothing else and this give me nothing)

  • The problem is still relevant

    i still can't understand, how i can work with itemStack.writeToNBT and itemStack.readFromNBT

    first i think NBT it's something like universal array of fields, like every itemStack have own NBT and we can just insert in this NBT new field with name FIELDNAME (itemStack.writeToNBT("FIELDNAME", FIELDNAME_value);), but we can't, at least i can't understand why WRITE returns NBTTagCompound and why READ don't returns

    my code (just tried to understand, by writing algoritm bases on my thoughts): https://yadi.sk/i/_ivrok6U3HF7j2

    • Official Post

    itemStack.writeToNBT() puts the ItemStack on NBT to be saved to disk. itemStack.readFromNBT() reads it again (from disk). You do not want to use these functions. What you do want to use is itemStack.stackTagCompound (make sure to do a null check before you use that and initialize it if it's null). THERE you can store and load your values.

    There are quite good tutorials out there on how to use NBT. You can find them using google.

  • itemStack.writeToNBT() puts the ItemStack on NBT to be saved to disk. itemStack.readFromNBT() reads it again (from disk). You do not want to use these functions. What you do want to use is itemStack.stackTagCompound (make sure to do a null check before you use that and initialize it if it's null). THERE you can store and load your values.

    THANKS, no, really, thanks a lot! first, i make what i want, second (that really important) i understand how i works! my thought was really near to real situation, i just used what i don't need to use! thanks again, because now i can use this anytime i need it))