跳到正文
DEV Community· Mohammad Mostafa Dastjerdi·· 4 小時前AI 評分53

jdx 教學:如何找出 mods 資料夾中實作 Fabric 或 Minecraft 類型的類別

Which mods hook into this? Find every implementor of a Fabric or Minecraft type across a mods folder

AI 導讀

jdx 是開源 CLI 和 MCP 伺服器,可在 mods 資料夾內搜尋實作指定 Fabric 或 Minecraft 類型的類別,並列出所屬 JAR。

正文

Mohammad Mostafa Dastjerdi

A modpack crashes, a log line names an interface, and the real question is: which of these 200 jars actually implements it? In an IDE that is one click on "Find implementations". In a folder full of mod jars it usually means unzipping everything or loading the whole pack into a dev workspace.

jdx is an open-source CLI and MCP server (Kotlin, Java 21+, Apache-2.0) that answers IDE questions about any JVM jar. It reads bytecode with ASM and never loads or runs the classes it inspects. This post is about one of those questions: who implements this type?

Every mod's entrypoint, in one command

Fabric API's own types are not Minecraft classes, so they keep the same names in every mapping namespace. That makes them a good first query against a real mods/ folder:

jdx implementors net.fabricmc.api.ModInitializer --jars 'mods/*.jar' --no-jdk
jdx implementors net.fabricmc.api.ClientModInitializer --jars 'mods/*.jar' --no-jdk

Each line is a class plus the jar it came from, so you get a map of "which mod runs code at startup, and in which class" without opening a single jar. Quote the glob so the shell does not expand it; --no-jdk keeps java.* out of the answer.

Narrow it down

  • --in '*sodium*' keeps only subtypes from jars whose name matches the glob; --exclude 'fabric-api*' drops the noise.
  • --direct shows only direct subtypes; --depth N caps transitive levels.
  • --limit controls how many rows you see (default 50), with a footer telling you how many were cut.

The other direction: what does this class extend?

jdx hierarchy walks both ways: supertypes up (full chain, interfaces included) and subtypes down. Point it at a mod's block or entity class and you see exactly which vanilla or library types it builds on, and who else extends it:

jdx hierarchy '<the mod class>' --jars "$MAPPED_JAR" --jars 'mods/*.jar' --no-jdk

If you paste a short name that matches more than one class, jdx does not guess: it exits 2 and lists every candidate as a paste-ready ref. Add --json if a script or an AI agent is reading the output.

Honest caveats

  • jdx does not remap. It answers in the names stored in the file. Mods in a production mods/ folder are usually compiled against intermediary names, so querying a Minecraft type there means using that same namespace. For Yarn or Mojmap names, pass the jar Fabric Loom or NeoForge ModDevGradle already produced with --jars.
  • Lambdas are not classes. A callback written as a lambda or method reference does not produce an implementing class in the jar, so it will not show up as an implementor.
  • Mixing namespaces gives nonsense. Comparing or joining an intermediary jar with a Yarn jar will not line up. The same rule applies to jdx diff: it only means something within one mapping namespace.

Try it

curl -fsSL https://raw.githubusercontent.com/MohammadMD1383/jdx/main/install-release.sh | bash

The same commands are available as MCP tools (jdx mcp), so an AI coding agent can ask "who implements this?" across your mods folder too.

來源:DEV Community · dev.to