AtomicStryker's Magic Yarn

AtomicStryker's Magic Yarn

82.8k Downloads

[Finder Compass] Crashes in MC 1.21.8 - Includes a fix

grickaby opened this issue · 3 comments

commented

Environment

  • Minecraft: 1.21.8
  • NeoForge: 21.8.47
  • FinderCompass: 1.21.5.2NF
  • Java: 21.0.7 (Microsoft build)

Steps to reproduce

  1. Place findercompass-1.21.5.2NF.jar into a 1.21.8 NeoForge instance.
  2. Launch the game.

Observed behavior
The game crashes at startup with:
java.lang.NoClassDefFoundError: net/minecraft/client/gui/LayeredDraw$Layer`

Expected behavior
Finder Compass should load correctly on 1.21.8 NeoForge.

Root cause
The mod was compiled against MC 1.21.5, which still had net.minecraft.client.gui.LayeredDraw$Layer.
That class was renamed/removed in 1.21.6+, causing a NoClassDefFoundError on newer versions.

Suggested fix
Port the overlay registration to the new GUI system in 1.21.6+:

  1. Register a GUI layer using RegisterGuiLayersEvent:
@Mod.EventBusSubscriber(modid = FinderCompass.MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public final class FCClientLayers {
    private static final ResourceLocation LAYER_ID =
            new ResourceLocation(FinderCompass.MODID, "finder_compass_overlay");

    @SubscribeEvent
    public static void onRegisterGuiLayers(RegisterGuiLayersEvent e) {
        e.registerAboveAll(LAYER_ID, FCClientLayers::renderOverlay);
    }

    private static void renderOverlay(GuiGraphics gg, float partialTick) {
        FinderCompassOverlay.render(gg, partialTick);
    }
}
  1. Update rendering code to use GuiGraphics:
public final class FinderCompassOverlay {
    public static void render(GuiGraphics gg, float partialTick) {
        // gg.blit(texture, x, y, u, v, width, height);
        // gg.drawString(minecraft.font, "Shiny Stones", x, y, 0xFFFFFF, true);
        // existing needle math + drawing logic
    }
}

Remove all imports/usages of LayeredDraw$Layer.

  1. Recompile against MC 1.21.8 + NeoForge 21.8.x.

Recommendation
Also pin the supported Minecraft/NeoForge versions in neoforge.mods.toml to prevent runtime crashes if users load a mismatched jar:

[[dependencies.findercompass]]
   modId="neoforge"
   versionRange="[21.8,21.9)"
   side="CLIENT"

[[dependencies.findercompass]]
   modId="minecraft"
   versionRange="[1.21.8,1.21.9)"
   side="CLIENT"

Backwards compatibility note
If support for both 1.21.5 and 1.21.8 is desired, consider splitting client overlay code per-version (≤1.21.5 vs ≥1.21.6) while keeping compass logic in a shared core, and publish separate jars with strict version ranges. This avoids NoClassDefFoundError while allowing users to stay on older worlds.

commented

No, 1.21.5 Finder compass is not expected to work on MC 1.21.8, they are different versions.

You will find i have in fact updated Finder Compass code for each new MC version, see

https://github.com/AtomicStryker/atomicstrykers-minecraft-mods/tree/1.21.7NF/FinderCompass
https://github.com/AtomicStryker/atomicstrykers-minecraft-mods/tree/1.21.8NF/FinderCompass

But there is a difference in behaviour regarding the render pipeline and i was unable to get needle rendering to work again. It's a matter of the render state machine which someone has to painfully guess their way through, and i dont care to invest the time.

commented

Thank you for those links. The reason I brought up the issues is because when downloading the mod from a mod site, the 1.21.5 version is what it gave me. So i had assumed it was "broken". I didn't noticed that you had more current versions.

I ended up building a mod similar to yours, but it puts an overlay on the hud, rather than using a compass.

commented

I havent released more current builds since they dont work, so 1.21.5 is the latest release. If you can get it to work i would welcome a pull request, otherwise i shall close this, thanks.