Damage Values

Discussion in 'Plugin Development' started by rob4001, Aug 11, 2011.

Thread Status:
Not open for further replies.
  1. Hey i have a material but i would like to get the damage value

    Code:
    Material mat;
    
    //i can get my  ID easily using
    
    mat.getID();
    
    //how do i get the damage value?
     
  2. Offline

    bergerkiller

    The item 'damage' value is not in the Material, it is an attribute for Item(Stack)s.
    Code:
    ItemStack item = new ItemStack(Material.WOOL, 64);
    short dam = 8;
    item.setDurability(dam);
    dam = item.getDurability();
    For blocks you probably have to use getData() and/or getState()/or getState().getData()

    For blocks you probably need to cast the MaterialData to a certain type. Example: wool
    Code:
    Block b = event.getClickedBlock();
    if (b != null && b.getType() == Material.WOOL) {
        Wool w = (Wool) b.getState().getData();
        DyeColor color = w.getColor();
    }
    Or try to convert the block to an ItemStack (toItemStack()) and get the durability value from that.
     
  3. But im using this to get my material

    Code:java
    1.  
    2. MaterialData dat = new MaterialData(id, data);
    3. return dat.getItemType();
    4.  


    Im not trying to get damage values but item types such as 17:2

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 18, 2016
  4. Offline

    nisovin

    Are you using Material or MaterialData? Material does not have data, but MaterialData has a getData() method. Other objects like Block and ItemStack also have a getData() method. But Material itself is the type, so it doesn't have data.
     
Thread Status:
Not open for further replies.

Share This Page