architectury / architectury-plugin

A simple gradle plugin to enable developing multiplatform mods.
MIT License
56 stars 19 forks source link

Built Fabric jar using incorrect refmap #43

Open ejektaflex opened 6 months ago

ejektaflex commented 6 months ago

When I try to build my JAR file for Fabric, I get this error:

 Mixin apply for mod kambrik failed kambrik.mixins.json:StructurePoolAccessor from mod kambrik -> net.minecraft.class_3785: org.spongepowered.asm.mixin.gen.throwables.InvalidAccessorException No candidates were found matching elements:Lit/unimi/dsi/fastutil/objects/ObjectArrayList; in net/minecraft/class_3785 for kambrik.mixins.json:StructurePoolAccessor from mod kambrik->@Accessor[FIELD_GETTER]::getElements()Lit/unimi/dsi/fastutil/objects/ObjectArrayList; [INJECT Applicator Phase -> kambrik.mixins.json:StructurePoolAccessor from mod kambrik -> Apply Accessors ->  -> Locate -> kambrik.mixins.json:StructurePoolAccessor from mod kambrik->@Accessor[FIELD_GETTER]::getElements()Lit/unimi/dsi/fastutil/objects/ObjectArrayList;]

StructurePoolAccessor is a Mixin in Kambrik, my mod.

I noticed that the .jar file contains a Kambrik-common-refmap.json. It's unused in kambrik.mixins.json. If I add the following line to kambrik.mixins.json:

    "refmap": "Kambrik-common-refmap.json"

The mod will launch successfully. As such, it seems that refmaps aren't being linked properly. I don't know much about how refmaps work, or how they're supposed to work, but this is what seems to be happening. It happens with ArchLoom 1.4-SNAPSHOT and 1.5-SNAPSHOT.

Juuxel commented 6 months ago

Do you have Architectury Plugin installed? It should fix this issue, which really isn't a Loom issue (the mixin config is in the common Gradle project, so its refmap property would need to be added in :common:remapJar, which isn't run here due to the project structure).

ejektaflex commented 6 months ago

What would I have to set in my remapJar task? Here is my current remapJar, but it doesn't run for common: https://github.com/ejektaflex/Bountiful/blob/96f85f641b2d0c42f7de77834482deaee21789e3/build.gradle.kts#L111

Juuxel commented 6 months ago

You can't fix it by tweaking remapJar settings since remapJar only does the refmap name adding for a mixin config from the current Gradle project. Architectury Plugin does it separately with its custom task.

The easiest solutions are using Architectury Plugin (in compile-only mode if needed) or specifying the refmap name manually in the mixin config.

ejektaflex commented 6 months ago

Cool, I've fixed this by doing:

loom {
    mixin {
        defaultRefmapName.set("Bountiful-common-refmap.json")
    }
}

Do you have an example of how this is done using Architectury Plugin? I'm depending on it in my gradle setup, but I don't exactly know how to utilize it.

Thanks so much!

Juuxel commented 6 months ago

If you include the common classes in the Fabric jar by bundling :common's transformProductionFabric configuration, it'll apply the transformers. Example from Arch API's code: https://github.com/architectury/architectury-api/blob/cd74016d85b562affb21890cb8796b1e34ac2ca9/fabric/build.gradle#L33

ejektaflex commented 6 months ago

It's my understanding that I'm already doing this. Could the problem arise because I'm not including transitive dependencies?

My code: https://github.com/ejektaflex/Bountiful/blob/d6e52965fc5b631e2160534f4fa83ccc63104b49/fabric/build.gradle.kts#L50C1-L50C114

Juuxel commented 6 months ago

No, I don't think it affects anything since that project dependency won't even have any transitive deps. As far as I can tell, the code should already work 🤔

I also don't think this is directly related to Loom, so I'm moving the issue to Arch Plugin's repo.