Jump to content

Recommended Posts

Posted

Hello everyone. I am new to modding with Forge (used to use ModLoader), and I have encountered a problem when trying to play my sounds for my mod. I follow the tutorial, and this is the code that I put(I only included the parts that play the sound):

 

ModMagicItems_EventSounds:

 


package magicItems.common;

import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;

public class MagicItems_EventSounds
{

@ForgeSubscribe
    public void onSound(SoundLoadEvent event)
    {
        try 
        {
            event.manager.soundPoolSounds.addSound("/folder/mirrorsound.wav", ModMagicItems.class.getResource("/spelssounds/sounds/folder/mirrorsound.wav"));            
        
        } 
        catch (Exception e)
        {
            System.err.println("Failed to register one or more sounds.");
        }
    }

}

 

 

My BaseMod File:

 


@Init
    public void load(FMLInitializationEvent initEvent){

        
        //Sounds
        
        MinecraftForge.EVENT_BUS.register(new MagicItems_EventSounds());
}

 

ItemMirror:

 


public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) 
{


		world.playSoundAtEntity(player, "spelssounds.mirror", 1.0F, 1.0F);
                        
                        
}

 

I'm pretty sure that I named the folders correctly and everything. I even tried exporting the mod, and putting it in my real minecraft.jar and playing it, but the sound just simply would not play. Does anybody know what I am doing wrong? Thanks!

Posted

Change your code to:

 

ModMagicItems_EventSounds:

 


package magicItems.common;

import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;

public class MagicItems_EventSounds
{

@ForgeSubscribe
    public void onSound(SoundLoadEvent event)
    {
        try 
        {
            event.manager.soundPoolSounds.addSound("/magicItems/mirrorsound.wav", "magicItems/spelssounds/sounds/folder/mirrorsound.wav");            
        // So you should have mirrorsound.wav in your "src/common/magicItems/spelssounds/sounds/folder" folder and after compiling you should put it into "magicItems.zip/common/spelssounds/sounds/folder"
        } 
        catch (Exception e)
        {
            System.err.println("Failed to register one or more sounds.");
        }
    }

}

 

 

BaseMod File:

 


@PreInit
    public void load(FMLInitializationEvent initEvent){

        
        //Sounds
        
        MinecraftForge.EVENT_BUS.register(new MagicItems_EventSounds());
}

 

ItemMirror:

 


public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) 
{


		world.playSoundAtEntity(player, "magicItems.mirrorsound", 1.0F, 1.0F);
                        
                        
}

Posted

I tried what you told me and it still didn't work, even when I exported it. I put the folders in everywhere you told me to put it, but it wasn't working :(

 

MagicItems_EventSounds:

 


@ForgeSubscribe
    public void onSound(SoundLoadEvent event)
    {
        try 
        {
            event.manager.soundPoolSounds.addSound("/magicItems/mirrorsound.ogg", ModMagicItems.class.getResource("magicItems/spelssounds/sounds/folder/mirrorsound.ogg"));            
        
        } 
        catch (Exception e)
        {
            System.err.println("Failed to register one or more sounds.");
        }

 

ModBase:

 


@PreInit
    public void load(FMLInitializationEvent initEvent)
{

	//Declare names


        
        //Recipes
        
        
        //Sounds
        
        MinecraftForge.EVENT_BUS.register(new MagicItems_EventSounds());
}

 

ItemMirror:

 


public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) 
{

	if (world.isRemote) 
	{
		return item;
	}


		player.addChatMessage("Commencing teleportation to bed.");
		world.playSoundAtEntity(player, "magicItems.mirrorsound", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 0.8F));
                        
	} 

Posted

Ok, so I modified them a bit, and this is my new code:

 

MagicItems_EventSounds:

 


package magicItems.common;

import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.event.ForgeSubscribe;

public class MagicItems_EventSounds
{

@ForgeSubscribe
    public void onSound(SoundLoadEvent event)
    {
        try 
        {
        	event.manager.soundPoolSounds.addSound("/folder/mirrorsound.ogg", ModMagicItems.class.getResource("/spelssounds/sounds/folder/mirrorsound.ogg"));
        
        } 
        catch (Exception e)
        {
            System.err.println("Failed to register one or more sounds.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
        }
    }

}

 

ModBase:

 


@PreInit
public void preInit(FMLPreInitializationEvent event) 
{

	MinecraftForge.EVENT_BUS.register(new MagicItems_EventSounds());

}

 

 

ItemMirror:

 


public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player) 
{
	world.playSoundAtEntity(player, "folder.mirrorsound", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
	System.out.println("SOUND PLAYED@@@@@@@@@");
	return item;
}

Posted

event.manager.soundPoolSounds.addSound("/folder/mirrorsound.ogg", ModMagicItems.class.getResource("/spelssounds/sounds/folder/mirrorsound.ogg"));

The first path is wrong. You shouldn't have a slash at the beginning. It should be like:

"folder/mirrorsound.ogg"

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

event.manager.soundPoolSounds.addSound("/folder/mirrorsound.ogg", ModMagicItems.class.getResource("/spelssounds/sounds/folder/mirrorsound.ogg"));

The first path is wrong. You shouldn't have a slash at the beginning. It should be like:

"folder/mirrorsound.ogg"

 

I tried that and got an error in the console:

 

2012-10-31 15:05:43 [iNFO] [sTDOUT] SOUND PLAYED@@@@@@@@@
2012-10-31 15:05:43 [iNFO] [sTDOUT] SOUND PLAYED@@@@@@@@@
2012-10-31 15:05:43 [iNFO] [sTDOUT] Error in class 'LibraryLWJGLOpenAL'
2012-10-31 15:05:43 [iNFO] [sTDOUT]     Unable to open file 'folder/mirrorsound.wav' in method 'loadSound'
2012-10-31 15:05:43 [iNFO] [sTDOUT] Error in class 'LibraryLWJGLOpenAL'
2012-10-31 15:05:43 [iNFO] [sTDOUT]     Source 'sound_3' was not created because an error occurred while loading folder/mirrorsound.wav

 

The path to my sound is MCP>src>common>magicItems>spelssounds>sound>folder>mirrorsound.wav

 

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • You would have better results asking a more specific question. What have you done? What exactly do you need help with? Please also read the FAQ regarding posting logs.
    • Hi, this is my second post with the same content as no one answered this and it's been a long time since I made the last post, I want to make a client-only mod, everything is ok, but when I use shaders, none of the textures rendered in RenderLevelStageEvent nor the crow entity model are rendered, I want them to be visible, because it's a horror themed mod I've already tried it with different shaders, but it didn't work with any of them and I really want to add support for shaders Here is how i render the crow model in the CrowEntityRenderer<CrowEntity>, by the time i use this method, i know is not the right method but i don't think this is the cause of the problem, the renderType i'm using is entityCutout @Override public void render(CrowEntity p_entity, float entityYaw, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight) { super.render(p_entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); ClientEventHandler.getClient().crow.renderToBuffer(poseStack, bufferSource.getBuffer(ClientEventHandler.getClient().crow .renderType(TEXTURE)), packedLight, OverlayTexture.NO_OVERLAY, Utils.rgb(255, 255, 255)); } Here renderLevelStage @Override public void renderWorld(RenderLevelStageEvent e) { horrorEvents.draw(e); } Here is how i render every event public void draw(RenderLevelStageEvent e) { for (HorrorEvent event : currentHorrorEvents) { event.tick(e.getPartialTick()); event.draw(e); } } Here is how i render the crow model on the event @Override public void draw(RenderLevelStageEvent e) { if(e.getStage() == RenderLevelStageEvent.Stage.AFTER_ENTITIES) { float arcProgress = getArcProgress(0.25f); int alpha = (int) Mth.lerp(arcProgress, 0, 255); int packedLight = LevelRenderer.getLightColor(Minecraft.getInstance().level, blockPos); VertexConsumer builder = ClientEventHandler.bufferSource.getBuffer(crow); Crow<CreepyBirdHorrorEvent> model = ClientEventHandler .getClient().crow; model.setupAnim(this); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, packedLight, OverlayTexture.NO_OVERLAY, alpha); builder = ClientEventHandler.bufferSource.getBuffer(eyes); RenderHelper.renderModelInWorld(model, position, offset, e.getCamera(), e.getPoseStack(), builder, 15728880, OverlayTexture.NO_OVERLAY, alpha); } } How i render the model public static void renderModelInWorld(Model model, Vector3f pos, Vector3f offset, Camera camera, PoseStack matrix, VertexConsumer builder, int light, int overlay, int alpha) { matrix.pushPose(); Vec3 cameraPos = camera.getPosition(); double finalX = pos.x - cameraPos.x + offset.x; double finalY = pos.y - cameraPos.y + offset.y; double finalZ = pos.z - cameraPos.z + offset.z; matrix.pushPose(); matrix.translate(finalX, finalY, finalZ); matrix.mulPose(Axis.XP.rotationDegrees(180f)); model.renderToBuffer(matrix, builder, light, overlay, Utils .rgba(255, 255, 255, alpha)); matrix.popPose(); matrix.popPose(); } Thanks in advance
    • Same issue - I have no idea
    • I am trying to develop a modpack for me and my friends to use on our server. Does anyone know how to develop a modpack for a server or could they help take a look at my modpack to potentially help at all?
    • un server de armas realista.  
  • Topics

×
×
  • Create New...

Important Information

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