Jump to content

Recommended Posts

Posted

So I followed a tutorial about adding sounds in forge 1.6.2 but it doesn't seem to be working for me. The sound should play while it is selected in the hotbar. I tested this with the "random.bow" sound and it worked, however, with my custom sound it doesn't. Here is the code I have:

 

Troncraft.java:

package taji34.troncraft;

import net.minecraft.client.renderer.entity.RenderSnowball;
import net.minecraft.item.Item;

import net.minecraftforge.common.MinecraftForge;

import cpw.mods.fml.client.registry.KeyBindingRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid="Troncraft", name="Troncraft", version="0.0.1")
@NetworkMod(clientSideRequired=true, serverSideRequired=false, channels={"troncraft"}, packetHandler = TajiPacketHandler.class)

public class Troncraft {
        // The instance of your mod that Forge uses.
        @Instance("Troncraft")
        public static Troncraft instance;
        public final static Item identityDisk = new IdentityDisk(5001);
        int diskItemID = identityDisk.itemID;
    	private final static Item baton = new Baton(5002);
    	int batonItemID = baton.itemID;
        // Says where the client and server 'proxy' code is loaded.
        @SidedProxy(clientSide="taji34.troncraft.client.ClientProxy", serverSide="taji34.troncraft.CommonProxy")
        public static CommonProxy proxy;
        @EventHandler
        public void preInit(FMLPreInitializationEvent event) {
                // Stub Method
        }
        @EventHandler
        public void load(FMLInitializationEvent event) {
            LanguageRegistry.addName(identityDisk, "Identity Disk");
            LanguageRegistry.addName(baton, "Baton");
            EntityRegistry.registerModEntity(EntityIdentityDisk.class, "IdentityDisk", 5001, this, 40, 3, true);
            RenderingRegistry.registerEntityRenderingHandler(EntityIdentityDisk.class, new RenderSnowball(identityDisk));
        	KeyBindingRegistry.registerKeyBinding(new TajiKeyHandler());
        	MinecraftForge.EVENT_BUS.register(new TajiEvents());
        }
        @EventHandler
        public void postInit(FMLPostInitializationEvent event) {
                // Stub Method
        }
}

 

TajiEvents.java:

package taji34.troncraft;

import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingHurtEvent;

public class TajiEvents {
public boolean isPlayerDamage(DamageSource source)
{
	if ((source.getSourceOfDamage() != null) && !(source.isExplosion()) && !(source.isFireDamage()) && !(source.isMagicDamage()) && !(source.isProjectile()))
	{
		return true;
	}
	return false;
}
@ForgeSubscribe
public void entityAttacked(LivingHurtEvent event)
{
	EntityLiving attackedEnt = (EntityLiving) event.entityLiving;
	DamageSource attackSource = event.source;
	if (isPlayerDamage(attackSource))
	{
		EntityPlayer player = (EntityPlayer) attackSource.getSourceOfDamage();
		if(player.getHeldItem() != null)
		{
			ItemStack itemstack = player.getHeldItem();
			if (itemstack.getDisplayName().equals("Baton"))
			{
				NBTTagCompound tag = itemstack.getTagCompound();
				int damageAmmount = tag.getInteger("Damage");
				event.ammount = damageAmmount;
			}
		}
	}
}
public void onSound(SoundLoadEvent event) {
	event.manager.addSound("troncraft:freezer-hum.ogg");
}
}

 

IdentityDisk.Java:

package taji34.troncraft;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class IdentityDisk extends Item {
        public IdentityDisk(int id) {
                super(id);
                setMaxStackSize(1);
                setCreativeTab(CreativeTabs.tabMisc);
                setUnlocalizedName("identityDisk");
        }
        @Override
        @SideOnly(Side.CLIENT)
        public void registerIcons(IconRegister iconRegister) {
            this.itemIcon = iconRegister.registerIcon("troncraft:IdentityDisk");
        }
        public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5){
        	if (par5){
        		par2World.playSoundAtEntity(par3Entity, "troncraft:freezer-hum", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
        	}
        }
        public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
        {
            if (!par3EntityPlayer.capabilities.isCreativeMode)
            {
                --par1ItemStack.stackSize;
            }

            par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

            if (!par2World.isRemote)
            {
                par2World.spawnEntityInWorld(new EntityIdentityDisk(par2World, par3EntityPlayer));
            }

            return par1ItemStack;
        }
}

Posted
  On 7/29/2013 at 11:15 PM, GotoLink said:

Make sure you put @ForgeSubscribe on your SoundLoadEvent.

And that your sound is in mcp/src/minecraft/assets/troncraft/sound/..

the sound is in the correct area, and when I put @ForgeSubscribe before the SoundLoadEvent, all sound goes away...

Posted

Well you definately need the @ForgeSubscribe annotation. It's normal to surround the addSound() method with a try-catch statement. Do this and print in the catch part something like "Problem when trying to load TronCraft sounds".

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Posted
  On 7/31/2013 at 7:47 AM, MineMaarten said:

Well you definately need the @ForgeSubscribe annotation. It's normal to surround the addSound() method with a try-catch statement. Do this and print in the catch part something like "Problem when trying to load TronCraft sounds".

 

Sorry for the delay, was a bit busy the past couple of days. So now my onSound block reads:

public void onSound(SoundLoadEvent event) {
	try {
		event.manager.addSound("troncraft:freezer-hum.ogg");
	}
	catch(Exception e){ 
		System.out.println("Something went wrong loading Troncraft Sounds!");
	}
}

 

However, the same error is occurring without the catch printing anything to the console. I noticed something though, sound works fine up until I load a world, in which case this Exception prints to the console:

2013-08-01 15:35:20 [iNFO] [sTDERR] Exception in thread "Thread-13" java.lang.NullPointerException
2013-08-01 15:35:20 [iNFO] [sTDERR] 	at paulscode.sound.codecs.CodecJOrbis.readHeader(CodecJOrbis.java:448)
2013-08-01 15:35:20 [iNFO] [sTDERR] 	at paulscode.sound.codecs.CodecJOrbis.initialize(CodecJOrbis.java:301)
2013-08-01 15:35:20 [iNFO] [sTDERR] 	at paulscode.sound.libraries.LibraryLWJGLOpenAL.loadSound(LibraryLWJGLOpenAL.java:392)
2013-08-01 15:35:20 [iNFO] [sTDERR] 	at paulscode.sound.libraries.LibraryLWJGLOpenAL.newSource(LibraryLWJGLOpenAL.java:640)
2013-08-01 15:35:20 [iNFO] [sTDERR] 	at paulscode.sound.SoundSystem.CommandNewSource(SoundSystem.java:1800)
2013-08-01 15:35:20 [iNFO] [sTDERR] 	at paulscode.sound.SoundSystem.CommandQueue(SoundSystem.java:2415)
2013-08-01 15:35:20 [iNFO] [sTDERR] 	at paulscode.sound.CommandThread.run(CommandThread.java:121)

 

Then sound stops working everywhere, even after exiting the world. Upon exiting the game this prints to the console:

2013-08-01 15:38:04 [iNFO] [sTDOUT] SoundSystem shutting down...
2013-08-01 15:38:09 [iNFO] [sTDOUT] Error in class 'SoundSystem'
2013-08-01 15:38:09 [iNFO] [sTDOUT]     Command thread did not die!
2013-08-01 15:38:09 [iNFO] [sTDOUT] Ignoring errors... continuing clean-up.
2013-08-01 15:38:09 [iNFO] [sTDOUT]     Author: Paul Lamb, www.paulscode.com

 

Any ideas?

Posted

The sound may be too long.

 

 

And also, if the Item is in your hotbar, and it is supposed to PLAY the sound when it is in your hotbar, does it not make sense that the thread may have trouble "dying"?

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Posted
  On 8/8/2013 at 2:44 AM, Mew said:

The sound may be too long.

 

 

And also, if the Item is in your hotbar, and it is supposed to PLAY the sound when it is in your hotbar, does it not make sense that the thread may have trouble "dying"?

OK, do you know how long is too long? I want to create something like the industrialcraft machines the have a recurring sound. And It's only plays while it's in your hand, not just the hotbar, but yes that does make sense. Let me see what happens when I close the game with it not in my hand.

 

Edit: Alright, so the Sound error is only thrown when my custom sound tries to play. If I log on with the item not selected and log off without selecting it, sound plays fine with no errors or trouble closing the thread. However, if at any point I select the item, the error gets thrown and sound completely cuts out. The error seems to be what is causing the thread to have trouble closing. I am going to see if shortening the sound helps...

Posted

I'm very interested in the solution to this problem, I havent encountered it myself but sounds code fascinates me.

I hope you can report back when you find out something :)

 

How long is the sound file? I did manage to play rather large files without a problem although I didn't thread it :)

 

  Quote

If you guys dont get it.. then well ya.. try harder...

Posted
  On 8/8/2013 at 3:01 AM, Mazetar said:

I'm very interested in the solution to this problem, I havent encountered it myself but sounds code fascinates me.

I hope you can report back when you find out something :)

 

How long is the sound file? I did manage to play rather large files without a problem although I didn't thread it :)

 

It is currently 1:00 which is way longer than I need it to be now that i think about it. I'm going to shorten it to 0:10 to see if that works. If not, then I am going to shorten it to one second as a last resort to see if length is causing the problem.

Posted

That lenght is not the problem, you can confirm this easly by creating a custom block which plays the sound on activation/r-click!

 

I do have several sounds longer than 2 minutes and they work! :)

  Quote

If you guys dont get it.. then well ya.. try harder...

Posted
  On 8/8/2013 at 3:15 AM, Mazetar said:

That lenght is not the problem, you can confirm this easly by creating a custom block which plays the sound on activation/r-click!

 

I do have several sounds longer than 2 minutes and they work! :)

Ok, So If length isn't the problem, it has to be something with my code right? Could you please make sure I have everything and have it in the right place?

Posted
  On 8/8/2013 at 8:48 PM, GotoLink said:

Doesn't seem to be the code. Could be something in your file codec. How did you make it ?

I downloaded the original file of off the internet as a mp3. I manipulated it in Adobe Soundbooth CS4 saving it as an mp3 again (as soundbooth doesn't natively save to ogg) and then used an online converter to convert it to ogg.

Posted

I also have this issue and I'm curious on what fixes it. Any luck yet? I personally converted my sound using Audacity which, to my knowledge, is quite universal. Also, I used stone.ogg by Mojang as a replacement for my sound and it still doesn't work (it's in assets/modID/sound). So I can hardly imagine that the codec of the sound file is the issue.

 

Does it perhaps have anything to do with the fact that it asks for a pack.mcmeta for my mod?

 

I'm really stuck on this so I hope this gets solved.

 

Here is my code btw, just so you guys can check.

 

  Reveal hidden contents

 

 

 

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.