Jump to content

[1.8.9] Custom Sounds?


Starjay811

Recommended Posts

After scouring the internet for hours hoping to find a tutorial that would moderately work for adding custom sounds to a custom mob, I finally came across a video tutorial that made sense. However, it was for 1.10.2/1.11.2, and eclipse is throwing errors I don't know how to fix.

 

The mob is called a New Guinea Singing Dog, and it is virtually a copy of the Minecraft wolf. The only difference is in place of barking like a minecraft wolf in its LivingSound, it howls. Or at least, that's what I would like it to do.

 

EnityNewGuineaSingingDog.java

Note that the class is so short because it inherits all of its wolf code from EntityVariedWolf. 

package slvr.LupineMod.entities;

import net.minecraft.world.World;
import slvr.LupineMod.Reference;

public class EntityNewGuineaSingingDog extends EntityVariedWolf{
	
	public EntityNewGuineaSingingDog(World dWorld){
		super(dWorld);
	}
	
	protected void entityInit(){
		super.entityInit();
		this.setWolfType(14);
	}
	
	@Override
	protected String getLivingSound()
    {
        return this.isAngry() ? "mob.wolf.growl" : (this.rand.nextInt(3) == 0 ? (this.isTamed() && this.dataWatcher.getWatchableObjectFloat(18) < 10.0F ? "mob.wolf.whine" : "mob.wolf.panting") : "mob.newguineasingingdog.singer_howl");
    }

}

 

sounds.json

{
"mob.newguineasingingdog.singer_howl":{
"category": "hostile",
"sounds":[{"name":"slupinemod:mob/newguineasingingdog/singer_howl","stream":true}]
}
}

 

SingerSoundHandler.java

package slvr.LupineMod;

import java.io.File;

import net.minecraft.client.Minecraft;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.sound.SoundEvent;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class SingerSoundHandler {
	
	private static int size = 0;
	
	public static SoundEvent SINGER_HOWL;
	
	public static void init() {
		size = SoundEvent.REGISTRY.getKeys().size();
		
		SINGER_HOWL = register("mob.newguineasingingdog.singer_howl");
	}
	
	public static SoundEvent register(String name) {
		ResourceLocation location = new ResourceLocation(Reference.MOD_ID, name);
		SoundEvent e = new SoundEvent(location);
		
		SoundEvent.REGISTRY.register(size, location, e);
		size++;
		return e;
	}
}

 

Main Mod Class, LupineMod.java

package slvr.LupineMod;

import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.EntityRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
import slvr.LupineMod.proxy.*;
import net.minecraftforge.common.BiomeManager.BiomeType;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraft.block.BlockPlanks;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.fml.common.Mod;
import slvr.LupineMod.entities.*;
import slvr.LupineMod.init.ModBlocks;
import slvr.LupineMod.init.ModItems;
import slvr.LupineMod.proxy.CommonProxy;
import net.minecraftforge.client.event.sound.SoundEvent;
import net.minecraftforge.common.BiomeDictionary;
import static net.minecraftforge.common.BiomeDictionary.Type;

@Mod(modid =Reference.MOD_ID, name =Reference.NAME, version =Reference.VERSION, acceptedMinecraftVersions =Reference.ACCEPTED_VERSIONS)
public class LupineMod {

	@Instance
	public static LupineMod instance;
	
	@SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
	public static CommonProxy proxy;
	
	@EventHandler
	public void preInit(FMLPreInitializationEvent event)
	{
		System.out.println("Pre Init");
		EntityRegistry.registerModEntity(EntityAfricanWildDog.class, "africanWildDog", 9, this, 50, 2, true, 0xdfc030, 0xb44b21);
		EntityRegistry.registerModEntity(EntityRedWolf.class, "redWolf", 9, this, 50, 2, true, 0xf01f4b, 0x5d1b07);
		EntityRegistry.registerModEntity(EntityCoyote.class, "coyote", 9, this, 50, 2, true, 0xc37025, 0x484848);
		EntityRegistry.registerModEntity(EntityNetherhound.class, "netherhound", 9, this, 50, 2, true, 0xcc6519, 0x2e2525);
		EntityRegistry.registerModEntity(EntityGermanShepherd.class, "germanShepherd", 9, this, 50, 2, true, 0xd39147, 0x361d06);
		EntityRegistry.registerModEntity(EntityGoldenRetriever.class, "goldenRetriever", 9, this, 50, 2, true, 0xffdd53, 0xea9600);
		EntityRegistry.registerModEntity(EntityPitBull.class, "pitBull", 9, this, 50, 2, true, 0x8eb2c9, 0xd2d2d2);
		EntityRegistry.registerModEntity(EntityDingo.class, "dingo", 9, this, 50, 2, true, 0xaa895a, 0xb6640c);
		EntityRegistry.registerModEntity(EntityArcticWolf.class, "arcticWolf", 9, this, 50, 2, true, 0xe9fff8, 0x7f80bc);
		EntityRegistry.registerModEntity(EntityEndWolf.class, "endWolf", 9, this, 50, 2, true, 0x360657, 0xe620e4);
		EntityRegistry.registerModEntity(EntityIslandWolf.class, "islandWolf", 9, this, 50, 2, true, 0x3188ff, 0x004141);
		EntityRegistry.registerModEntity(EntityNewGuineaSingingDog.class, "newGuineaSingingDog", 9, this, 50, 2, true);
		proxy.preInit();
		ModItems.init();
		ModItems.register();
		ModBlocks.init();
		ModBlocks.register();
		
	}
			
	
	@EventHandler
	public void init(FMLInitializationEvent event)
	{
		System.out.println("Init");
		proxy.init();
		SingerSoundHandler.init();
		GameRegistry.addRecipe(new ItemStack(slvr.LupineMod.init.ModBlocks.dog_bowl, 1), new Object[] {"###", "#X#", "###", '#', Blocks.planks, 'X', Items.mutton});
		GameRegistry.addRecipe(new ItemStack(slvr.LupineMod.init.ModItems.golden_steak), new Object[] {"###", "#X#", "###", '#', Items.gold_ingot, 'X', Items.cooked_beef});
	}
	
	@EventHandler
	public void postInit(FMLPostInitializationEvent event)
	{
		System.out.println("Post Init");
		MinecraftForge.EVENT_BUS.register(new LupineEventHandler());
		net.minecraft.world.biome.BiomeGenBase.SpawnListEntry african = new net.minecraft.world.biome.BiomeGenBase.SpawnListEntry(EntityAfricanWildDog.class, 1, 2, 4);
		net.minecraft.world.biome.BiomeGenBase.SpawnListEntry red = new net.minecraft.world.biome.BiomeGenBase.SpawnListEntry(EntityRedWolf.class, 1, 2, 4);
		net.minecraft.world.biome.BiomeGenBase.SpawnListEntry coyote = new net.minecraft.world.biome.BiomeGenBase.SpawnListEntry(EntityCoyote.class, 1, 4, 4);
		net.minecraft.world.biome.BiomeGenBase.SpawnListEntry netherhound = new net.minecraft.world.biome.BiomeGenBase.SpawnListEntry(EntityNetherhound.class, 25, 1, 2);
		net.minecraft.world.biome.BiomeGenBase.SpawnListEntry gs = new net.minecraft.world.biome.BiomeGenBase.SpawnListEntry(EntityGermanShepherd.class, 1, 1, 1);
		net.minecraft.world.biome.BiomeGenBase.SpawnListEntry golden = new net.minecraft.world.biome.BiomeGenBase.SpawnListEntry(EntityGoldenRetriever.class, 1, 1, 1);
		net.minecraft.world.biome.BiomeGenBase.SpawnListEntry pit = new net.minecraft.world.biome.BiomeGenBase.SpawnListEntry(EntityPitBull.class, 1, 1, 1);
		net.minecraft.world.biome.BiomeGenBase.SpawnListEntry dingo = new net.minecraft.world.biome.BiomeGenBase.SpawnListEntry(EntityDingo.class, 2, 1, 1);
		net.minecraft.world.biome.BiomeGenBase.SpawnListEntry arctic = new net.minecraft.world.biome.BiomeGenBase.SpawnListEntry(EntityArcticWolf.class, 4, 4, 4);
		net.minecraft.world.biome.BiomeGenBase.SpawnListEntry end = new net.minecraft.world.biome.BiomeGenBase.SpawnListEntry(EntityEndWolf.class, 5, 4, 4);
		net.minecraft.world.biome.BiomeGenBase.SpawnListEntry island = new net.minecraft.world.biome.BiomeGenBase.SpawnListEntry(EntityIslandWolf.class, 6, 4, 4);
		net.minecraft.world.biome.BiomeGenBase.SpawnListEntry singing = new net.minecraft.world.biome.BiomeGenBase.SpawnListEntry(EntityNewGuineaSingingDog.class, 6, 4, 4);
		
		BiomeGenBase biomes[] = BiomeDictionary.getBiomesForType(Type.SANDY);
		for (int i = 0; i < biomes.length; i++){
			if(BiomeDictionary.isBiomeOfType(biomes[i], Type.HOT)){
				biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(dingo);
				biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(african);
				biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(red);
			}
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(gs);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(pit);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(golden);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(coyote);
		}
		
		biomes = BiomeDictionary.getBiomesForType(Type.SNOWY);
		for (int i = 0; i < biomes.length; i++){
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(arctic);
		}
		
		biomes = BiomeDictionary.getBiomesForType(Type.PLAINS);
		for (int i = 0; i < biomes.length; i++){
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(african);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(gs);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(pit);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(golden);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(coyote);
		}
		
		biomes = BiomeDictionary.getBiomesForType(Type.FOREST);
		for (int i = 0; i < biomes.length; i++){
			if(!BiomeDictionary.isBiomeOfType(biomes[i], Type.SNOWY)){
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(red);
			}
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(gs);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(pit);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(golden);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(coyote);
		}
		
		biomes = BiomeDictionary.getBiomesForType(Type.NETHER);
		for (int i = 0; i < biomes.length; i++){
			biomes[i].getSpawnableList(EnumCreatureType.MONSTER).add(netherhound);
		}
		
		biomes = BiomeDictionary.getBiomesForType(Type.END);
		for (int i = 0; i < biomes.length; i++){
			biomes[i].getSpawnableList(EnumCreatureType.MONSTER).add(end);
		}
		
		biomes = BiomeDictionary.getBiomesForType(Type.WASTELAND);
		for (int i = 0; i < biomes.length; i++){
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(red);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(singing);
		}
		
		biomes = BiomeDictionary.getBiomesForType(Type.MOUNTAIN);
		for (int i = 0; i < biomes.length; i++){
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(gs);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(pit);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(golden);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(coyote);
		}
		
		biomes = BiomeDictionary.getBiomesForType(Type.MUSHROOM);
		for (int i = 0; i < biomes.length; i++){
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(gs);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(pit);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(golden);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(coyote);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(island);
			
		}
		
		biomes = BiomeDictionary.getBiomesForType(Type.JUNGLE);
		for (int i = 0; i < biomes.length; i++){
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(gs);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(pit);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(golden);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(coyote);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(singing);
		}
		
		biomes = BiomeDictionary.getBiomesForType(Type.SWAMP);
		for (int i = 0; i < biomes.length; i++){
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(gs);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(pit);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(golden);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(coyote);
		}
		
		biomes = BiomeDictionary.getBiomesForType(Type.WATER);
		for (int i = 0; i < biomes.length; i++){
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(gs);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(pit);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(golden);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(island);
			biomes[i].getSpawnableList(EnumCreatureType.CREATURE).add(singing);
		}
	}

}

 

 

My problem lies in the SingerSoundHandler.

At this-

public static void init() {
        size = SoundEvent.REGISTRY.getKeys().size();

it says "REGISTRY cannot be resolved or is not a field."

 

At this-

ResourceLocation location = new ResourceLocation(Reference.MOD_ID, name);
        SoundEvent e = new SoundEvent(location);

It says "the SoundEvent ResourceLocation is undefined." 

 

And at this-

SoundEvent.REGISTRY.register(size, location, e);

It just says that "REGISTRY cannot be resolved or is not a field" again.

 

I'm assuming a lot of this is technical naming detail, but I am still pretty new to modding, and no tutorials I have found have seemed to clear this up at all. I would be EXTREMELY grateful for some help!

Link to comment
Share on other sites

2 hours ago, Starjay811 said:

REGISTRY cannot be resolved

Is it private? Look for a getRegistry method.

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

Minecraft only added the SoundEvent system in 1.9, it doesn't exist in 1.8.9. The SoundEvent class you're referencing is the base class for Forge's sound-related events.

 

I don't remember exactly how the sound system worked in 1.8.9, but I'm pretty sure you just needed the sounds.json file; all the registration was handled automatically.

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

1 minute ago, Choonster said:

Minecraft only added the SoundEvent system in 1.9, it doesn't exist in 1.8.9. The SoundEvent class you're referencing is the base class for Forge's sound-related events.

 

I don't remember exactly how the sound system worked in 1.8.9, but I'm pretty sure you just needed the sounds.json file; all the registration was handled automatically.

 

I recall reading something like this yet when I attempted to run the game, the mob would attempt to make the sound but would spit an error out in console. I'll revert it to that code and see exactly whatit does again. 

Link to comment
Share on other sites

  • 2 weeks later...

Thank you for yalls help, I did figure out that it was because I didn't do "slupinemod: before the file name in the mob's class! However, now Im having another small issue... I just don't quite know how to do this, haha.

 

I want the New Guinea Singing Dog to howl, but he howls very frequently. So I was thinking it would also be nice if he would bark instead of howl sometimes too. However, this mess here:

@Override
	protected String getLivingSound()
    {
        return this.isAngry() ? "mob.wolf.growl" : (this.rand.nextInt(3) == 0 ? (this.isTamed() && this.dataWatcher.getWatchableObjectFloat(18) < 10.0F ? "mob.wolf.whine" : "mob.wolf.panting") : "slupinemod:mob.newguineasingingdog.singer_howl");
    }

makes my brain hurt. I want the NGSD to sometimes bark as well as howl. How would I go about writing that in?

 

Again, any help is greatly appreciated. thanks all :)

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.