How to change item damage

Discussion in 'Plugin Development' started by Puschie, Mar 19, 2013.

  1. Offline

    Puschie

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Hello,
    im new to plugin programming with java. After working on my first plugin, i need to change the damage of some items.
    So i think it should be work via "EntityDamageByEntityEvent", but i have some question.
    1. How can i check if that item is one of my items( ItemMeta ? )
    2. How do i handle the damage( has each item his own listener or casting ItemStack to my item class ? )
    3. Which priotity do i need for this ? it have to work on 100% of all attacks, so i think monitor ?

    there is a list of little plugins which are open source to lern ?
    Thx for reading

    This post has been edited 1 time. It was last edited by TnT Mar 19, 2013.
  2. Offline

    Barinade

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  3. Offline

    Puschie

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    ????
    nice link,
    but what is with my questions ?

    This post has been edited 2 times. It was last edited by TnT Mar 19, 2013.
  4. Offline

    raGan.

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    As you say, you can set item meta and check it later, but it's not persistent through restarts. You can add little bit of lore to it that identifies it as yours.
    EntityDamageByEntityEvent happens when one entity is gamaged by another (e.g. Creeper->Player, Player->Creeper, Arrow->Zombie). I think there's no event that fires when item is damaged, you will need to check multiple events depending on what you want. If you do not want to modify event contents in any way, then MONITOR is for you. To get plugin sources just look into resources section for code snippets or browse dev.bukkit and look for github links. Some plugins also provide source inside the JAR file.
  5. Offline

    Puschie

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    ok, but how can i get the damage value ?
    currently i have a Class Item, that extends ItemStack
    so if i identify that the hitting item is my, i should can cast it back into Item.
    But its fails
    All open source projects i found read every time the damage value new, and that is crape...
    also use all projects only the basics items, not own items

    This post has been edited 2 times. It was last edited by TnT Mar 19, 2013.
  6. Offline

    raGan.

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Why would you need to extend itemStack ? Anyway, if your class extends itemstack then you can call setItem() directly for your class.
  7. Offline

    Puschie

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    what do you mean ?, where should i call setItem?
    i extend itemStack to share values with the items, i
    thought that i can use them later( while dmg calc etc.)

    The Thing is, it should be possible to store more than 1000 items, and all with custom values( f.e. damage and armor ). If i have to acces every attack the values, the i would store the values in a HashArray. But a HashMap with a size of 1000 would have long manage time. Any idears ?

    This post has been edited 3 times. It was last edited by Puschie Mar 20, 2013.
  8. Offline

    raGan.

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    My apologies, I meant setDurability(). You should look up how HashMap works and use it to your advantage. It's perfect for storing big amounts of values.

    This post has been edited 1 time. It was last edited by raGan. Mar 20, 2013.
  9. Offline

    Puschie

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    ^^ i have found FastMaps for this
    http://javolution.org/target/site/apidocs/javolution/util/FastMap.html
    it has much better performance for this.

    setDurability set only the durability or not ? didnt know what all of you mean with this

    But now im think about how to hold the Map updateted, maybe i will check on each item in hand change if the waepon is a custom one, and the identify would i make via a value, mutiple all values of that item, so i can detected if there is a custom waepon with old values which has to be updated after database item change.

    This post has been edited 1 time. It was last edited by Puschie Mar 20, 2013.

Share This Page