Skip to content

Allow Soft Overwrite/Override of Super Methods #440

@gabizou

Description

@gabizou

I need to provide an explanation for this:

In the case of having classes Foo and Bar extends Foo, I have times where I want to soft override Foo#baz() when I already have MixinFoo and MixinBar.

In code:

public class Foo {
  public void baz() {
    // something
  }
}
public class Bar extends Foo {
  public void fooBar() {
    // something else
  }
}
@Mixin(Foo.class)
public class MixinFoo {
  @Shadow public void baz() {
    // shadowed! Doesn't actually do anything
  }
}
@Mixin(Bar.class)
public class MixinBar extends MixinFoo {
  @Override
  public void baz() {
    // actually do something different?
  }
}

I've come across wanting this functionality, since Generate > Overwrite methods... is available and Generate > Shadow members... is available. In this case, it'd be easier to do something akin to:
Generate > Override target superclass members (name is whatever) where it first generates the shadowed member method as required (for most cases, should just dummy implement with defaults), and then provide the *exact same method from an Overwrite but as a simple @Override in the subclass mixin.

Examples from Sponge include:
MixinEntityLivingBase

https://github.com/SpongePowered/SpongeCommon/blob/06f890888049ff5fa501c84780076a6e0c8346e9/src/main/java/org/spongepowered/common/mixin/core/entity/MixinEntityLivingBase.java#L205-L207
MixinEntityArmorStand

https://github.com/SpongePowered/SpongeCommon/blob/06f890888049ff5fa501c84780076a6e0c8346e9/src/main/java/org/spongepowered/common/mixin/core/entity/item/MixinEntityArmorStand.java#L216

Of course, this is more of a convenience as more and more of the plugin I get to use to do some fancy things with mixins.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions