Jade ๐Ÿ”

Jade ๐Ÿ”

45M Downloads

Jade incorrectly computes the height of custom boss bars

Shadows-of-Fire opened this issue ยท 5 comments

commented

Mod loader

NeoForge

Minecraft version

1.20.1

Mod version

11.6.1

Modloader version

47.1.28

Modpack info

No response

If bug:

  • Can you reproduce this issue with relevant mods only?

If bug: The latest.log file

No response

Issue description

Jade uses the following computation to offset its position based on the active number of boss events:

	@Nullable
	public static Rect2i getBossBarRect() {
		Minecraft mc = Minecraft.getInstance();
		int size = mc.gui.getBossOverlay().events.size();
		if (size == 0) {
			return null;
		}
		int i = mc.getWindow().getGuiScaledWidth();
		int k = i / 2 - 91;
		int height = 10 + mc.font.lineHeight;
		size = Math.min(size, (mc.getWindow().getGuiScaledHeight() / 3 - 12) / height + 1);
		return new Rect2i(k, 12, 182, height * size);
	}

However, this discards changes made through the Forge event CustomizeGuiOverlayEvent.BossEventProgress which may increase the height of individual elements. While normally the height of a boss bar is 10 + Font#lineHeight, the event provides a setIncrement method used to report back the changed width.
Ignoring this produces undesireable results such as the following:

There are two potential ways to compute the real offset:

  1. Listen to all of these events with LOWEST priority (and receiveCanceled = true, because cancellation of this event does not mean nothing is drawn), and sum the values of getIncrement(), resetting them on some threshold (potentially in another event).
  2. Mixin to BossHealthOverlay#render and cache the value of the local j after all bars have rendered (after the for loop is completed). This could be done by setting the cached value to zero at the HEAD of the method and capturing j after line 45: j += event.getIncrement();
commented

Ah, so that's probably a bit better. These lines need to be removed, though https://github.com/Snownee/Jade/blob/1.20-forge/src/main/java/snownee/jade/util/ClientProxy.java#L239-L240

The increment of the event is still used even if the event is cancelled. If you need to evaluate a condition for bossBarShown you likely need to check getIncrement == 0.

commented

Oh, and reading this, this will not work if there are multiple bars on the screen, since this event is fired once for each bar, not once in general.

commented

How do you listen to the event? I'd like to see the code.

commented

How do you listen to the event? I'd like to see the code.

@Shadows-of-Fire