Jump to content

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


LorenzoPapi

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 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

    • @bluedisgusted That actually fully fixed it, thank you so much
    • Hi, I would like to know how to create multiple hitboxes for the player like the ender dragon. I've searched everywhere but I haven't found anything.
    • FOLKWIN EXPERT RECOVERY is the crypto hero we all need in the ongoing battle against cryptocurrency theft. With the rise in popularity of digital assets like Bitcoin and Ethereum, crypto crime has also been on the rise as hackers look to steal funds stored in virtual wallets. Many a crypto investor has fallen victim to clever scams and hacking schemes that drain wallets of their precious coins. But fear not, for FOLKWIN EXPERT RECOVERY has arrived as a beacon of hope for those who have had their hard-earned crypto stolen. This service is like a superhero for tracking down lost or stolen cryptocurrency, utilizing their advanced forensic technology and expertise to follow the blockchain paper trail and identify where your funds have gone. Their team of ethical hackers act like detectives, piecing together crypto transactions and unmasking the thieves behind complex cybercrimes. No case is too difficult for FOLKWIN EXPERT RECOVERY; they have recovered millions in stolen crypto assets from around the globe. Their mission is to reunite victims with their lost funds and bring criminals who prey on cryptocurrency investors to justice. With their help, those who have been robbed of their digital fortunes now have a crypto guardian to call upon in their time of need. FOLKWIN EXPERT RECOVERY gives victims the hope that all is not lost forever when crypto theft occurs.For support, Contact details is: TELEGRAM: @FOLKWIN_EXPERT_RECOVERY, EMAIL: FOLKWINEXPERTRECOVERY at TECH-CENTER dot COM, WEBSITE: WWW.FOLKWINEXPERTRECOVERY.COM .  are the heroes we need in the ongoing battle to make cryptocurrency ownership safe and secure for all. Get FOLKWIN EXPERT RECOVERY on your side when you have issues like this by dialing: Do this and thank me later. God Blessings to all, I'm forever grateful oh God for the successful recovery. I recommend FOLKWIN EXPERT RECOVERY the best ever and i'm so happy i got all my lost money back. Best Regards. Pamela K Ingram.
    • Made it work. As a note, one of the times it didn't recognize the recipe cause the MOD_ID constant I was using somewhere was NOT referencing my MOD_ID but rather another static variable with the same name. Maybe OP is having a similar problem
    • What exactly is the issue?
  • Topics

×
×
  • Create New...

Important Information

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