1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How to add piano sound?

Discussion in 'Development' started by SuperXingKong, Apr 15, 2017.

  1. SuperXingKong

    SuperXingKong Spider Jockey

    Messages:
    28
    GitHub:
    SuperXingKong
    I want to listen nbt music in the server, but the noteblock doesn't work.
    What to do with it?:facepalm:
     
  2. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    You can add sound using plugin and PlayerInteractEvent.

    PHP:
    public function onTouch(PlayerInteractEvent $e) {
            
    $p $e->getPlayer();
            if(
    $e->getBlock()->getId() == Block::NOTEBLOCK) {
                
    $p->getLevel()->addSound(new NoteblockSound($p,NoteblockSound::INSTRUMENT_PIANO,rand(1,10)),[$p]);
            }
        }
     
    SuperXingKong likes this.
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    If you want use nbt music dont do this:
    I think noteblock is working he meant noteblock not working when trying to use .nbt
     
    SuperXingKong likes this.
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    NoteblockSound isn't an actual class...

    Try this:
    PHP:
    public function onTouch(PlayerInteractEvent $e) {
            
    $p $e->getPlayer();
            if(
    $e->getBlock()->getId() === Block::NOTEBLOCK) {
                
    $p->getLevel()->addSound(new GenericSound($e->getBlock(), LevelSoundEventPacket::SOUND_NOTErand(1,10)), $p->getLevel()->getPlayers());
            }
        }
     
    SuperXingKong likes this.
  5. SuperXingKong

    SuperXingKong Spider Jockey

    Messages:
    28
    GitHub:
    SuperXingKong
    Thx . I will text them on my device :)
     
  6. SuperXingKong

    SuperXingKong Spider Jockey

    Messages:
    28
    GitHub:
    SuperXingKong
    Seems not work...
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.