Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot inject into a constructor that doesn't call super() but calls this() #23

Open
skyrising opened this issue Jul 13, 2019 · 0 comments

Comments

@skyrising
Copy link

For example trying

@Mixin(TntEntity.class)
public abstract class TntEntityMixin extends Entity {
    public TntEntityMixin(EntityType<?> type, World world) {
        super(type, world);
    }

    @Redirect(
            method = "<init>(Lnet/minecraft/world/World;DDDLnet/minecraft/entity/LivingEntity;)V",
            at = @At(value = "INVOKE", target = "Ljava/util/Random;nextDouble()D")
    )
    private double myNextDouble(Random random) {
        return random.nextDouble();
    }
}

crashes with

java.lang.NullPointerException
	at org.spongepowered.asm.lib.tree.InsnList.indexOf(InsnList.java:133)
	at org.spongepowered.asm.mixin.injection.struct.Target.indexOf(Target.java:450)
	at org.spongepowered.asm.mixin.injection.invoke.InvokeInjector.checkTargetForNode(InvokeInjector.java:108)
	at org.spongepowered.asm.mixin.injection.invoke.RedirectInjector.inject(RedirectInjector.java:252)
	at org.spongepowered.asm.mixin.injection.code.Injector.inject(Injector.java:200)
	at org.spongepowered.asm.mixin.injection.struct.InjectionInfo.inject(InjectionInfo.java:267)

Because Bytecode.findSuperInit will return null because there is no call to Entity.<init>(...), but there is a call to TntEntity.<init>(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant