Jump to content

[1.7.2] Custom Music Disc Sounds [SOLVED]


Esophose

Recommended Posts

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 :)

Link to comment
Share on other sites

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}]}
   }

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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();
    }
}

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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

    • Hello! My friends and I were attempting to add a few extra mods to the Create Chronicles modpack, and all was well until people started crashing when they opened their inventories. Any help finding the culprit would be MUCH appreciated, I've been scratching my head for the past few days on what went wrong. https://paste.ee/p/8pajP
    • >>>KLIK LOGIN DISINI SAYANG<<< >>>KLIK DAFTAR DISINI SAYANG<<< Pendahuluan Dalam dunia perjudian online, slot menjadi salah satu permainan yang paling diminati. Dengan munculnya berbagai platform, Togel2Win hadir sebagai salah satu pilihan menarik, terutama dengan fitur anti rungkad yang dijanjikan. Artikel ini akan membahas tentang Togel2Win, keunggulan slot terbaru, dan bagaimana server Thailand berperan dalam meningkatkan pengalaman bermain. Apa Itu Togel2Win? Togel2Win adalah platform permainan yang menawarkan berbagai jenis permainan, termasuk slot dan togel. Dengan antarmuka yang ramah pengguna dan beragam pilihan permainan, situs ini bertujuan untuk memberikan pengalaman bermain yang menyenangkan dan menguntungkan bagi para pemain. Keunggulan Slot Togel2Win Fitur Anti Rungkad: Salah satu keunggulan utama dari Togel2Win adalah fitur anti rungkad yang dirancang untuk mengurangi kemungkinan gangguan saat bermain. Ini memastikan bahwa pemain dapat menikmati permainan tanpa gangguan teknis, meningkatkan kenyamanan dan fokus. Beragam Pilihan Slot: Togel2Win menawarkan berbagai jenis slot, dari yang klasik hingga yang modern dengan grafis menawan dan tema yang menarik. Ini memberikan variasi yang cukup bagi pemain untuk menemukan permainan yang sesuai dengan preferensi mereka. Server Thailand yang Stabil: Server yang berlokasi di Thailand memberikan koneksi yang cepat dan stabil. Ini sangat penting untuk pengalaman bermain yang lancar, terutama saat bermain slot yang memerlukan respons cepat. Bonus dan Promosi Menarik: Togel2Win sering menawarkan bonus dan promosi yang menarik untuk menarik pemain baru dan mempertahankan loyalitas pemain yang sudah ada. Ini bisa berupa bonus deposit, putaran gratis, atau program loyalitas. Tips untuk Pemain Slot di Togel2Win Pilih Slot dengan RTP Tinggi: Sebelum memulai permainan, pastikan untuk memilih slot dengan tingkat pengembalian pemain (RTP) yang tinggi untuk meningkatkan peluang menang. Kelola Anggaran: Tentukan batasan anggaran sebelum bermain dan patuhi itu. Ini membantu mencegah kerugian besar dan menjaga pengalaman bermain tetap menyenangkan. Manfaatkan Bonus: Jangan ragu untuk memanfaatkan bonus dan promosi yang ditawarkan. Ini bisa memberikan tambahan modal untuk bermain lebih lama. Kesimpulan Togel2Win merupakan pilihan menarik bagi para penggemar slot, terutama dengan fitur anti rungkad dan server yang stabil. Dengan berbagai pilihan permainan dan bonus yang menggiurkan, Togel2Win siap memberikan pengalaman bermain yang tak terlupakan. Jika Anda mencari platform slot yang andal dan menyenangkan, Togel2Win bisa menjadi solusi yang tepat.
    • I'm trying to make my own modpack, but sometimes, in certain areas of the world, the game just says "server closed". Minecraft doesn't close, it just returns to the menu. When I tried to figure it out on my own and understand the logs, I didn't understand anything (English is not my native language, so it's difficult for me). I've been trying to solve the problem for the third month. So I ask if anyone is good at this and it's not difficult for you, to help me with this. If you need details, ask. I'll describe everything. What it looks like Logs
  • Topics

×
×
  • Create New...

Important Information

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