Jump to content

Recommended Posts

Posted

I have been struggling for numerous hours now trying to find the correct path needed to place my music disc sounds in. I'm not entirely sure if my sounds.json file is in the correc format, or in the correct path in the assets folder.

 

From what I have, it seems the path for the sound file should be assets/records/sounds but that doesn't make much sense... If anyone would be able to lead me in the correct path as to where the sound files should be located that would be great. If you could also skim through my sounds.json file and make sure it's right too that would be nice :)

 

Not sure if you will need any/all of this so i'll put it anyway.

 

Error I am getting while attempting to play the music disc in a Juke Box: Unable to play unknown soundEvent: minecraft:records.hey_brother

 

modid = "musics"

sound file name = "hey_brother.ogg"

 

sounds.json

 

 {
   "hey_brother": {"category": "master","record": [{"name": "hey_brother","stream": true}]}
   }

 

 

MusicsRecord.java

 

package com.gamc.musics.items;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.minecraft.block.BlockJukebox;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemRecord;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;

import com.gamc.musics.main.Musics;

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

public class MusicsRecord extends ItemRecord
{ 

private static final Map recordsMap = new HashMap();
    /** The name of the record. */
    public final String recordName;
    
    @SuppressWarnings("unchecked")
public MusicsRecord(String p_i45350_1_) {
	super(p_i45350_1_);
	this.recordName = p_i45350_1_;
        this.maxStackSize = 1;
        this.setCreativeTab(Musics.tabMusics);
        recordsMap.put(p_i45350_1_, this); //Forge Bug Fix: RenderGlobal adds a "records." when looking up below.
}

    /**
     * Gets an icon index based on an item's damage value
     */
    @SideOnly(Side.CLIENT)
    public IIcon getIconFromDamage(int par1)
    {
        return this.itemIcon;
    }

    /**
     * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
     * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
     */
    
    public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
    {
        if (par3World.getBlock(par4, par5, par6) == Blocks.jukebox && par3World.getBlockMetadata(par4, par5, par6) == 0)
        {
            if (par3World.isRemote)
            {
                return true;
            }
            else
            {
                ((BlockJukebox)Blocks.jukebox).func_149926_b(par3World, par4, par5, par6, par1ItemStack);
                par3World.playAuxSFXAtEntity((EntityPlayer)null, 1005, par4, par5, par6, Item.getIdFromItem(this));
                --par1ItemStack.stackSize;
                return true;
            }
        }
        else
        {
            return false;
        }
    }

    /**
     * allows items to add custom lines of information to the mouseover description
     */
    @SuppressWarnings("unchecked")
@SideOnly(Side.CLIENT)
    public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
    {
        par3List.add(this.getRecordNameLocal());
    }

    @SideOnly(Side.CLIENT)
    public String getRecordNameLocal()
    {
        return StatCollector.translateToLocal("item.record." + this.recordName + ".desc");
    }

    /**
     * Return an item rarity from EnumRarity
     */
    public EnumRarity getRarity(ItemStack par1ItemStack)
    {
        return EnumRarity.rare;
    }

    /**
     * Return the record item corresponding to the given name.
     */
    
    @SideOnly(Side.CLIENT)
    public static ItemRecord getRecord(String p_150926_0_)
    {
        return (ItemRecord)recordsMap.get(p_150926_0_);
    }

    /**
     * Retrieves the resource location of the sound to play for this record.
     * 
     * @param name The name of the record to play
     * @return The resource location for the audio, null to use default.
     */
    
    @Override()
    public ResourceLocation getRecordResource(String name)
    {
    	ResourceLocation mrl = new ResourceLocation(name);
        return mrl;
        
    }
}

 

 

Creating the Music Disc

 

public final static Item musics_hey_brother = new MusicsRecord("hey_brother").setUnlocalizedName("hey_brother").setTextureName(Musics.modid + ":" + "hey_brother");

 

 

If there is any more information you need to know, please let me know :)

Posted

When you define new sounds, you typically use

modid:soundname format, resulting in the sound being placed in

assets/modid/sounds/soundname.ogg

and the corresponding sounds.json would be:

{
   "soundname": {"category": "record","sounds": [{"name": "soundname","stream": true}]}
   }

Posted

Thank you for replying, this is my new sounds.json file that is essentially a copy of the default music disc format for the sounds. My sounds are placed in the correct folders and are named correctly because I am not getting any errors in the console from it. The sounds.json file is also loading below.

 

sounds.json

 

 {
   "records.hey_brother": {
     "category": "record",
 "sounds": [ 
   {
     "name": "records/hey_brother",
	 "stream": true
   }
]
  }
}

 

 

I am still getting the same error of Unable to play unknown soundEvent: musics:records.hey_brother though :L

Posted

Forgot to mension that I created a new MusicsResourceLocation class so Forge will check the right folder for the sounds and such. Not sure if its working as intended though lol.

 

 

package com.gamc.musics.items;

import net.minecraft.util.ResourceLocation;

import org.apache.commons.lang3.Validate;

public class MusicsResourceLocation extends ResourceLocation
{
    private final String resourceDomain;
    private final String resourcePath;

    public MusicsResourceLocation(String par1Str, String par2Str)
    {
    	super(par1Str, par2Str);
        Validate.notNull(par2Str);

        if (par1Str != null && par1Str.length() != 0)
        {
            this.resourceDomain = par1Str;
        }
        else
        {
            this.resourceDomain = "musics";
        }

        this.resourcePath = par2Str;
    }

    public MusicsResourceLocation(String par1Str)
    {
    	super(par1Str);
        String s1 = "musics";
        String s2 = par1Str;
        int i = par1Str.indexOf(58);

        if (i >= 0)
        {
            s2 = par1Str.substring(i + 1, par1Str.length());

            if (i > 1)
            {
                s1 = par1Str.substring(0, i);
            }
        }

        this.resourceDomain = s1.toLowerCase();
        this.resourcePath = s2;
    }

    public String getResourcePath()
    {
        return this.resourcePath;
    }

    public String getResourceDomain()
    {
        return this.resourceDomain;
    }

    public String toString()
    {
        return this.resourceDomain + ":" + this.resourcePath;
    }

    public boolean equals(Object par1Obj)
    {
        if (this == par1Obj)
        {
            return true;
        }
        else if (!(par1Obj instanceof MusicsResourceLocation))
        {
            return false;
        }
        else
        {
            MusicsResourceLocation resourcelocation = (MusicsResourceLocation)par1Obj;
            return this.resourceDomain.equals(resourcelocation.resourceDomain) && this.resourcePath.equals(resourcelocation.resourcePath);
        }
    }

    public int hashCode()
    {
        return 31 * this.resourceDomain.hashCode() + this.resourcePath.hashCode();
    }
}

 

Posted

Sorry for kinda spamming my own post :L

 

Now I'm seriously confused. If I use player.playSound("musics:records.hey_brother" 1F, 1F); it actually plays the music disc sound correctly, but it is unable to find the sound when putting the disc into a jukebox. Anyone know a fix for this?

Posted

I suggest you post the MusicRecords with the minimal amount of code you want to change from it.

Remove everything that you copied from the parent class ItemRecord.

Not sure why you would need to change the ResourceLocation. It should work as-is.

Posted

Thanks for helping :)

 

I cleaned up the MusicsRecord class, didn't seem to change much but it did make it much neater. I need to have a custom resource location or else the game will try loading the sounds from the minecraft assets folder instead of the musics assets folder.

 

MusicsRecord.java

 

package com.gamc.musics.items;

import net.minecraft.item.ItemRecord;

import com.gamc.musics.main.Musics;

public class MusicsRecord extends ItemRecord
{ 
    
public MusicsRecord(String recordName) {
	super(recordName);
        this.setCreativeTab(Musics.tabMusics);
}
    
    @Override()
    public MusicsResourceLocation getRecordResource(String name)
    {
    	MusicsResourceLocation mrl = new MusicsResourceLocation(name);
        return mrl;
   }
}

 

 

EDIT: Furthing looking into the ResourceLocation class it looks like you can just specify what I need to edit. Deleting the MusicsResourceLocation class, as it is now pointless.

Posted

Turns out the custom class MusicsResourceLocation was breaking it. I should have looked at ResourceLocation better. Thanks for all the help :D

 

Problem Solved.

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.