Call Explosion Sound

Discussion in 'Plugin Development' started by xtr4xtr3m3, Jul 2, 2011.

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

    xtr4xtr3m3

    I want to make a plugin for OP`s which allows you to call Fake Explosions (no damage on blocks are made, but the players near will hear an explosion sound, as if a tnt exploded the block the op was standing). i looked through the APIdocs, but dont found anything usefull. do i have to create a tnt, make it explode, and cancel the explosion?
     
  2. There is packet called Packet60Explosion, which sends an explosion-packet to a player (and makes the sound play).
    If you have never worked with packets:
    The constructor for the packet:
    Code:
    Packet60Explosion packet = new Packet60Explosion(double x, double y, double z, float size, Set destroyedBlocks);
    x/y/z are the coordinates where the explosion should take place. Use the player's location to get even volume/balance.
    size is the size of the explosion. It doesn't matter for only the sound, set it to 0.
    destroyedBlocks is a Set of blocks that were destroyed by the explosion. Set to null or pass in an empty HashSet to have it take no effect.

    Then, you can send the packet to the player using the following code:
    Code:
    ( (CraftPlayer)ply ).getHandle().netServerHandler.sendPacket(packet);
    Note that you will have to add craftbukkit.jar to your Build Path (just like you did with bukkit.jar) in order to have access to CraftPlayer and packets.


    Letting tnt explode and cancelling the event wouldn't send this packet to the players, so they wouldn't see or hear it (sometimes it does, it might be or have been a bug).
     
  3. Offline

    Shamebot

    I think not cancelling the event but clearing the list of blocks would work.
    @Bone008 The set isn't a set of blocks, but of ChunkPosition.
    @xtr4xtr3m3 Since you want to send it to more than one player you can either iterate through all players and send it to all players within a certain radius (you can see explosions in a radius of 8, dunno how it's for sounds) or have a look at the sendAll method in my Rocket plugin: https://github.com/Shamebot/Rocket/blob/master/src/main/java/shamebot/rocket/Smoke.java#L68
     
  4. Well, means pretty much the same. With "block", I didn't mean the Block-class but ... well just a block. ChunkPosition represents the coordinates of a block.
    The decompiled packet properties (MCP) are called like that:
    Code:
        public double explosionX;
        public double explosionY;
        public double explosionZ;
        public float explosionSize;
        public Set destroyedBlockPositions;
    And Generics aren't added in ...
    So I just wrote block. But you're right, it's Set<ChunkPosition>.


    And this method is safer than creating an explosion and empying it. I think I read about a bug that would drop doors/torches/etc. even if the list of destroyed blocks is clear. Additionally, you couldn't have it equally sounding for every player.
     
  5. Offline

    xtr4xtr3m3

    Ok thx 4 help, but where did you get your infos from?
     
  6. Offline

    Shamebot

    Bukkit/mc-dev repo, but it's down due to 1.7.
     
  7. For information about packets I use MCP to decompile the vanilla server and the Protocol. For the bukkit-part, it's always
    CraftPlayer.getHandle().netServerHandler.sendPacket(Packet)
    Where you can cast "Player" to "CraftPlayer"
     
  8. Offline

    Shamebot

    it's
    Code:java
    1. ((CraftPlayer)player).getHandle().netServerHandler.sendPacket(..)
     
  9. @Shamebot Meeh, I forgot the getHandle() :p
    and as I've written, a Player needs to be cast to a CraftPlayer.
     
  10. Offline

    Ghappy

    ive just tried this; it just send the message "0 blocks destroyed" and no sound/explosion whatsoever happens :S
     
  11. Offline

    Shamebot

    Code?
     
  12. If you just want the explosion sound on the client side then another way to get it is to generate a zero strength explosion (I used this in a plugin to get the sound because I didn't find another way).
    Code:
    world.createExplosion(location,0);
    
     
Thread Status:
Not open for further replies.

Share This Page