Architectury API (UNUSED)

Architectury API (UNUSED)

9M Downloads

Help Needed: `AssertionError` during `runDatagen` in Architectury Project

DawsonBodenhamer opened this issue ยท 2 comments

commented

I'm in the final stages of migrating my 1.21.1 Fabric mod to an Architectury project and have hit a wall with data generation. When I run the runDatagen task, the game crashes during initialization with an AssertionError.

The crash seems to be caused by my @ExpectPlatform method for registering entity spawn restrictions.

Crash Log:

Caused by: java.lang.AssertionError
        at knot//net.dawson.adorablehamsterpets.world.ModSpawnPlacements.register(ModSpawnPlacements.java:18)
        at knot//net.dawson.adorablehamsterpets.AdorableHamsterPets.init(AdorableHamsterPets.java:64)
        at knot//net.dawson.adorablehamsterpets.fabric.AdorableHamsterPetsFabric.onInitialize(AdorableHamsterPetsFabric.java:14)

Here's the full Crash Log pastebin if you need it.

I've followed the standard @ExpectPlatform pattern, with an implementation for Fabric and one for NeoForge. The crash happens when the common code calls the @ExpectPlatform method.

I've double-checked my build.gradle files and the file paths for the implementation classes, but I can't spot the issue.

Here is the link to the full project repo

The relevant files are:

Any insight into why the AssertionError is being thrown would be greatly appreciated. Thank you!

commented

Ok so I "solved" that issue by wrapping the runtime-only initializers (like entity spawn placements) in my common init() method with a check (System.getProperty("fabric-api.datagen") == null) to prevent them from running during data generation.

That allowed datagen to complete successfully, but now I'm facing the same AssertionError when trying to launch the actual Fabric client.

The Main Problem:
The Fabric client fails to launch, crashing with an AssertionError. This happens when my common init() method calls ModSpawnPlacements.register(), which is a method annotated with @ExpectPlatform. This indicates that the common placeholder method is being executed instead of the Fabric-specific implementation.

I have already tried cleaning the Gradle cache multiple times and have added the architectury common entrypoint to my fabric.mod.json, but the issue persists.

The Secondary Problem:
Separately, when I run ./gradlew build, the resulting Fabric JAR file is nearly empty (around 25 bytes) and only contains a META-INF folder. This suggests a problem with how the shadowJar task is configured in my fabric/build.gradle.

I'm sure it's a configuration issue I'm just not seeing. Would hugely appreciate if you took a look!

Full Repo:

Direct Links to Key Files:

Thanks in advance for any help or insights!

commented

Figured it out. Massive thank you to @zemonkey and @fzzyhmstrs for the pointers that got me looking in the right direction.

After a solid 12 hours of debugging, the entire cascade of issues (ClassNotFoundException, @ExpectPlatform AssertionError, and the empty build JAR) was caused by one thing:

A package path mismatch between my fabric.mod.json entrypoint and the actual location of my Fabric initializer class.

Fabric Loader was looking for ...pets.fabric.AdorableHamsterPetsFabric, but the class was located in ...pets.AdorableHamsterPetsFabric. The initial ClassNotFoundException broke the entire Architectury runtime initialization, which is why the @ExpectPlatform stubs were never replaced.

The fix was to refactor my package structure:

  • Moved the Fabric entrypoint classes (AdorableHamsterPetsFabric, ...Client, ...DataGenerator) into a .../fabric/ sub-package to exactly match the path declared in fabric.mod.json.
  • Moved my @ExpectPlatform implementation (ModSpawnPlacementsImpl) to a more conventional .../world/fabric/ package to align with Architectury's conventions.

After that, a ./gradlew clean build produced a working JAR and the client launched perfectly. The empty root JAR was just a distraction from the real classpath issue.

Thanks again for the help everyone. Hopefully this saves someone else a headache lol