MaterialData or durability?

Discussion in 'Plugin Development' started by Muizers, Apr 10, 2013.

Thread Status:
Not open for further replies.
  1. What do

    short ItemStack.getDurability()

    and

    byte ItemStack.getData().getData()

    have in common, and when should I use which one? What do they represent? I need the EXACT difference between these two.

    Thanks in advance :)
     
  2. Offline

    chasechocolate

  3. Offline

    ConflictRealms

    how do you not know what getDurability() means.. it gets the items durability
     
  4. Muizers
    First, they're the same value.

    getDurability() gives you the actual data from the item, it's a short because potions have values way higher than byte can support (I belive it's -126 to 127 ?), it also doesn't create any objects when used since it's a direct value, as opposed to getData() which (if not already created) it will create the MaterialData object for that item type.

    The getData() from MaterialData can give you false values because it returns a byte and it can hold a much smaller value than short, so by using that on a potion would give you invalid data value since it can't store the big values that potions use.

    MaterialData has extensions like Lever, Wool, Door, Tree (logs), etc which you can use to help you set the data value of blocks when setting them as on, off or setting their attach direction... and it can also be useful for items to set species (like for trees, leaves, etc).
    Basically it's an API friendly class to set stuff to items rather than directly setting data values, but it may get confusing.
    I'm not really sure the *right* way of getting one of those extensions... I guess you could get instanceof and cast but not sure.

    For known subclasses see:
    http://jd.bukkit.org/rb/apidocs/org/bukkit/material/MaterialData.html
    http://jd.bukkit.org/rb/apidocs/org/bukkit/material/DirectionalContainer.html
    http://jd.bukkit.org/rb/apidocs/org/bukkit/material/SimpleAttachableMaterialData.html
    http://jd.bukkit.org/rb/apidocs/org/bukkit/material/ExtendedRails.html
    And there may be more... would be easier to browse them in your IDE.

    So yeah, use whatever you think it's easier for you, both are valid but like I said for the byte one, it has limitations due to the limits of byte.
     
    AmShaegar likes this.
  5. Thanks for your post Digi ! :) That was exactly what I needed, I've now got the info to continue on trying to edit potions and dyes with the same script for example.

    Thanks a lot, you addressed the problem directly :)
     
Thread Status:
Not open for further replies.

Share This Page