Jump to content

Music Disc Issue [1.10/11.2]


turbodiesel4598

Recommended Posts

Hi there,

 

I'm trying to add a couple of music discs to the game - the general idea is to just extend the ItemRecord class and register instances. My discs are in the game, and can be inserted into jukeboxes, but their associated music does not play. Another hint that there is something wrong is that the name of the song does not appear above the hotbar as one would usually expect. Other sounds in the mod do work, by the way. I have probably just misinterpreted and misused some of the methods - here are the relevant classes and files:

 

NCItemRecord:

public class NCItemRecord extends ItemRecord {
	
	public final String[] info;
	private final String music;
	private final String name;
	
	public NCItemRecord(String unlocalizedName, String registryName, SoundEvent sound, Object... tooltip) {
		super("record_" + unlocalizedName, sound);
		name = unlocalizedName;
		setUnlocalizedName("record_" + unlocalizedName);
		setRegistryName(new ResourceLocation(Global.MOD_ID, "record_" + registryName));
		music = Global.MOD_ID + ":music." + unlocalizedName;
		
		if (tooltip.length == 0) {
			String[] strings = {};
			info = strings;
		} else if (tooltip[0] instanceof String) {
			String[] strings = new String[tooltip.length];
			for (int i = 0; i < tooltip.length; i++) {
				strings[i] = (String) tooltip[i];
			}
			info = strings;
		} else if (tooltip[0] instanceof Integer) {
			String[] strings = new String[(int) tooltip[0]];
			for (int i = 0; i < (int) tooltip[0]; i++) {
				strings[i] = I18n.translateToLocalFormatted("item." + "record_" + unlocalizedName + ".des" + i);
			}
			info = strings;
		} else {
			String[] strings = {};
			info = strings;
		}
	}
	
	public void addInformation(ItemStack itemStack, EntityPlayer player, List<String> tooltip, boolean advanced) {
		//super.addInformation(itemStack, player, tooltip, advanced);
		if (info.length > 0) NCInfo.infoFull(tooltip, info);
	}

	public ResourceLocation getRecordResource(String name) {
		return new ResourceLocation(Global.MOD_ID, "music." + name);
	}

	public EnumRarity getRarity(ItemStack stack) {
		return EnumRarity.EPIC;
	}
	
	@SideOnly(Side.CLIENT)
	public String getRecordNameLocal() {
		return I18n.translateToLocal("item.record_" + name + ".des0");
	}
}

 

Relevent part of registering:

public static Item record_wanderer;
public static Item record_end_of_the_world;
.
.
.
record_wanderer = new NCItemRecord("wanderer", "wanderer", SoundHandler.WANDERER, 2);
record_end_of_the_world = new NCItemRecord("end_of_the_world", "end_of_the_world", SoundHandler.END_OF_THE_WORLD, 2);
.
.
.
registerItem(record_wanderer, CommonProxy.TAB_MISC);
registerItem(record_end_of_the_world, CommonProxy.TAB_MISC);
.
.
.
registerRender(record_wanderer);
registerRender(record_end_of_the_world);

 

SoundHandler:

public class SoundHandler {
	
	private static int size = 0;
	
	public static SoundEvent FUSION_RUN;
	public static final int FUSION_RUN_TIME = 67;
	
	public static SoundEvent ACCELERATOR_RUN;
	public static final int ACCELERATOR_RUN_TIME = 67;
	
	public static SoundEvent WANDERER;
	public static SoundEvent END_OF_THE_WORLD;
	
	public static void init() {
		size = SoundEvent.REGISTRY.getKeys().size();
		
		FUSION_RUN = register("block.fusion_run");
		ACCELERATOR_RUN = register("block.accelerator_run");
		WANDERER = register("music.wanderer");
		END_OF_THE_WORLD = register("music.end_of_the_world");
	}
	
	public static SoundEvent register(String name) {
		ResourceLocation location = new ResourceLocation(Global.MOD_ID, name);
		SoundEvent event = new SoundEvent(location);
		
		SoundEvent.REGISTRY.register(size, location, event);
		size++;
		NCUtil.getLogger().info("Registered sound " + name);
		return event;
	}
}

 

sounds.json:

{
	"block.fusion_run": {
		"category": "block",
		"subtitle": "block.fusion_run",
		"sounds": [ { "name": "nuclearcraft:block/fusion_run", "stream": false } ]
	},
	"block.accelerator_run": {
		"category": "block",
		"subtitle": "block.accelerator_run",
		"sounds": [ { "name": "nuclearcraft:block/accelerator_run", "stream": false } ]
	},
	"music.wanderer": {
		"category": "record",
		"subtitle": "music.wanderer",
		"sounds": [ { "name": "nuclearcraft:music/wanderer", "stream": true } ]
	},
	"music.end_of_the_world": {
		"category": "record",
		"subtitle": "music.end_of_the_world",
		"sounds": [ { "name": "nuclearcraft:music/end_of_the_world", "stream": true } ]
	}
}

 

Thanks in advance :)

Edited by turbodiesel4598
Link to comment
Share on other sites

  • Did not know that, but I guess that's good practise if you want to minimise conflits, right? Probably a good idea then.
  • Yeh, it's not great, but the reason it's there is because I just copied it over from my base item class so that I could use the same naming system for the discs (because obviously I can't extent my base class in this case). I'll clean it up at some point. Are you saying it will crash when the language is changed? Because I haven't had any reports of it just crashing servers yet.
  • Yeh, I need to - I know it's bad pracice, and I just keep forgetting.
  • I'll get rid of it.

 

  • No errors show up when I insert the disc. Essentialy, nothing happens. The disc goes in and... silence. I tried using other sound files I know play correctly, and they didn't play either, and I also temporarily swapped out the standard furnace sound effect for the record music, and it did play, so I'm pretty sure that the issue is specifically with the music disc item, but I just don't know where the issue is - I even looked up other mods' classes (Botania and BoP), and they do nothing discernibly different, yet theirs seem to behave.

 

EDIT: Found the issue - I was registering my sounds after my items. The problem has now gone - thanks for the help.

Edited by turbodiesel4598
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.

×
×
  • Create New...

Important Information

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