Posted February 2, 20232 yr 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 @Mixin(Vex.class) public class EvokerVexIntangibleLifelink { @Shadow @Nullable 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; super.tick(); this.noPhysics = false; this.setNoGravity(true); 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?
February 2, 20232 yr This is a question for the mixin discord; however, you should have read the docs first since it literally goes over scenarios like this.
February 2, 20232 yr 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
June 27Jun 27 On 2/2/2023 at 4:12 PM, Darkorg69 said: 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 For people seeing this in the future: First: I've never once done this. You're just bloating your mixin classes. Second: Good advice, even if not pertinent Third: Incorrect. You cast (TargetClass) (Object) this. Your example casts the wrong way around, ultimately casting to Object, which isn't very useful. I would also advise making this a private field at the top of the mixin called something like "self", so you can reference it without performing the cast every time. It's kind of a strange concept to get your head around, but remember that this code is literally being executed inside the target class as if it's native code (more or less), so at runtime, "this" will actually refer to the target object.
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.