Tool Break Sound Effect

Discussion in 'Plugin Development' started by Limeth, Aug 11, 2012.

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

    Limeth

    Hello, I've been wondering, how to create a tool break sound effect. I know it's gotta be something with sending packets, but I can't seem to understand how should I build it without example. (You know, I like to know from clear examples)

    So I am asking you, would you show me how to do it, please?

    Limeth
     
  2. Offline

    agd555

    How to create? You mean how to play that sound effect for player? If yes, use Player.playEffect.
     
  3. Offline

    Limeth

    agd555
    Yes, I mean play, but there is no "ToolBreak" Effect listed.
     
  4. Offline

    Hannes103

    right i think you can't play ToolBreak Effects but you can player a Block break effect
    (
    Code:
    player.getWorld().playEffect(player.getLocation(), Effect.STEP_SOUND, 1);
    )
    or you can create a tool and desroy it do play the effect
     
  5. Offline

    Courier

    I'm pretty sure you'd need to give the player a tool then break it; the tool-break sound is only generated client side when it thinks a took breaks.
     
  6. Offline

    Limeth

    Courier
    But how should I break the tool?
     
  7. Maybe trigger a PlayerItemBreakEvent? I would imagine that is how the client realizes that it broke a tool. If not, then adding a tool to the hotbar, getting the slot number, getting the slot, setting the durability to 0 might do the trick.
     
  8. Offline

    Limeth

    Im_Zeus
    Would you mind posting me an example, please?
     
  9. Offline

    RingOfStorms

    Well, store item slot 9 in the cache, put a pick or something there, set the pick's dura to zero, itbreaks, restore the previous item.

    Limeth
     
  10. PlayerItemBreakEvent event = new PlayerItemBreakEvent(player, null);
    player.getServer().getPluginManager().callEvent(event);

    I would rather him try the event first. Would be much more simple.

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

    Limeth

    Code:java
    1. PlayerItemBreakEvent eventa = new PlayerItemBreakEvent(((Player) event.getEntity()), null);
    2. ((Player) event.getEntity()).getServer().getPluginManager().callEvent(eventa);

    Doesn't seem to work for me, I'm calling it before the player dies.

    Code:java
    1. ((Player) event.getEntity()).getInventory().setItem(9, new ItemStack(Material.WOOD_PICKAXE, 1));
    2. ((Player) event.getEntity()).getInventory().getItem(9).setDurability((short) 0);

    Doesn't seem to work either.

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

    r0306

    Limeth
    I think the durability goes up instead of down so 0 would actually be restoring the item. Try setting it to 100 or something higher instead.
    Code:
        ((Player) event.getEntity()).getInventory().setItem(9, new ItemStack(Material.WOOD_PICKAXE, 1));
        ((Player) event.getEntity()).getInventory().getItem(9).setDurability((short) 100);
     
  13. Don't put a Player cast on an Entity.
    Use event.getEntity().getServer().getPlayer()
     
  14. Offline

    Firefly

    Or cast it to Player after you check the Entity is an instance of Player.
     
  15. Offline

    Limeth

    Firefly
    Im_Zeus
    r0306
    Code:java
    1. ((Player) event.getEntity()).getInventory().setItem(9, new ItemStack(Material.WOOD_PICKAXE, 1));
    2. ((Player) event.getEntity()).getInventory().getItem(9).setDurability((short) 60);

    This is what I did. The code still doesn't work. Help :(
    60 is the number of uses for wooden tools.
     
  16. Offline

    Firefly

    I'm guessing it's because you're manually setting the damage on it, and the sound only plays if the player uses its last use.
     
  17. Offline

    Limeth

    Firefly
    Does the effect play when an armour piece is broken?
    If not, how should I do it then? (It works on a.mcctf.com, when you get headshotted)
     
  18. Your solution is more than likely going to use the Event. Events are what triggers actions between the client and server and vice versa.
    Limeth
     
  19. Offline

    Limeth

    Would you show me a working example, please? I'm pretty new to this.
     
  20. Offline

    rjVapes

    This requires linking against CraftBukkit and minecraft, but will add a lot of flexibility to your case:
    Code:
    String sound = "random.break";
    Packet62NamedSoundEffect packet = new Packet62NamedSoundEffect(sound, player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), 1.0F, 1.0F);
    ((CraftPlayer)player).getHandle().netServerHandler.sendPacket(packet);
    
     
  21. Offline

    Firefly

    Good to know... Where do you find a list of the possible sounds you can send?
     
  22. Offline

    rjVapes

    .minecraft/resources/newsound

    I updated the call a little. The last two floats are volume/pitch. Pitch also lengthens/shortens the duration for obvious reasons. I'm not sure yet how to call different effects that are indexed, for instance random.explode, there is an explode1.ogg, explode2.ogg, etc.

    Also I'm a little unsure when these sounds are actually populated, as I just did a fresh install of minecraft on another computer and there are far less sounds on that client (they seemed to stream down as I was playing, I guess this has to do with how minecraft client is installed). I haven't attempted to play sounds that don't exist on the client to see their result.

    It seems the indexed sounds are just randomly played. If you play mob.wolf.growl over and over you eventually end up getting the various ones. It doesn't seem there's a way to call any specific one currently, but it's possible I just haven't found how yet.

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

    Firefly

    Possibly the packet constructor takes an extra parameter (Similar to playEffect's method parameter) for a "data value" that acts as a differentiation between different sounds of the same "type."
     
  24. Offline

    rjVapes

    Firefly I just saw the one constructor, that was string, double, double, double, float, float. So I guess at least currently it's intended to just play ones with numbers after them randomly. Maybe they'll add something else at some point, but just being able to do this adds a lot of options. You can even play note block sounds, and adjust the pitch of everything, so... lots of possibilities.
     
Thread Status:
Not open for further replies.

Share This Page