Solved Item Durability

Discussion in 'Plugin Development' started by VenamousV, Feb 21, 2014.

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

    VenamousV

    I am trying to make a plugin that, when a player breaks a snow block it sets the durability of the item in his hand to full. I can't seem to get it to work though, any help would be greatly appreciated.
    Code:java
    1. @EventHandler
    2. public void onBreak(PlayerItemBreakEvent e){
    3. Player p = (Player) e.getPlayer();
    4. if(e.getBrokenItem().getType() == Material.SNOW_BLOCK){
    5. p.getItemInHand().setDurability(p.getItemInHand().getType().getMaxDurability());
    6. }
    7. }
     
  2. Offline

    SourceForums

    VenamousV
    What isn't working? The whole thing? I believe that PlayerItemBreakEvent is the wrong event for this.
     
  3. Offline

    VenamousV

    Well when I break the snow it just disappears, and my item doesn't gain any durability, any idea what event may work? SourceForums
     
  4. Offline

    xTigerRebornx

    VenamousV You are using the wrong event, the event you are using is for when a tool breaks (i.e. has no durability left), you want the BlockBreakEvent.
     
  5. Offline

    VenamousV

    Okay now that I changed the event to BlockBreakEvent when I break the snow both the snow block and the item in my hand disappear. xTigerRebornx
     
  6. Offline

    Gater12

    What do you have now?
     
  7. Offline

    VenamousV

    Code:java
    1. @EventHandler
    2. public void onBreak(BlockBreakEvent e){
    3. Player p = (Player) e.getPlayer();
    4. short md = p.getItemInHand().getType().getMaxDurability();
    5. if(e.getBlock().getType() == Material.SNOW_BLOCK){
    6. p.getItemInHand().setDurability(md);
    7. }
    8. }
    Gater12
     
  8. Offline

    xTigerRebornx

    VenamousV Set the durability to 0, Minecraft's durability is weird in the sense that you'd have to do everything reverse in a way (like to take away durability, you need to add, and vise-versa)
     
  9. Offline

    VenamousV

    Okay the item durability is working now, do you know how to make it so the snow block doesn't disappear after it is broken? xTigerRebornx
     
  10. Offline

    Luke_Lax

    Simply do:
    Code:java
    1. p.getEquipment().getItemInHand().setDurability((short) Integer.MAX_VALUE);
     
    97WaterPolo likes this.
  11. Offline

    VenamousV

    I got that to work already, My problem now is that the snow block that is mined to set the item durability to full disappears. Can you help with that? Luke_Lax
     
  12. Offline

    xTigerRebornx

    VenamousV Cancel the event, and the block wont be broken
     
  13. Offline

    VenamousV

    I want it to break, I want to be able to pick it up after I break it but then it doesn't have a dropped entity when it's broke, it just disapears xTigerRebornx
     
  14. Offline

    xTigerRebornx

  15. Offline

    Gater12

    VenamousV
    Then drop an item entity in the place of the broken block's location.
     
Thread Status:
Not open for further replies.

Share This Page