Jump to content

[1.9] Play custom sound for item <SOLVED>


perromercenary00

Recommended Posts

 

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 ??

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);

 

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have been trying to combat this issue between oculus and embeddium and to no avail... I have already tried a few online tutorials on how to get this working but it doesn't work at all. https://pastebin.com/geQgifjc
    • wow you sound like fun to play with
    • Instale el mod en mi servidor y este se queda iniciando por horas, en la consola me habla de algo de permisos y trate de seguir la ruta que me da pero no existe.   [13:05:32 INFO]: CustomNPC Permissions available: [13:05:32 INFO]: customnpcs.edit.blocks [13:05:32 INFO]: customnpcs.edit.villager [13:05:32 INFO]: customnpcs.global.bank [13:05:32 INFO]: customnpcs.global.dialog [13:05:32 INFO]: customnpcs.global.faction [13:05:32 INFO]: customnpcs.global.linked [13:05:32 INFO]: customnpcs.global.naturalspawn [13:05:32 INFO]: customnpcs.global.playerdata [13:05:32 INFO]: customnpcs.global.quest [13:05:32 INFO]: customnpcs.global.recipe [13:05:32 INFO]: customnpcs.global.transport [13:05:32 INFO]: customnpcs.npc.advanced [13:05:32 INFO]: customnpcs.npc.ai [13:05:32 INFO]: customnpcs.npc.clone [13:05:32 INFO]: customnpcs.npc.create [13:05:32 INFO]: customnpcs.npc.delete [13:05:32 INFO]: customnpcs.npc.display [13:05:32 INFO]: customnpcs.npc.freeze [13:05:32 INFO]: customnpcs.npc.gui [13:05:32 INFO]: customnpcs.npc.inventory [13:05:32 INFO]: customnpcs.npc.reset [13:05:32 INFO]: customnpcs.npc.stats [13:05:32 INFO]: customnpcs.scenes [13:05:32 INFO]: customnpcs.soulstone.all [13:05:32 INFO]: customnpcs.spawner.create [13:05:32 INFO]: customnpcs.spawner.mob [13:05:32 INFO]: customnpcs.tool.mounter [13:05:32 INFO]: customnpcs.tool.nbtbook [13:05:32 INFO]: customnpcs.tool.pather [13:05:32 INFO]: customnpcs.tool.scripter
    • I have created a very simple mod that is just supposed to send a message to a player when they join. Upon adding it to a server (that has other mods on it), the following crash message appears: [12:13:01] [main/ERROR] [minecraft/Main]: Failed to start the minecraft server net.minecraftforge.fml.LoadingFailedException: Loading errors encountered: [         Epic Mod (epicmod) has failed to load correctly §7java.lang.NoSuchMethodException: net.ed.epicmod.EpicMod.<init>() ]         at net.minecraftforge.fml.ModLoader.waitForTransition(ModLoader.java:243) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.fml.ModLoader.lambda$dispatchAndHandleError$24(ModLoader.java:208) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] {re:mixin}         at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:208) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$14(ModLoader.java:185) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] {re:mixin,re:computing_frames}         at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:185) ~[fmlcore-1.19.2-43.2.14.jar%23548!/:?] {}         at net.minecraftforge.server.loading.ServerModLoader.load(ServerModLoader.java:32) ~[forge-1.19.2-43.2.14-universal.jar%23552!/:?] {re:classloading}         at net.minecraft.server.Main.main(Main.java:113) ~[server-1.19.2-20220805.130853-srg.jar%23547!/:?] {re:classloading,re:mixin,pl:mixin:A}         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}         at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}         at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}         at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}         at net.minecraftforge.fml.loading.targets.CommonServerLaunchHandler.lambda$launchService$0(CommonServerLaunchHandler.java:29) ~[fmlloader-1.19.2-43.2.14.jar%2367!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:30) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-10.0.8.jar%2354!/:?] {}         at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:141) [bootstraplauncher-1.1.2.jar:?] {} Why could this be? I have tried using the mod on another forge server with only this mod installed and it works there. Is my mod somehow interfering with other mods? MC version is 1.19.2
    • how to make animated doors?, maybe geckolib, but i don't know how to code it?
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.