Jump to content

How to get "this" as instance in mixin inject target?


Recommended Posts

I am trying to mixin to the Vex class to give itself an effect if the owning evoker has said effect. The only problem is I can't reference the "this" object from the Vex class and there is no entity getter method or variable to get the vex entity (just the owner).

package gg.hipposgrumm.intangibility.effects.intangibility.special_cases;

// Imports Ommitted

public class EvokerVexIntangibleLifelink {
    private Mob owner;

    @Inject(method = "Lnet/minecraft/world/entity/monster/Vex;tick()V", at = @At("HEAD"))
    private void intangibilitypotion_ifvexsummonerisintangiblebecomeintangible(CallbackInfo ci) {
        if (this.owner.hasEffect(Main.INTANGIBILITY.get())) {
            ((Vex)this).addEffect(new MobEffectInstance(Main.INTANGIBILITY.get(), this.owner.getEffect(Main.INTANGIBILITY.get()).getDuration()));

This is the method I am trying to inject into:

   public void tick() {
      this.noPhysics = true;
      this.noPhysics = false;
      if (this.hasLimitedLife && --this.limitedLifeTicks <= 0) {
         this.limitedLifeTicks = 20;
         this.hurt(DamageSource.STARVE, 1.0F);

Is there any easy way to do this?

I'm not good at modding, but at least I can read a crash report (well enough). That's something, right?

Link to comment
Share on other sites

first your mixin should extend/implement everything the target class is extending or implementing

second, always declare your mixins abstract so you don't accidentally instantiate them.

then just cast ((object) (target class) this).->... it should work as both mixin class and target class are objects

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.