#Assigning values to a float using Mixins

1 messages · Page 1 of 1 (latest)

lone urchin
#

I'm trying to use mixins to change the values of float amount by whatever I feel like (atm amount * 300) using @ModifyVariable. But whenever I use it, nothing seems to happen.

Mixin code:

@Mixin(FabricEntityTypeBuilder.Living.class)
public class KniveBonusMixin {

    @ModifyVariable(method = "applyDamage", at = @At("HEAD"), ordinal = 1,print = true)
    private float injected(float amount) {
        return amount * 300;
    }
}

applyDamage code

protected void applyDamage(DamageSource source, float amount) {
        //--- should be: amount = injected(amount)
        if (!this.isInvulnerableTo(source)) {
            amount = this.applyArmorToDamage(source, amount);
            amount = this.modifyAppliedDamage(source, amount);
            float var9 = Math.max(amount - this.getAbsorptionAmount(), 0.0F);
            this.setAbsorptionAmount(this.getAbsorptionAmount() - (amount - var9));
            float g = amount - var9;
            if (g > 0.0F && g < 3.4028235E37F && source.getAttacker() instanceof ServerPlayerEntity serverPlayerEntity) {
                serverPlayerEntity.increaseStat(Stats.DAMAGE_DEALT_ABSORBED, Math.round(g * 10.0F));
            }

            if (var9 != 0.0F) {
                this.getDamageTracker().onDamage(source, var9);
                this.setHealth(this.getHealth() - var9);
                this.setAbsorptionAmount(this.getAbsorptionAmount() - var9);
                this.emitGameEvent(GameEvent.ENTITY_DAMAGE);
            }
        }
    }
modern marsh
lone urchin
#

let me check that rq

#

😭

#

ong if thats it

#

nope

#

it still functions as before without the print=true

modern marsh
#

!!mixinexport

honest emberBOT
#
Exporting Mixin Classes

Annotate your Mixin class with @Debug(export = true), which will export the individual Mixin.

Example:

@Debug(export = true)
@Mixin(...)
public class MyMixin {
    // Mixin code here
}

You can export all Mixin classes by adding -Dmixin.debug.export=true to your VM options.

IntelliJ IDEA - Run/debug configurations - More options (See "VM options")
VSCode - Running and debugging Java - Configuration options (See "vmArgs")

Exported finalized classes will appear in run/.mixin.out.

lone urchin
#

lemme see what this does

#

ok idk why but .mixin.out is not appearing

@Debug(export = true)
@Mixin(FabricEntityTypeBuilder.Living.class)
public class KniveBonusMixin {

    @ModifyVariable(method = "applyDamage", at = @At("HEAD"), ordinal = 1)
    private float injected(float amount) {
        return amount * 300;
    }
}

#

hang on a sec

#

there's no way I made it FabricEntityTypeBuilder instead of LivingEntity right??

modern marsh
#

it would seem so?

lone urchin
#

right now its telling me:
Caused by: org.spongepowered.asm.mixin.injection.throwables.InjectionError: Critical injection failure: Variable modifier method injected(F)F in knively.mixins.json:ExampleMixin from mod knively Scanned 0 target(s). No refMap loaded.

#

so it probably was that I had the wrong class 😭

#

absolutely no clue what the problem is but that it's my modifyVariable's fault