Posted April 13, 20169 yr good nights I'm trying to add custom sounds for and item so i have sounds in ogg assets/modmercenario/sounds/pistolaFM92_reload.ogg assets/modmercenario/sounds/pistolaFM92_unload.ogg assets/modmercenario/sounds/pistolaFM92_disparo.ogg and also have sounds.json { "pistolaFM92_disparo": { "category": "player", "sounds": [ "pistolaFM92_disparo" ] }, "pistolaFM92_reload": { "category": "player", "sounds": [ "pistolaFM92_reload" ] }, "pistolaFM92_unload": { "category": "player", "sounds": [ "pistolaFM92_unload" ] } } but now sounds work as soundEvent so i been reading other post and say things like must register the three sounds in some place inside preinit using gameregistry but no i don't get how to use it //new ModelResourceLocation("sounds/pistolaFM92_reload.ogg", "sound"); //GameRegistry.register(object, name) GameRegistry.register(new ModelResourceLocation("sounds/pistolaFM92_disparo") , "pistolaFM92_disparo" ); ############ someone can give me and example on how to register a sound, and later how play it server side so it could be audible in all the clients i think sounds.json is not use anymore it is true ??
April 14, 20169 yr You need to create a ResourceLocation (not a ModelResourceLocation , which is client-only and only used for models) with your mod ID as the domain and the JSON sound event's name (the keys of the top-level object in sounds.json) as the path. You then need to create a SoundEvent with this ResourceLocation , set the ResourceLocation as its registry name (with the setRegistryName method inherited from IForgeRegistryEntry ) and register it (with the single-argument GameRegistry.register method). sounds.json is still needed to specify the sound files for each SoundEvent . You can see how I create and register a SoundEvent here and my sounds.json file here. To play a sound, use one of the overloads of World#playSound with an EntityPlayer as the first argument. On the server side, these will send a packet to every nearby player except the first argument (if it's not null ) to play the sound on their clients. On the client side, these will simply play the sound if the first argument is the client player. Edit: The packet is only sent to nearby players, not all players. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
April 14, 20169 yr If just playing a sound effect, is it really all that complicated? Isn't it enough to register the sound and then call playSoundEffect on the server? (playSound is client-side rendering). If 1.9 has screwed up simple sound effects so badly, then I might not bother to upgrade. The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
April 14, 20169 yr If just playing a sound effect, is it really all that complicated? Isn't it enough to register the sound and then call playSoundEffect on the server? (playSound is client-side rendering). If 1.9 has screwed up simple sound effects so badly, then I might not bother to upgrade. It's not really that complicated. If the code that plays the sound is only running server side, pass null as the EntityPlayer argument of World#playSound and the sound effect packet will be sent to all nearby players. If the code that plays the sound is running on both sides, pass the appropriate player as the EntityPlayer argument of World#playSound . The server will send the sound effect packet to all nearby players except the specified one and the player's client will play the sound itself. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
April 14, 20169 yr Author good nights is not working soo may i still missing something i create the class sonidos.java to register the sounds https://gist.github.com/anonymous/f4976daca96e2a9989fa88efc1cad6fa and set in mi main class preinit @EventHandler public void preInit(FMLPreInitializationEvent event) { MMMateriales.init(); MMBlocks.init(); sonidos.init(); proxy.preInit(); } well this is a simple sound example but i need to register like 50 sounds but i ask thath later when the first one works { "pistolaFM92_disparo": { "category": "record", "sounds": [ { "name": "modmercenario:sounds/pistolaFM92_disparo", "stream": true } ] } } and in the gun Item class i doo on left click it must play in the two worlds // ############################################################################################3 @Override public boolean onEntitySwing(EntityLivingBase shootingEntity, ItemStack stack) { World worldIn = shootingEntity.worldObj; double x = shootingEntity.posX; double y = shootingEntity.posY; double z = shootingEntity.posZ; if ( shootingEntity instanceof EntityPlayer) { EntityPlayer playerIn= (EntityPlayer) shootingEntity; //worldIn.playSound(x, y, z, sonidos.pistolaFM92_disparo , SoundCategory.RECORDS , 2.0F, 1.0F, true); worldIn.playSound(playerIn , x, y, z, sonidos.pistolaFM92_disparo , SoundCategory.RECORDS , 20.0F, 1.0F); } return false; } // ############################################################################################3 for what i understand if i play a sound server side ill shall play everywhere excep for mi player world?? soo i have also to play it client side if i wanna hear it ?? thanks for reading
April 14, 20169 yr Your sounds.json file was already valid, you don't want your gun sounds to play as if they records. What you have now should still work, though. Item#onEntitySwing will be called on both the client and server. If the shooting entity is a player, pass it to World#playSound as the first argument. The client-side call will play the sound for the shooting player and the server side call will send a packet to every other nearby player to play the sound for them. If the shooting entity isn't a player, pass null to World#playSound as the first argument. The client-side call will do nothing and the server side call will send a packet to all nearby players to play the sound for them. Either way, all nearby players will hear the sound. You can see a working example of this here. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
April 15, 20169 yr Author ya le soluciones good nights i fix it and it ends like this for : assets/modmercenario/sounds/pistolaFM92_disparo.ogg assets/modmercenario/sounds/pistolaFM92_reload.ogg assets/modmercenario/sounds/pistolaFM92_unload.ogg assets/modmercenario/sounds/pistolaFM92_vacia.ogg i do sound.json https://gist.github.com/anonymous/3b70a65103d263c89d08d354cd579d53 and make mi sound register class and init it in preinit() sonido.java https://gist.github.com/anonymous/d1fac5b82c549012e5c9f716324654a7 and to play the sound i do in server side double x = player.posX; double y = player.posY; double z = player.posZ; player.worldObj.playSound(null , x, y, z, sonidos.pistolaFM92_reload , SoundCategory.PLAYERS , 2.0F, 1.0F);
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.