Changing/Removing mob sounds?

Discussion in 'Plugin Development' started by MineCrypt, Jan 16, 2013.

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

    MineCrypt

    Is there a way to remove the sounds or change the sounds of a mob using bukkit? With a certain mob you spawn make it so it doesn't have the normal mob sounds?
     
  2. Offline

    Miner_Fil

  3. Offline

    MineCrypt

    Well do you know the way to do so? Does it require editing the zombie, or a listener?
     
  4. Offline

    Miner_Fil

    I've never done it so i don't know
     
  5. Offline

    zRations

    I'm guessing you would have to create your own custom mob Entity if you can remove their sounds.
     
  6. Offline

    MineCrypt

    How do you do that?
     
  7. Offline

    chasechocolate

  8. Offline

    fireblast709

    no one thought of ProtocolLib? (you could block the sound packets)
     
    Comphenix likes this.
  9. Offline

    Comphenix

    Creating a custom zombie class is probably the way to go, but there is an alternative method that has some other advantages:
    • It's very simple to and short - you only need to add a dependency to ProtocolLib.
    • You can make the same mob emit different sounds for different players.
    • It automatically applies to every mob
    However, there are some problems:
    • You don't get a direct reference to the original mob that made the sound. You have to look up the mob based on the location.
    • It works best if the new mob sounds should be generated under similar circumstances. It's harder to generate sound when the zombie doesn't normally do it.
    In any case, here's how you do it (with PacketWrapper):
    Code:java
    1.  
    2. public class ExampleMod extends JavaPlugin {
    3. @Override
    4. public void onEnable() {
    5. final ProtocolManager manager = ProtocolLibrary.getProtocolManager();
    6.  
    7. manager.addPacketListener(
    8. new PacketAdapter(this, ConnectionSide.SERVER_SIDE,
    9. Packet3ENamedSoundEffect.ID) {
    10. @Override
    11. public void onPacketSending(PacketEvent event) {
    12. Packet3ENamedSoundEffect named = new Packet3ENamedSoundEffect(event.getPacket());
    13.  
    14. // Just rename all zombie sounds to skeleton sounds
    15. named.setSoundName(named.getSoundName().replace("mob.zombie", "mob.skeleton"));
    16. }
    17. });
    18. }
    19. }
     
  10. Offline

    MineCrypt

    Alright there is one thing though, I don't want it to apply to every mob just certain ones, how would I do that?
     
  11. Offline

    Comphenix

    It depends - is it okay if it only applies to zombies? Then you can do something like what I did above, and only modify the zombie sounds.

    However, if you're trying to create a single "special" mob, you might want to look at any of the NPC libraries out there, or create a custom NMS entity yourself. It's difficult to apply the ProtocolLib approach above to a single mob.

    Still, it might be possible if you use the coordinates the named sound effect and search for the closest mob. That should allow you to find which mob generated the given sound. Just keep a track of the mobs you're modifying, and find the closest (within a certain distance) to the sound effect. If you're only doing this on a small number of mobs, it shouldn't cost too much in terms of performance.
     
Thread Status:
Not open for further replies.

Share This Page