Solved Stopping an item from breaking

Discussion in 'Plugin Development' started by pkt, Jul 24, 2013.

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

    pkt

    Honestly I didn't think it would be so hard to stop an item from breaking, and by breaking I mean the breaking animation. Like when you cancel the BlockBreakEvent, the item does the animation, but the actual item doesn't break. You can't cancel the PlayerItemBreakEvent. I tried this:
    Code:
        @EventHandler
        public void breaking(BlockBreakEvent event) {
            if (event.getPlayer().getItemInHand() != null) {
                ItemStack item = event.getPlayer().getItemInHand();
                if (item.getDurability() - (item.getType().getMaxDurability()) <= 1) {
                    item.setDurability((short) (item.getType().getMaxDurability() - 1));
                }
            }
            event.setCancelled(true);
        }
    this:
    Code:
        @EventHandler
        public void itemBreak(PlayerItemBreakEvent event) {
            event.getBrokenItem().setDurability((short) 250);
        }
    and this:
    Code:
        @EventHandler
        public void itemBreak(PlayerItemBreakEvent event) {
            event.getPlayer().setItemInHand(event.getBrokenItem());
        }
    but it still goes through the animation. I think it's a packet, but I'm not sure which one. Any information on this is appreciated. :)
     
  2. Offline

    Samthelord1

    You may want to change your code to check if its on a bit before breaking, then set back to full.
     
  3. Offline

    pkt

    to check if whats on?
     
  4. Offline

    Samthelord1

    On was a typo, to check if its a bit before breaking
     
  5. Offline

    pkt

    I did check if it's <= 1 , I didn't want to make it 2, but if I have to, I will
     
  6. Offline

    Drkmaster83

    I'm pretty sure Packet63WorldParticles is sent with packet.a = either tilecrack_*_* or iconcrack_*. I'm not exactly sure how this works, though.
     
  7. Offline

    pkt

    Do you know if you can cancel packets from being sent?
     
  8. Offline

    Drkmaster83

    I'm not too familiar with cancelling packets, only sending them. Sorry.
     
  9. Offline

    xTrollxDudex

  10. Offline

    pkt

    I have, but I don't know which packet is used for the item break...
     
  11. Offline

    xTrollxDudex

    pkt
     
  12. Offline

    pkt

    Yea, but I'm talking about the Packet Enum types from ProtocolLib... :p
     
  13. Offline

    wadu436

    YYou can also set it to full durability when the item durability is decreased.
     
  14. Offline

    xTrollxDudex

    pkt
    Packets.Server.WORLD_EVENT
     
  15. Offline

    pkt

    Thanks! That was the right one :D
     
Thread Status:
Not open for further replies.

Share This Page