用Mixin能否重写非public的类中方法?----------------------------------------
例子
复制代码'net.minecraft.screen.BrewingStandScreenHandler.PotionSlot' 在 'net.minecraft.screen.BrewingStandScreenHandler' 中不为 public。无法从外部软件包访问
----------------------------------------
我想重写matches方法,怎么做。
例子
- public class BrewingStandScreenHandler
- extends ScreenHandler {
- ...
- static class PotionSlot
- extends Slot {
- ...
- public static boolean matches(ItemStack stack) {
- Item item = stack.getItem();
- return item == Items.POTION || item == Items.SPLASH_POTION || item == Items.LINGERING_POTION || item == Items.GLASS_BOTTLE;
- }
- }
- }
----------------------------------------
我想重写matches方法,怎么做。
用 Mixin 注解的 targets 参数指定类的名称即可,即 @Mixin(targets = "net.minecraft.screen.BrewingStandScreenHandler$PotionSlot")
可以继承一下,再重写
可以,@Mixin注解有一个targets属性,比如@Mixin(targets="com.example.ExampleClass$1")