SpongePowered / Mixin

Mixin is a trait/mixin and bytecode weaving framework for Java using ASM
MIT License
1.37k stars 185 forks source link

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

Closed heckerpowered closed 1 month ago

heckerpowered commented 1 month ago
@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 commented 1 month ago
  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 commented 1 month ago
  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