Solved I want to change the durability on an item when right clicking

Discussion in 'Plugin Development' started by MRANDOM, Mar 26, 2021.

Thread Status:
Not open for further replies.
  1. Offline

    MRANDOM

    Ive got everything up till the durability thing, I was going to use .setdurability but thats depreciated. so what's the new form of writing this?
     
  2. Offline

    KarimAKL

    @MRANDOM As by the deprecation message:
     
  3. Offline

    MRANDOM

    @KarimAKL I have item meta set up as a variable "meta"
    but when ever I do meta.setdamage(9); it goes red because setdamage isnt a method. I also made sure my build path jar thingy is up to date.
     
    Last edited: Mar 27, 2021
  4. Offline

    KarimAKL

    @MRANDOM You have to cast ItemMeta to Damageable (check if it is actually an instance of it first), and then you can access the methods.
     
  5. Offline

    MRANDOM

    @KarimAKL it says it cannot be cast, so damage just doesnt work on items? Cause that is what this comeback to, I just want to make it take 1 durability every time it is in use

    edit I got the cast using. Damageable pp = (Damageable) item.getItemMeta();
    pp.setdamage(pp.getdamage() + 1);

    but this doesnt actually make the pic take any damage.

    Final edit:
    I got it boys I for got to put in item.setItemMeta(pp); at the very end
     
    Last edited: Mar 27, 2021
  6. Offline

    davidclue

    Code:
    import org.bukkit.inventory.meta.Damageable;
    
    if (((Damageable) itemstack.getItemMeta()).getDamage() >= itemstack.getType().getMaxDurability())
        itemstack.setAmount(0);
    else {
        ItemMeta meta = itemstack.getItemMeta();
        ((Damageable) meta).setDamage((int) (((Damageable) meta).getDamage()+e.getDamage()+1));
        itemstack.setItemMeta(meta);
    }
    EDIT: I used the wrong import my bad but I fixed it so it works now
     
    Last edited: Mar 29, 2021
Thread Status:
Not open for further replies.

Share This Page