Jump to content

[SOLVED] [1.12.2] Music Disc inserted in Jukebox doesn't play music


Recommended Posts

Posted (edited)

Hi, I have a problem with my music discs. Even though the sound EXISTS, cause I can play it with playsound, when I put the disc into the jukebox, it doesn't play the music or show the "Now playing:" thing.

package com.lorenzopapi.portalgun.common.item;

import java.util.List;

import com.lorenzopapi.portalgun.common.PortalGun;
import com.lorenzopapi.portalgun.common.core.SoundIndex;

import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemRecord;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraft.world.World;

public class ItemRecords extends ItemRecord {

	private final SoundEvent soundIn;
	
	public ItemRecords(String name, SoundEvent sound, String registryName, String unlocalizedName) {
		super(name, sound);
		this.soundIn = sound;
		this.setUnlocalizedName(unlocalizedName);
		this.setRegistryName(registryName);
		this.setCreativeTab(PortalGun.creativeTab);
		
	}

@Override
    public EnumRarity getRarity(ItemStack stack)
    {
        return EnumRarity.RARE;
    }
}

This is my SoundIndex:

package com.lorenzopapi.portalgun.common.core;

import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.RegistryEvent.Register;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraft.util.SoundEvent;

public class SoundIndex
{
    public static SoundEvent r_records_still_alive;
	public static SoundEvent r_records_want_you_gone;
	
    public static void init(final Register<SoundEvent> registry) {
        SoundIndex.r_records_still_alive = register(registry, "records.still_alive");
        SoundIndex.r_records_want_you_gone = register(registry, "records.want_you_gone");
        }
    
    private static SoundEvent register(final RegistryEvent.Register<SoundEvent> event, final String name) {
        final ResourceLocation rs = new ResourceLocation("portalgun", name);
        final SoundEvent soundEvent = (SoundEvent)new SoundEvent(rs).setRegistryName(rs);
        event.getRegistry().registerAll(soundEvent);
        return soundEvent;
    }
}

 

 

Edited by LorenzoPapi
Posted

do you have a resources/assets/modid/sounds.json file? if not, stop and see a working example.

do you have a resources/assets/modid/sounds/records/songname.ogg file? if not, see a working example.

Posted

Yes I have the sound, in fact I can play it with the /playsound command. The problem is that when I put the disc in the jukebox, it doesn't play the music and it doesn't show the "Now Playing: disc name" line.

Posted

probably sounds.json.

 

try mine:

 

 


 

{
    "record.song1": {
        "category": "record",
        "sounds": [
            {
                "name": "yourmodid:records/song1",
                "stream": true
            }
        ],
        "subtitle": "subtitle1"
    }

}

 

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

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

 

Posted

Your sounds.json looks good, as well as your registration of the SoundEvents. Can you also show your initialization/registration of the music discs, as well as the file path of the sounds.json?

Posted (edited)

These are the items. I already tried by changing Item to ItemRecord, no success.

public static Item itemRecordStillAlive;
public static Item itemRecordWantYouGone;

 

This is the items initialization:

@SubscribeEvent
public void onRegisterItem(RegistryEvent.Register<Item> event) {
  PortalGun.itemRecordStillAlive = new ItemRecords("Still Alive", SoundIndex.r_records_still_alive, "portalgun:item_record_still_alive","record");
  PortalGun.itemRecordWantYouGone = new ItemRecords("Want You Gone", SoundIndex.r_records_want_you_gone, "portalgun:item_record_want_you_gone",  "record");
event.getRegistry().register(PortalGun.itemRecordStillAlive);
event.getRegistry().register(PortalGun.itemRecordWantYouGone);
}

 

This is the model initialization:

@SubscribeEvent
public void onModelRegistry(final ModelRegistryEvent event) {
    ModelLoader.setCustomModelResourceLocation(PortalGun.itemRecordStillAlive, 0, new ModelResourceLocation("portalgun:item_record_still_alive", "inventory"));
    ModelLoader.setCustomModelResourceLocation(PortalGun.itemRecordWantYouGone, 0, new ModelResourceLocation("portalgun:item_record_want_you_gone", "inventory"));
}

 

Edited by LorenzoPapi
Posted (edited)

Try changing onRegisterSoundEvent to static

 

Edit: Also, the issue may be that items are being initialized before the sounds are. In that case, in FMLPreInitializationEvent, you need to instantiate the sounds, and in RegistryEvent.Register<SoundEvent>, you need to register them.

Edited by kaydogz
Posted

Ok I've changed it to static... and now it doesn't load the sounds at all. Strange.

Then, the sounds are already called in pre-init and as I see when I start Minecraft, Forge automatically starts by loading the sounds up.

Now, could you tell me why did I have to change it to static, since the sounds doesn't load if I do so?

Btw, I've added a laser sound to a sword, that played when you right-click with the item, just to test if it worked, and it did.
So, is it a record problem/bug?

Posted
7 minutes ago, LorenzoPapi said:

 So, is it a record problem/bug?

As their edit points out you need to initialize your sounds in the Item registry event and then register those instances in the sound registry event.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)

What do you mean by 'the sounds are already called in preinit"

 

The problem is that forge registers items before soundevents. Your records don't play sound because when they were registered, the soundevents were null. Basically, you need to make it so that the soundevents are instantiated before the registration of items. You can do this in FMLPreInitializationEvent, because it fires before registration. You need to move this line

soundEvent = (SoundEvent)new SoundEvent(rs).setRegistryName(rs);

so that it gets called in FMLPreInitializationEvent. And in RegistryEvent.Register<SoundEvent>, you just need to pass each of the soundevents in event.getRegistry.registerAll(). If that doesn't work, remove the static from onRegisterSoundEvent.

 

Also, the reason your sword works is because it uses the onItemRightClick (or something like that) method to play the sound, while records have the sound as a parameter.

Edited by kaydogz
  • Thanks 1
Posted
10 hours ago, LorenzoPapi said:

Can you show me a working example please?

Here's some pseudo code

Register items

   SOUND_1 = new SOUND...

   // DO ITEM REGISTRATION

 

RegisterSounds

   // DO SOUND REGISTRATION

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

  • LorenzoPapi changed the title to [SOLVED] [1.12.2] Music Disc inserted in Jukebox doesn't play music

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

    • Also check the worldsave / serverconfig folder If there is no such file, make a test without this mod  
    • Hi, I've been having trouble trying to use forge as it shows a black screen when I open the game, but I can still interact with it and hear the music.  I've done all of the step by steps and most common fixes like updating drivers, keeping up to date with Java, deleting and reinstalling minecraft, restarting my computer MANY times, even smaller things like splash.properties (I didn't have that file so I added it and set it to false thinking it would do something, definitely not) and making sure to prioritize my rtx 3070 in the settings but with no luck. Minecraft works as intended when I uninstall forge and I also don't have any mods currently, it just gives me this issue when I install forge. I also increased the ram usage, made sure my hardware isn't full or anything, and even changed the resolution in hopes it would fix things. I checked my antivirus and firewall but that isn't the issue either. Trust me, I've done everything I can think of. For some reason the black screen does flicker a little into the main menu, but obviously unplayable. I couldn't even make my way to the settings with how little it flickered. I'm not sure if it flickered randomly or if it was because I was messing around moving and clicking a bunch, I didn't really test it that much.  
    • I've had a really weird issue recently,  I wanted to add the Depper and Darker mod on my dedicated server (MC 1.21 with Fabric 0.16.9, hosted on nitroserv.com) but whenever I do add the mod the sever stops doing anything after listing the mods, and I get no crash or error or anything, just a stuck server. Here's a normal log of the server booting up: https://pastebin.com/JipFF2Eh and here's the log of the server doing the weird thing: https://pastebin.com/W4JBh3eX I just don't understand it. I've tried removing other mods (somewhat randomly) but deeper and darker still breaks my server whenever I add it. NitroServ support staff is about as confused as I am and I've had no response from the Deeper and Darker support staff... Now I know this is the Forge support not the Fabric support but I'm just trying to know if anyone has any kind of idea to fix this (aside from not using the mod obviously) Also I still have a bunch of errors and warnings whenever the server does start properly, are there any of them I should be worried about?
  • Topics

×
×
  • Create New...

Important Information

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