Jump to content

Get boss bars visible to player


Recommended Posts


Thanks, unfortunately, this is a client-side only mod.

However, I did manage to resolve my problem using a little bit of reflection.

In case anyone else ever needs it, here's my solution:


	public static List<String> getBossBarNames(Minecraft minecraft) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
		GuiBossOverlay bossOverlay = minecraft.ingameGUI.getBossOverlay();

		String nameAfter = null;
		// Find the name of the field as it will change with each obfuscation of forge
		// If you're using this, you'll want to move this lookup elsewhere and store the result
		for (Field s : GuiBossOverlay.class.getDeclaredFields()) {
			if (s.getType().getName().equals("java.util.Map")) {
				nameAfter = s.getName();
		List<String> names = new ArrayList<String>();
		if (nameAfter != null) {
			Field bossField = GuiBossOverlay.class.getDeclaredField(nameAfter);
			Map<UUID, BossInfoLerping> mapBossInfos = (Map<UUID, BossInfoLerping>) bossField.get(bossOverlay);
			for (BossInfoLerping bIL : mapBossInfos.values())
		return names;


Edited by Craftiii4
Fix possible npe
  • Like 1
Link to comment
Share on other sites

Just now, diesieben07 said:

Then why did you say "on the server"? o.O


As for your reflection code:

  • Do not use getClass. Use a static .class reference.
  • Do not use that field-detection magic. Use the actual field name (SRG and MCP name).
  • Only look up the Field instance once and then store it in a static final field.
  • Don't cast to HashMap if the field is only of type Map.


By on server I meant that the boss bar is on the server, e.g. "Welcome to thisserver.com"


Thanks for the tips, I do only look up field once, just modified it slightly before I added the code here so it would work as a standalone function.

Link to comment
Share on other sites

Just now, diesieben07 said:

Just for the future, this is very counter-productive.

Was experimenting with the boss related classes trying to get the output out I wanted, so granted it's not the best reflection ever written. I'll modify my above code to reflect the changes suggested, thanks again!

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.

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.