Jump to content

Cannot seem to override default entity sounds


MrChoke

Recommended Posts

What I want to do seems so simple to me but I cannot get it to work.  All I want to do is override some of the default zombie sounds with a few of my own.  As usual I find tons of examples on how to create custom sounds and play them with playSound() or attach to a new custom entity.  But I want to override a default sound.  Can't this easily be done?

 

Example, in the vanilla sounds.json, it has this:

 

"entity.zombie.hurt": {
    "sounds": [
      "mob/zombie/hurt1",
      "mob/zombie/hurt2"
    ],
    "subtitle": "subtitles.entity.zombie.hurt"
  },

 

I have my sounds.json file in my mod folder (or outside, I've tried many things).  And my .ogg files of those names in a "sounds" subdirectory.

 

{
  "entity.zombie.hurt": {
    "sounds": [
      "dumbhurt1",
      "dumbhurt2"
    ],
    "subtitle": "subtitles.entity.zombie.hurt"
  }
}

 

The closest I get to anything working are these messages in the console:

19:18:52] [main/WARN] [minecraft/SoundHandler]: File minecraft:sounds/dumbhurt1.ogg does not exist, cannot add it to event testmod1:entity.zombie.hurt
[19:18:52] [main/WARN] [minecraft/SoundHandler]: File minecraft:sounds/dumbhurt2.ogg does not exist, cannot add it to event testmod1:entity.zombie.hurt

 

So I don't get it.  Can someone help me do this?

 

Link to comment
Share on other sites

1 hour ago, MrChoke said:

Is there a way to only get the new ones?

I'm not sure what this means.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 hour ago, Animefan8888 said:

I'm not sure what this means.

What I mean is the default "zombie hurt" sound effects.  So I added two of my own but the two that come with the game also play.  I assume it chooses one of the four randomly each time it plays.

 

I have been deep diving into the forge stuff so much to figure this out.  Number 1) We are not allowed to remove entries from a ForgeRegistry (I even tried hacking it by using reflection but it just blew up later complaining about missing keys).  So I cannot remove the initial two sounds.  My next attempt now is a long shot and that is to somehow override the contents of the default ones with my own.  But I am lost in trying to understand how the SoundEvent is processed right now.

 

My overall opinion of Forge so far is this:

It is great for adding new content.  It is not good at all for overriding default behaviors.

Edited by MrChoke
Link to comment
Share on other sites

3 minutes ago, MrChoke said:

It is great for adding new content.  It is not good at all for overriding default behaviors.

You'd be wrong. However, most registries prevent modification, the only one I know of that allows removal is the IRecipe registry. Also there used to be a substitution alias system for Items and Blocks, however I knew there where some problems with it. Not sure if they worked the kinks out or just threw it in the trash to be started again.

 

The solution to your problem is simple. Use this

/***
 * Raised when the SoundManager tries to play a normal sound.
 *
 * If you return null from this function it will prevent the sound from being played,
 * you can return a different entry if you want to change the sound being played.
 */
public class PlaySoundEvent extends SoundEvent 

 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Just now, Animefan8888 said:

You'd be wrong. However, most registries prevent modification, the only one I know of that allows removal is the IRecipe registry. Also there used to be a substitution alias system for Items and Blocks, however I knew there where some problems with it. Not sure if they worked the kinks out or just threw it in the trash to be started again.

 

The solution to your problem is simple. Use this


/***
 * Raised when the SoundManager tries to play a normal sound.
 *
 * If you return null from this function it will prevent the sound from being played,
 * you can return a different entry if you want to change the sound being played.
 */
public class PlaySoundEvent extends SoundEvent 

 

 

So I was going to look into that after I give up on this.  However, is my understanding correct in that this is a way to override the sound being played right before it is actually played?  Meaning the initial load of the default sounds is still there.  And this override logic executes for every sound.  Seems like that is not an ideal approach...  Hence my forming opinion for Forge...  But I will admit, I am very new to it still.

Link to comment
Share on other sites

2 minutes ago, MrChoke said:

Seems like that is not an ideal approach...  Hence my forming opinion for Forge...  But I will admit, I am very new to it still.

An extra if statement or two means nothing in the grand scale of an application.

3 minutes ago, MrChoke said:

However, is my understanding correct in that this is a way to override the sound being played right before it is actually played?

Yes that is what happens.

3 minutes ago, MrChoke said:

Meaning the initial load of the default sounds is still there.

If your intent is to replace the default sounds on load, then use your mod as a resource pack. Because it is one.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

1 minute ago, Animefan8888 said:

If your intent is to replace the default sounds on load, then use your mod as a resource pack. Because it is one.

I tried this at first and I couldn't get it to work.  I was able to create an actual resource pack and put it in run/resourcepacks.  That ended up working the exact same as what I am seeing now.  The new sounds were added to the existing ones.

 

If you aware of a way I can override them with a resource pack that would  be great.

Link to comment
Share on other sites

UPDATE:  I got it to work!  I used reflection and changed the domain of the default sounds to my mod:

 

Collection<SoundEvent> coll = reg.getValuesCollection();
Iterator<SoundEvent> iter = coll.iterator();
while(iter.hasNext()) {
    SoundEvent se = iter.next();
    if(se.getSoundName().toString().equals("minecraft:entity.zombie.hurt")) {
        Field fld = SoundEvent.class.getDeclaredField("soundName");
        fld.setAccessible(true);
        ResourceLocation resLoc = (ResourceLocation) fld.get(se);
        Field fld2 = ResourceLocation.class.getDeclaredField("resourceDomain");
        fld2.setAccessible(true);
        fld2.set(resLoc, TestMod1.MODID);
    }
}

 

Edited by MrChoke
Link to comment
Share on other sites

1 minute ago, MrChoke said:

UPDATE:  I got it to work!  I used reflection and changed the domain of the default sounds to my mod:

Don't do that.

 

You do it exactly the same as you would for a resource pack. Put your sounds in assets.minecraft.sounds.folder.yourfile.ogg

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

There are a few things being discussed here.

 

First of all, a resource pack should be able to replace vanilla assets not just add to them. It is possible that sounds are behaving different/wrongly but I don't think it is expected.

 

Secondly, the events are perfectly suited for this. As mentioned above, there is no noticeable performance impact for checking for a sound. Just check for the sound and if it is the one you want to replace, play yours instead.


Here is a video with more details about adding sounds in modpacks - the first part is about custom sounds (played using commands), but later it talks about replacing existing ones.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

18 hours ago, jabelar said:

There are a few things being discussed here.

 

First of all, a resource pack should be able to replace vanilla assets not just add to them. It is possible that sounds are behaving different/wrongly but I don't think it is expected.

 

Secondly, the events are perfectly suited for this. As mentioned above, there is no noticeable performance impact for checking for a sound. Just check for the sound and if it is the one you want to replace, play yours instead.


Here is a video with more details about adding sounds in modpacks - the first part is about custom sounds (played using commands), but later it talks about replacing existing ones.

I would love to use simply a resource pack.  I could not get it to work.  As simply a pack file I put in run/resourcepacks for my mod, it does work in that it appends my sounds to the default ones.  It does not overwrite.  When trying to add my sounds and a sounds.json file directly into the mod, I couldn't get anything to work.

 

Ok, I agree, adding an event for playSound will probably work and long term I will probably do that, fine.  But please, if you think simply using .ogg files and sounds.json can work, please let me know....  I think you will find at best you append sounds, not replace.

Link to comment
Share on other sites

1 minute ago, MrChoke said:

I would love to use simply a resource pack.  I could not get it to work.  As simply a pack file I put in run/resourcepacks for my mod, it does work in that it appends my sounds to the default ones.  It does not overwrite.  When trying to add my sounds and a sounds.json file directly into the mod, I couldn't get anything to work.

 

Ok, I agree, adding an event for playSound will probably work and long term I will probably do that, fine.  But please, if you think simply using .ogg files and sounds.json can work, please let me know....  I think you will find at best you append sounds, not replace.

 

19 hours ago, Animefan8888 said:

assets.minecraft.sounds.folder.yourfile.ogg

 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

23 minutes ago, Animefan8888 said:

 

OMG, it was that easy!  Why did I not think to rename the exact zombie filenames in vanilla????

assets\minecraft\sounds\mob\zombie\hurt1.ogg   and hurt2.ogg

 

It works as a a pack and directly in my mod.  Thanks for your help. 

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



×
×
  • Create New...

Important Information

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