Minecraft mixin
Skill code-onigiri/mc-modding-skill/.agent/skills/minecraft-mixin
Minecraft開発用スキル
npx -y skills add code-onigiri/mc-modding-skill --skill minecraft-mixinAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 2 stars2 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Minecraft 1.20.1 Forge / 1.21.1 NeoForge ModdingにおけるMixinの実装支援。既存のMinecraft/Forge/NeoForge/他Modのクラスに対する コード挿入・置換・フィールドアクセス・メソッド呼び出しなど。Mixinのセットアップから @Inject/@Redirect/@Shadow/@Accessorなど各アノテーションの使い方、競合回避、トラブルシューティングまで。
The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.
SKILL.md
3.9 KB, as published. Nobody here has run it
概要
Mixin は既存クラスの動作を変更する強力なツール。Forge/NeoForge に同梱済み(追加依存不要)。
✅ やるべきこと(優先順位順)
- @Inject を最優先 — 元のコードを破壊しない。他Modとの競合が最も少ない。
- @Unique を徹底 — Mixin内で追加するフィールド・メソッドには必ず付与。名前衝突を防ぐ。
- Interface Mixin(@Accessor/@Invoker)は安全 — 元のコードを書き換えない。競合リスク極低。
- Constructorへの@InjectはTAIL/RETURNのみ可能 — HEADや他位置への注入は不可。
- Compatibility Level: Forge 1.20.1 →
JAVA_17, NeoForge 1.21.1 →JAVA_21 - 他Modのクラスに注入する際は@Pseudoを必ず付与 — クラスが存在しない場合のクラッシュを防ぐ。
- 開発時は
locals = LocalCapture.CAPTURE_FAILHARD— 即座にエラー検知。リリース時はCAPTURE_FAILSOFTに切替。
❌ やってはいけないこと
- @Overwrite / @Redirect は極力避ける — 同じ箇所を他Modも書き換えると互換性破壊。どうしても必要な場合のみ
priorityで順序制御。 - @Shadow したフィールドに
finalを付けない —@Final @Mutable @Shadowを使うこと。Mixinコンパイル時にエラーになる。 method = "target()V"のシグネチャを間違えない — 戻り値・引数・修飾子は必ず正確に記述。間違えるとMixin apply failedで起動時クラッシュ。- CallbackInfoReturnableのジェネリクス型を間違えない — 戻り値の型と一致しないと注入失敗。
- Mixin Configの
packageと実際のパッケージを一致させる — 不一致はClassNotFoundExceptionの原因。 mods.toml/neoforge.mods.tomlの[[mixins]]を忘れない — 忘れるとMixinが一切適用されない。build.gradleの jar manifest にMixinConfigsを含める — ないと配布用jarでMixinが読み込まれない。- run引数に
-mixin.config=mixins.<modid>.jsonを含める — ないと開発環境でもMixinが読み込まれない。
開発ワークフロー
- 1.
build.gradleにMixin設定追加(jar manifestのMixinConfigs、run引数の-mixin.config=mixins.<modid>.json) - 2.
mods.toml/neoforge.mods.tomlに[[mixins]]追加 - 3.
src/main/resources/mixins.<modid>.json作成(Mixin Config) - 4. Mixinクラスを
src/main/java/.../mixin/に作成 - 5. ターゲットメソッドのシグネチャを確認(obf/name/mapping)
- 6.
runClientで動作確認。Mixin apply failedが出たらシグネチャ見直し
詳細リファレンス
| トピック | ファイル | 読むタイミング |
|---|---|---|
| セットアップ(build.gradle, mods.toml, mixin config) | references/SETUP.md | 最初に1回 |
| Injector一覧(@Inject, @Redirect, @Overwrite, @ModifyArg/Args/Variable...) | references/INJECTORS.md | コード挿入・変更が必要な際 |
| Helper/Utility(@Shadow, @Accessor, @Invoker, @Unique, @Slice, @Pseudo, @Dynamic) | references/HELPERS.md | フィールドアクセス・命名・競合回避 |