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

[Feature Request] Allow modifying arguments on @Inject methods #669

Closed
heckerpowered opened this issue Jun 8, 2024 · 2 comments
Closed

Comments

@heckerpowered
Copy link

@Mixin(LivingEntity.class)
abstract class LivingEntityMixin extends Entity {
    LivingEntityMixin(final EntityType<?> type, final World world) {
        super(type, world);
    }

    @Inject(method = "damage", at = @At("HEAD"))
    private void modifyDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
       // ...
    }
}

In the above code, I injected the beginning of the damage method, and I want to make it so that when a creature takes damage, it increases or decreases the amount of damage it takes based on certain conditions (which need to be determined using DamageSource). However, if I use @Inject, I cannot modify the parameters. If I use @ModifyVariable, I cannot get the other parameters.

@LlamaLad7
Copy link
Contributor

LlamaLad7 commented Jun 8, 2024

  1. You can modify params in Inject using https://github.com/LlamaLad7/MixinExtras/wiki/Local
  2. You can get all the params in a ModifyVariable by simply appending them to your handler's params as explained in the docs https://jenkins.liteloader.com/view/Other/job/Mixin/javadoc/org/spongepowered/asm/mixin/injection/ModifyVariable.html

@heckerpowered
Copy link
Author

  1. You can modify params in Inject using https://github.com/LlamaLad7/MixinExtras/wiki/Local
  2. You can get all the params in a ModifyVariable by simply appending them to your handler's params as explained in the docs https://jenkins.liteloader.com/view/Other/job/Mixin/javadoc/org/spongepowered/asm/mixin/injection/ModifyVariable.html

Thanks

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

2 participants