Jump to content

Recommended Posts

Posted

 

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

Posted

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.

Posted

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.

Posted
  On 4/14/2016 at 1:58 AM, jeffryfisher said:

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.

Posted

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

 

 

 

 

Posted

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.

Posted

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.

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

    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • I removed yetanotherchance booster and now it says Invalid player identity
    • Cracked Launchers are not supported
    • After some time minecraft crashes with an error. Here is the log https://drive.google.com/file/d/1o-2R6KZaC8sxjtLaw5qj0A-GkG_SuoB5/view?usp=sharing
    • The specific issue is that items in my inventory wont stack properly. For instance, if I punch a tree down to collect wood, the first block I collected goes to my hand. So when I punch the second block of wood to collect it, it drops, but instead of stacking with the piece of wood already in my hand, it goes to the second slot in my hotbar instead. Another example is that I'll get some dirt, and then when I'm placing it down later I'll accidentally place a block where I don't want it. When I harvest it again, it doesn't go back to the stack that it came from on my hotbar, where it should have gone, but rather into my inventory. That means that if my inventory is full, then the dirt wont be picked up even though there should be space available in the stack I'm holding. The forge version I'm using is 40.3.0, for java 1.18.2. I'll leave the mods I'm using here, and I'd appreciate it if anybody can point me in the right direction in regards to figuring out how to fix this. I forgot to mention that I think it only happens on my server but I'm not entirely sure. PLEASE HELP ME! LIST OF THE MODS. aaa_particles Adorn AdvancementPlaques AI-Improvements AkashicTome alexsdelight alexsmobs AmbientSounds amwplushies Animalistic another_furniture AppleSkin Aquaculture aquamirae architectury artifacts Atlas-Lib AutoLeveling AutoRegLib auudio balm betterfpsdist biggerstacks biomancy BiomesOPlenty blockui blueprint Bookshelf born_in_chaos Botania braincell BrassAmberBattleTowers brutalbosses camera CasinoCraft cfm (MrCrayfish’s Furniture Mod) chat_heads citadel cloth-config Clumps CMDCam CNB cobweb collective comforts convenientcurioscontainer cookingforblockheads coroutil CosmeticArmorReworked CozyHome CrabbersDelight crashexploitfixer crashutilities Create CreativeCore creeperoverhaul cristellib crittersandcompanions Croptopia CroptopiaAdditions CullLessLeaves curios curiouslanterns curiouslights Curses' Naturals CustomNPCs CyclopsCore dannys_expansion decocraft Decoration Mod DecorationDelightRefurbished Decorative Blocks Disenchanting DistantHorizons doubledoors DramaticDoors drippyloadingscreen durabilitytooltip dynamic-fps dynamiclights DynamicTrees DynamicTreesBOP DynamicTreesPlus Easy Dungeons EasyAnvils EasyMagic easy_npc eatinganimation ecologics effective_fg elevatorid embeddium emotecraft enchantlimiter EnchantmentDescriptions EnderMail engineersdecor entityculling entity_model_features entity_texture_features epicfight EvilCraft exlinefurniture expandability explosiveenhancement factory-blocks fairylights fancymenu FancyVideo FarmersDelight fast-ip-ping FastSuite ferritecore finsandtails FixMySpawnR Forge Middle Ages fossil FpsReducer2 furnish GamingDeco geckolib goblintraders goldenfood goodall H.e.b habitat harvest-with-ease hexerei hole_filler huge-structure-blocks HunterIllager iammusicplayer Iceberg illuminations immersive_paintings incubation infinitybuttons inventoryhud InventoryProfilesNext invocore ItemBorders itemzoom Jade jei (Just Enough Items) JetAndEliasArmors journeymap JRFTL justzoom kiwiboi Kobolds konkrete kotlinforforge lazydfu LegendaryTooltips libIPN lightspeed lmft lodestone LongNbtKiller LuckPerms Lucky77 MagmaMonsters malum ManyIdeasCore ManyIdeasDoors marbledsarsenal marg mcw-furniture mcw-lights mcw-paths mcw-stairs mcw-trapdoors mcw-windows meetyourfight melody memoryleakfix Mimic minecraft-comes-alive MineTraps minibosses MmmMmmMmmMmm MOAdecor (ART, BATH, COOKERY, GARDEN, HOLIDAYS, LIGHTS, SCIENCE) MobCatcher modonomicon mods_optimizer morehitboxes mowziesmobs MutantMonsters mysticalworld naturalist NaturesAura neapolitan NekosEnchantedBooks neoncraft2 nerb nifty NightConfigFixes nightlights nocube's_villagers_sell_animals NoSeeNoTick notenoughanimations obscure_api oculus oresabovediamonds otyacraftengine Paraglider Patchouli physics-mod Pillagers Gun PizzaCraft placeableitems Placebo player-animation-lib pneumaticcraft-repressurized polymorph PrettyPipes Prism projectbrazier Psychadelic-Chemistry PuzzlesLib realmrpg_imps_and_demons RecipesLibrary reeves-furniture RegionsUnexplored restrictedportals revive-me Scary_Mobs_And_Bosses selene shetiphiancore ShoulderSurfing smoothboot
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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