Jump to content

Help with sound?


ocomobock

Recommended Posts

EDIT: Wow, sorry about that. This should probably be in Support & Bug Reports..

 

I have absolutely no idea what I'm doing. I've been trying to get my mob to play sound files for several hours now, and it's getting pretty annoying. I got it to work with ModLoader fine. I could always just do the same thing I did to get it to work for ModLoader, but I wanted to learn how to do it with Forge too. This is the tutorial I'm trying to follow:

 

http://minecraftforge.net/wiki/Adding_Custom_Sounds_to_Minecraft!

 

And here's my code (I'm sure there's a lot of stuff wrong with it):

 

mod_Scoaleton

 

 

package net.minecraft.src;

 

import java.util.Map;

import net.minecraft.src.forge.*;

import java.io.File;

import cpw.mods.fml.common.FMLCommonHandler;

import net.minecraft.client.Minecraft;

import java.util.*;

import net.minecraft.src.SoundManager;

import net.minecraft.src.forge.MinecraftForgeClient;

import net.minecraft.src.forge.*;

 

public class mod_Scoaleton extends BaseMod{

 

public mod_Scoaleton()

{

 

}

 

static Configuration configuration = new Configuration(new File(Minecraft.getMinecraftDir(), "/config/Scoaleton.cfg"));

public static int DoesScoaletonExplodeAtDay;

public static int DoesScoaletonAttackVillagers;

static int ScoaletonProperties = configurationProperties();

public static int ScoaletonHealth;

public static int ScoaletonStrength;

public static int ScoaletonEXP;

public static int ScoaletonSpawnRate;

public static int ScoaletonMinimumGroupSize;

public static int ScoaletonMaximumGroupSize;

 

public void load()

{

 

ModLoader.addSpawn(EntityScoaleton.class, ScoaletonSpawnRate, ScoaletonMinimumGroupSize, ScoaletonMaximumGroupSize, EnumCreatureType.monster);

ModLoader.registerEntityID(EntityScoaleton.class, "Scoaleton", 85, 1447446, 3158064);

}

 

public static int configurationProperties()

    {

            configuration.load();

            DoesScoaletonAttackVillagers = Integer.parseInt(configuration.getOrCreateIntProperty("DoesScoaletonAttackVillagers", Configuration.CATEGORY_GENERAL, 0).value);

            DoesScoaletonExplodeAtDay = Integer.parseInt(configuration.getOrCreateIntProperty("DoesScoaletonExplodeAtDay", Configuration.CATEGORY_GENERAL, 0).value);

            ScoaletonHealth = Integer.parseInt(configuration.getOrCreateIntProperty("ScoaletonHealth", Configuration.CATEGORY_GENERAL, 70).value);

        ScoaletonStrength = Integer.parseInt(configuration.getOrCreateIntProperty("ScoaletonStrength", Configuration.CATEGORY_GENERAL, 8).value);

        ScoaletonEXP = Integer.parseInt(configuration.getOrCreateIntProperty("ScoaletonEXP", Configuration.CATEGORY_GENERAL, 30).value);

        ScoaletonSpawnRate = Integer.parseInt(configuration.getOrCreateIntProperty("ScoaletonSpawnRate", Configuration.CATEGORY_GENERAL, 1).value);

        ScoaletonMinimumGroupSize = Integer.parseInt(configuration.getOrCreateIntProperty("ScoaletonMinimumGroupSize", Configuration.CATEGORY_GENERAL, 1).value);

        ScoaletonMaximumGroupSize = Integer.parseInt(configuration.getOrCreateIntProperty("ScoaletonMaximumGroupSize", Configuration.CATEGORY_GENERAL, 1).value);

            configuration.save();

            return ScoaletonProperties;

    }

 

public void addRenderer(Map map)

{

FMLCommonHandler.instance().addStringLocalization("entity.Scoaleton.name", "en_US", "Scoaleton");

map.put(EntityScoaleton.class, new RenderBiped(new ModelBiped(), 0.5F));

map.put(net.minecraft.src.EntityScoaleton.class, new RenderScoaleton(new ModelScoaleton(), 0.4F));

}

 

public String getVersion()

{

return "1.2.5";

}

}

 

 

 

SoundHandler

 

 

package net.minecraft.src;

 

import java.io.File;

import java.lang.reflect.Method;

import java.net.URL;

import java.net.URLClassLoader;

 

import net.minecraft.src.ModLoader;

import net.minecraft.src.SoundManager;

import net.minecraft.src.SoundPoolEntry;

import net.minecraft.src.mod_Scoaleton;

import net.minecraft.src.forge.*;

 

public abstract class SoundHandler implements ISoundHandler {

 

        @Override

        public void onSetupAudio(SoundManager soundManager) { }

 

        @Override

        // Initialises our entries into the Sound Pool

        public void onLoadSoundSettings(SoundManager soundManager) {

String [] soundFiles = {

"metalhurt.ogg",

"metalliving.ogg",

"metaldeath.ogg"};

for (int i = 0; i < soundFiles.length; i++){

soundManager.getSoundsPool().addSound(soundFiles, this.getClass().getResource("/ocomosounds/sound/" + soundFiles));

}

}

 

        @Override

        public SoundPoolEntry onPlayBackgroundMusic(SoundManager soundManager, SoundPoolEntry entry) {

                return entry;

        }

 

        @Override

        public SoundPoolEntry onPlayStreaming(SoundManager soundManager, SoundPoolEntry entry, String soundName, float x, float y, float z) {

                return entry;

        }

 

        @Override

        public SoundPoolEntry onPlaySound(SoundManager soundManager,

                        SoundPoolEntry entry, String soundName, float x, float y, float z,

                        float volume, float pitch) {

                return entry;

        }

 

        @Override

        public SoundPoolEntry onPlaySoundEffect(SoundManager soundManager, SoundPoolEntry entry, String soundName, float volume, float pitch) {

                return entry;

        }

 

}

 

 

Link to comment
Share on other sites

Try naming your sound files with a XXX/ before it. So for example in the tutorial "horse.whinny" is acceptable but when you added your sound files you don't have a prefix before the sound file. That might be the problem.

 

Also, I wrote that tutorial, so I guess it wasn't a good enough tutorial to get people to understand it...

Link to comment
Share on other sites

I tried that and it didn't work, here's my code now:

 

public void onLoadSoundSettings(SoundManager soundManager) {
		String [] soundFiles = {
				"test/metalhurt.ogg",
				"test/metalliving.ogg",
				"test/metaldeath.ogg"};
		for (int i = 0; i < soundFiles.length; i++){
			soundManager.getSoundsPool().addSound(soundFiles[i], this.getClass().getResource("/ocomosounds/sound" + soundFiles[i]));
		}
	}

 

Also, I put the files in 'resources\mod\ocomosounds\test'. Here are the sounds in my Entity file:

 

public String getHurtSound()
{
	return "test.metalhurt";
}

public String getLivingSound()
{
	return "test.metalliving";
}

public String getDeathSound()
{
	return "test.metaldeath";
}

 

And also, I'm not using the

MinecraftForgeClient.registerSoundHandler(mod_Scoaleton, ISoundManager);

function (which is most likely the problem), because I kept this error on that line:

 

Multiple markers at this line
- Syntax error on token ")", delete this token
- Syntax error on token "(", delete this token

 

Your tutorial is fine, I'm just stupid  :-\ I wasn't really sure where to put that function, so I just put it after

public abstract class SoundHandler implements ISoundHandler {

Link to comment
Share on other sites

I dont understand the

MinecraftForgeClient.registerSoundHandler(new SoundHandlerClass());

thing, I try this but it doesnt work:

 

MinecraftForgeClient.registerSoundHandler(new ThorMod_SoundHandler());

 

Eclipse gives me the error: Cannot instantiate the type ThorMod_SoundHandler

 

ThorMod_SoundHandler:

package net.minecraft.src;

import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;

import net.minecraft.src.ModLoader;
import net.minecraft.src.SoundManager;
import net.minecraft.src.SoundPoolEntry;
import net.minecraft.src.mod_TheThorMod;
import net.minecraft.src.forge.*;

public abstract class ThorMod_SoundHandler implements ISoundHandler {
   
        @Override
        public void onSetupAudio(SoundManager soundManager) { }

        @Override
        public void onLoadSoundSettings(SoundManager soundManager) {
            String [] soundFiles = {
                            "monkey/cry1.ogg",
                            "monkey/cry2.ogg",
                            "monkey/cry3.ogg",};
            for (int i = 0; i < soundFiles.length; i++){
                    soundManager.getSoundsPool().addSound(soundFiles[i], this.getClass().getResource("/Thormod/Audio/" + soundFiles[i]));
            }
    }

        @Override
        public SoundPoolEntry onPlayBackgroundMusic(SoundManager soundManager, SoundPoolEntry entry) {
                return entry;
        }

        @Override
        public SoundPoolEntry onPlayStreaming(SoundManager soundManager, SoundPoolEntry entry, String soundName, float x, float y, float z) {
                return entry;
        }

        @Override
        public SoundPoolEntry onPlaySound(SoundManager soundManager,
                        SoundPoolEntry entry, String soundName, float x, float y, float z,
                        float volume, float pitch) {
                return entry;
        }

        @Override
        public SoundPoolEntry onPlaySoundEffect(SoundManager soundManager, SoundPoolEntry entry, String soundName, float volume, float pitch) {
                return entry;
        }

}

 

Pls help I need this :D

Link to comment
Share on other sites

I folllowed that tutorial and it worked for me.

 

*NOTE* if you don't use a prefix for your sound files it assumes you have your sound in a "Sounds/" folder in the jar file. Thats built in to the codec thingy.

Link to comment
Share on other sites

What did you do with the MinecraftForgeClient.registerSoundHandler thing?

 

EDIT: Didn't see that someone else posted, sorry.

 

Who posted? I still dont see any answers to this problem. Nothing works with the registerSoundHandler thing no matter what I put in there it always says cannot instantiate <The Thing You Put In The Brackets>. Also, what do I put in the getLivingSound thing on mobs when I want to use the sound?

Link to comment
Share on other sites

So you guys can't get it to work following the tutorial?

I had some trouble initially too, I think my code is basically the same as the tutorial except I didn't put a prefix on my sound files, this means I have to put my sound files in a Sounds/ folder as it assumes this for some reason.

 

Make a class that extends SoundHandlerAdaptor. Most important method in there is onLoadSoundSettings, in general

 

My onLoadSoundSettings :

@Override
public void onLoadSoundSettings(SoundManager soundManager) {
	String[] soundFiles = {
		"aSound.wav",	
		"abeep.wav",	
		"aSuperBeep.wav"
	};
	for (int i = 0; i < soundFiles.length; i++){
            soundManager.getSoundsPool().addSound(soundFiles[i], this.getClass().getClassLoader().getResource("/" + soundFiles[i]));
	}
}

 

In your mod_**** class, I simply created an instance of this soundHandler class, and then loaded it with MinecraftForge.

 

//With my declarations
public static awesomeSoundHandler soundHandler = new awesomeSoundHandler();


// Loading with MinecraftForge
public void load() {
        MinecraftForgeClient.registerSoundHandler(soundHandler);
}

 

 

Then when testing in MCP, I put my custom sounds in the minecraft.jar Sounds/aSounds.wav for example.

 

And playing a sound:

 

world.playSoundEffect(xPos,yPos,zPos, "aSound", world.rand.nextFloat()*0.2f + 0.8f, world.rand.nextFloat() * 0.2F + 0.8F);

Those parameters are reasonably self-explanatory bar the last 2. Note the lack of ".wav" in my sound name string.

The last two paramaters are volume and pitch respectively. If you wish, a simple 1f will suffice.

 

I think thats everything you need to do...?

 

Link to comment
Share on other sites

So you guys can't get it to work following the tutorial?

I had some trouble initially too, I think my code is basically the same as the tutorial except I didn't put a prefix on my sound files, this means I have to put my sound files in a Sounds/ folder as it assumes this for some reason.

 

Make a class that extends SoundHandlerAdaptor. Most important method in there is onLoadSoundSettings, in general

 

My onLoadSoundSettings :

@Override
public void onLoadSoundSettings(SoundManager soundManager) {
	String[] soundFiles = {
		"aSound.wav",	
		"abeep.wav",	
		"aSuperBeep.wav"
	};
	for (int i = 0; i < soundFiles.length; i++){
            soundManager.getSoundsPool().addSound(soundFiles[i], this.getClass().getClassLoader().getResource("/" + soundFiles[i]));
	}
}

 

In your mod_**** class, I simply created an instance of this soundHandler class, and then loaded it with MinecraftForge.

 

//With my declarations
public static awesomeSoundHandler soundHandler = new awesomeSoundHandler();


// Loading with MinecraftForge
public void load() {
        MinecraftForgeClient.registerSoundHandler(soundHandler);
}

 

 

Then when testing in MCP, I put my custom sounds in the minecraft.jar Sounds/aSounds.wav for example.

 

And playing a sound:

 

world.playSoundEffect(xPos,yPos,zPos, "aSound", world.rand.nextFloat()*0.2f + 0.8f, world.rand.nextFloat() * 0.2F + 0.8F);

Those parameters are reasonably self-explanatory bar the last 2. Note the lack of ".wav" in my sound name string.

The last two paramaters are volume and pitch respectively. If you wish, a simple 1f will suffice.

 

I think thats everything you need to do...?

 

I found the problem and everything is working smoothly now,

what I did wrong:

 

1. My class was implementing ISoundHandler

2. I didnt have onPlaySoundAtEntity() in my class

3. I was using .ogg files not wav files

 

Thank you!

Link to comment
Share on other sites

I found the problem and everything is working smoothly now,

what I did wrong:

 

1. My class was implementing ISoundHandler

2. I didnt have onPlaySoundAtEntity() in my class

3. I was using .ogg files not wav files

 

Thank you!

 

The fact that you were implementing ISoundHandler wasn't necessarily a problem - by extending the SoundHandlerAdaptor (or whatever it was called) you are extending a class which has implemented ISoundHandler. Its just a nice simple way to do it as the SoundHandlerAdaptor has default implementations you can override.

 

Anyway, as long as you got it working its all good

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

    • What's the issue your running into? The link for the image you posted is also broken.
    • What does NetworkHooks.openScreen(player, blockEntity, pPos) do?
    • At an attempt at answering my first question I thought I might be able to change the code to this public static final RegistryObject<StatType<?>> FIREWORK_BOOSTS_USED = STATISTICS.register("firework_boosts_used", () -> new StatType<>(ForgeRegistries.STAT_TYPES, Component.literal("firework_boosts"))); or to this public static final RegistryObject<StatType<?>> FIREWORK_BOOSTS_USED = STATISTICS.register("firework_boosts_used", () -> new StatType<>(BuiltInRegistries.STAT_TYPE, Component.literal("firework_boosts"))); but for the first code snippet the StatType constructor requires a Registry not an IForgeRegistry and for the second code snippet we run into the same NPE issue from above.
    • Hi guys,   I'm using Crafty installed on CasaOS and i want to create a BetterMC4 Server. Unfortunatly i got an error message. This error only appear when using my "online" server because when i create a singleplayer adventure, everythings works just fine. https://github.com/OwNuT/Errors/issues/1   Thank you !
    • I am attempting to create a mod that adds custom statistics to Minecraft. I've had some help from LexManos on the Discord server, but posting a lot of what I posted in the #mod-dev-support-1.20 channel here to have a more permanent spot for discussion.   ---   Minecraft creates their stats like this: and some of the registries in the code above are located in BuiltInRegistries.java like this: and the ForgeRegistries#STAT_TYPES looks like this: So, attempting to follow that and the forge documentation on registries I arrived at this: Clearly, registering a stat twice in a row is the wrong way to do it, but the makeRegistryStatType function was used as it does give the correct return type for the code I had come up with so far.   ---   At this point the game crashes upon trying to use Player#awardStat, because of a NPE that occurs in Stat#locationToKey. Which happens in the 2nd Stat#locationToKey in the Stat#buildName function. The .getRegistry returns the this.registry class variable with a value of {MappedRegistry@#####} "Registry[ResourceKey[minecraft:root / minecraft:custom_stat] (Stable)]" The value passed into .getKey is "samplemod:fireworks_boosts_used" but the reference found is null. So Lex's conclusion was that "[I'm] passing in null because the registry doesnt have an entry for your custom stat instance. So.. register your custom stat instance in that registry."   ---   So I suppose at this point my questions are 1. How can I create a supplier that returns a Supplier<? extends StatType<?>> to replace the () -> makeRegistryStatType("firework_boosts_used", BuiltInRegistries.CUSTOM_STAT) line of code. 2. Is my registry entry public static final RegistryObject<StatType<?>> FIREWORK_BOOSTS_USED the correct type? 3. Do I need to do anything additional, like create my own StatType<> or my own Stat<> ?
  • Topics

×
×
  • Create New...

Important Information

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