Jump to content

Recommended Posts

Posted

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?

Posted

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

  • 2 years later...
Posted
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.

Guest
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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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