xmsc
用Mixin能否重写非public的类中方法?----------------------------------------

例子
  1. public class BrewingStandScreenHandler
  2. extends ScreenHandler {
  3.     ...
  4.     static class PotionSlot
  5.     extends Slot {
  6.         ...
  7.         public static boolean matches(ItemStack stack) {
  8.             Item item = stack.getItem();
  9.             return item == Items.POTION || item == Items.SPLASH_POTION || item == Items.LINGERING_POTION || item == Items.GLASS_BOTTLE;
  10.         }
  11.     }
  12. }
复制代码
'net.minecraft.screen.BrewingStandScreenHandler.PotionSlot' 在 'net.minecraft.screen.BrewingStandScreenHandler' 中不为 public。无法从外部软件包访问

----------------------------------------

我想重写matches方法,怎么做。


youyihj
用 Mixin 注解的 targets 参数指定类的名称即可,即 @Mixin(targets = "net.minecraft.screen.BrewingStandScreenHandler$PotionSlot")

李虹鲛
可以继承一下,再重写

吕易天
可以,@Mixin注解有一个targets属性,比如@Mixin(targets="com.example.ExampleClass$1")