playSound который не хочет работать или как правильно его использовать?

Версия Minecraft
1.12.2
10
2
Здравствуйте после успешной регистрации звука не получается его воспроизвести с помощью событий

ExampleMod.MODID = examplemod

resources\assets\examplemod\sounds.json
resources\assets\examplemod\sounds\mytestsound.ogg



Код:
/playsound examplemod:mytestsound player oler009

Код:
{
"mytestsound": {
"category": "player",
"sounds": [
  {
    "name": "examplemod:mytestsound",
    "stream": true
  }
]
}
}


Код:
package com.example.examplemod;

import com.example.examplemod.ExampleMod;

import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry.ObjectHolder;

@ObjectHolder(ExampleMod.MODID)
public class Music {
 
    public static final SoundEvent myTestSound = new SoundEvent(new ResourceLocation(ExampleMod.MODID, "mytestsound")).setRegistryName(new ResourceLocation(ExampleMod.MODID, "mytestsound"));
 
     
    @Mod.EventBusSubscriber(modid = ExampleMod.MODID)
    public static class SoundEventRegistration {
        @SubscribeEvent
        public static void registerSoundEvents(final RegistryEvent.Register<SoundEvent> event) {
            final SoundEvent[] sounds = {
                    myTestSound
            };
         
            event.getRegistry().registerAll(sounds);
        }
    }
}


Не хочет вызывается
Код:
    @SubscribeEvent
    public static void onfishg(ItemFishedEvent event)
    {
        event.getEntityPlayer().playSound(Music.myTestSound,  1.0F, 1.0F);
    }

или


Код:
private static boolean bool = true;
    @SubscribeEvent
    public static void onJoin(EntityJoinWorldEvent e)
    {
     
        if (e.getEntity() instanceof EntityPlayer)
        {
            if(bool) {
            EntityPlayer player = (EntityPlayer) e.getEntity();
            player.sendMessage(new TextComponentString("Привет, " + player.getName() +  "!"));
            player.playSound(Music.myTestSound,  1.0F, 1.0F);
            bool = false;
            }
        }
    }
 
Последнее редактирование:
10
2
Решил данную проблему с помощью

Код:
World world = Minecraft.getMinecraft().world;
        world.playSound(event.getEntityPlayer().lastTickPosX, event.getEntityPlayer().lastTickPosY, event.getEntityPlayer().lastTickPosZ, Music.myTestSound, SoundCategory.PLAYERS, 1F, 1F, false);

Код:
    @SubscribeEvent
    public static void onfishg(ItemFishedEvent event)
    {
        World world = Minecraft.getMinecraft().world;
        world.playSound(event.getEntityPlayer().lastTickPosX, event.getEntityPlayer().lastTickPosY, event.getEntityPlayer().lastTickPosZ, Music.myTestSound, SoundCategory.PLAYERS, 1F, 1F, false);
     }
    }


Проблема заключалась в том что
EntityPlayer - может воспроизвести звук для всех, кроме самого игрока.
 
Последнее редактирование:
Сверху