zh_cn:tutorial:mixin_examples
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
zh_cn:tutorial:mixin_examples [2023/12/18 02:10] – [使用偏移注入到一个方法调用之前] solidblock | zh_cn:tutorial:mixin_examples [2023/12/18 02:19] (current) – [捕获局部变量] solidblock | ||
---|---|---|---|
Line 244: | Line 244: | ||
===== 捕获局部变量 ===== | ===== 捕获局部变量 ===== | ||
+ | ==== 不用 MixinExtras 捕获局部变量 ==== | ||
Mixin: | Mixin: | ||
Line 266: | Line 267: | ||
</ | </ | ||
+ | |||
+ | ==== 使用 MixinExtras 捕获局部变量 ==== | ||
+ | :!: MixinExtras 需要 Fabric Loader 0.15 或者以上版本,否则你需要在 '' | ||
+ | |||
+ | :!: 如果有多个同一类型的局部变量,你需要指定 '' | ||
+ | |||
+ | Mixin: | ||
+ | <code java> | ||
+ | @Inject(method = " | ||
+ | private void injected(CallbackInfo ci, @Local TypeArg2 arg2) { | ||
+ | arg1.doSomething4(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | 结果: | ||
+ | <code diff> | ||
+ | public void foo() { | ||
+ | TypeArg1 arg1 = getArg1(); | ||
+ | arg1.doSomething1(); | ||
+ | arg1.doSomething2(); | ||
+ | TypeArg2 arg2 = getArg2(); | ||
+ | arg2.doSomething3(); | ||
+ | + | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== 捕获多个同一类型的局部变量中的一个 ==== | ||
+ | Mixin: | ||
+ | <code java> | ||
+ | @Inject(method = " | ||
+ | private void injected(CallbackInfo ci, @Local(ordinal = 2) TypeArg arg) { | ||
+ | arg1.doSomething4(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | 结果: | ||
+ | <code diff> | ||
+ | public void foo() { | ||
+ | TypeArg arg1 = getArg1(); | ||
+ | TypeArg arg2 = getArg2(); | ||
+ | TypeArg arg3 = getArg3(); | ||
+ | TypeArg arg4 = getArg4(); | ||
+ | doSomething(); | ||
+ | + | ||
+ | } | ||
+ | </ | ||
===== 修改返回值 ===== | ===== 修改返回值 ===== | ||
Mixin: | Mixin: |
zh_cn/tutorial/mixin_examples.1702865459.txt.gz · Last modified: 2023/12/18 02:10 by solidblock