Mixin error: Cannot resolve method in target class #1782
-
Hey. I am trying to make a callback for the PlayerEntity class's kill() function. Here is my code: import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.text.LiteralText;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(PlayerEntity.class)
public abstract class PlayerEntityMixin extends LivingEntity
{
protected PlayerEntityMixin(EntityType<? extends LivingEntity> entityType, World world)
{
super(entityType, world);
}
@Inject(at = @At("RETURN"), method = "Lnet/minecraft/entity/LivingEntity;kill()V")
public void kill(CallbackInfo ci)
{
MinecraftClient.getInstance().player.sendMessage(new LiteralText("kill() called."), false);
}
} And here is the error that I get: On running Minecraft Client: OutputException in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at net.fabricmc.loader.game.MinecraftGameProvider.launch(MinecraftGameProvider.java:236) at net.fabricmc.loader.launch.knot.Knot.launch(Knot.java:153) at net.fabricmc.loader.launch.knot.KnotClient.main(KnotClient.java:28) at net.fabricmc.devlaunchinjector.Main.main(Main.java:86) Caused by: java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) at net.fabricmc.loader.game.MinecraftGameProvider.launch(MinecraftGameProvider.java:234) ... 3 more Caused by: org.spongepowered.asm.mixin.transformer.throwables.MixinTransformerError: An unexpected critical error was encountered at org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:363) at org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClass(MixinTransformer.java:208) at org.spongepowered.asm.mixin.transformer.MixinTransformer.transformClassBytes(MixinTransformer.java:178) at org.spongepowered.asm.mixin.transformer.FabricMixinTransformerProxy.transformClassBytes(FabricMixinTransformerProxy.java:23) at net.fabricmc.loader.launch.knot.KnotClassDelegate.getPostMixinClassByteArray(KnotClassDelegate.java:162) at net.fabricmc.loader.launch.knot.KnotClassLoader.loadClass(KnotClassLoader.java:154) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519) at net.minecraft.client.main.Main.main(Main.java:129) ... 8 more Caused by: org.spongepowered.asm.mixin.throwables.MixinApplyError: Mixin [fabrictesting.mixins.json:PlayerEntityMixin] from phase [DEFAULT] in config [fabrictesting.mixins.json] FAILED during APPLY at org.spongepowered.asm.mixin.transformer.MixinProcessor.handleMixinError(MixinProcessor.java:642) at org.spongepowered.asm.mixin.transformer.MixinProcessor.handleMixinApplyError(MixinProcessor.java:594) at org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:356) ... 15 more Caused by: org.spongepowered.asm.mixin.injection.throwables.InvalidInjectionException: @Inject annotation on kill specifies a target class 'net/minecraft/entity/LivingEntity', which is not supported [PREINJECT Applicator Phase -> fabrictesting.mixins.json:PlayerEntityMixin -> Prepare Injections -> -> handler$zhm000$kill(Lorg/spongepowered/asm/mixin/injection/callback/CallbackInfo;)V -> Parse] at org.spongepowered.asm.mixin.injection.struct.InjectionInfo.parseTargets(InjectionInfo.java:309) at org.spongepowered.asm.mixin.injection.struct.InjectionInfo.readAnnotation(InjectionInfo.java:288) at org.spongepowered.asm.mixin.injection.struct.InjectionInfo.(InjectionInfo.java:275) at org.spongepowered.asm.mixin.injection.struct.InjectionInfo.(InjectionInfo.java:267) at org.spongepowered.asm.mixin.injection.struct.CallbackInjectionInfo.(CallbackInjectionInfo.java:46) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:78) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480) at org.spongepowered.asm.mixin.injection.struct.InjectionInfo$InjectorEntry.create(InjectionInfo.java:140) at org.spongepowered.asm.mixin.injection.struct.InjectionInfo.parse(InjectionInfo.java:624) at org.spongepowered.asm.mixin.transformer.MixinTargetContext.prepareInjections(MixinTargetContext.java:1247) at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.prepareInjections(MixinApplicatorStandard.java:1033) at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.applyMixin(MixinApplicatorStandard.java:388) at org.spongepowered.asm.mixin.transformer.MixinApplicatorStandard.apply(MixinApplicatorStandard.java:320) at org.spongepowered.asm.mixin.transformer.TargetClassContext.applyMixins(TargetClassContext.java:345) at org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:569) at org.spongepowered.asm.mixin.transformer.MixinProcessor.applyMixins(MixinProcessor.java:351) ... 15 more |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 4 replies
-
The kill() method is in the LivingEntity class so you need: If you just want it for player entities, you can override the method using normal java rules instead of an injection
But this might conflict with other mods if they do the same thing. Also, the way you have written it doesn't work properly in general. |
Beta Was this translation helpful? Give feedback.
-
That's fine. Purists would say |
Beta Was this translation helpful? Give feedback.
-
For clarification, should I put this mixin in |
Beta Was this translation helpful? Give feedback.
-
As a rule of thumb, you should put it in "mixins" unless you know it only works on either the client (e.g. gui related) or the server. |
Beta Was this translation helpful? Give feedback.
-
By server, I mean specific to dedicated server mode |
Beta Was this translation helpful? Give feedback.
-
There are very few examples where dedicated server mode specific code is necessary. |
Beta Was this translation helpful? Give feedback.
The kill() method is in the LivingEntity class so you need:
@Mixin(LivingEntity.class)
If you just want it for player entities, you can override the method using normal java rules instead of an injection
But this might conflict with other mods if they do the same thing.
Also, the way you have written it doesn't work properly in general.
The kill() command runs on the server where MinecraftClient won'…