#Can't get Status effect of attacker in Mixin (1.21)

31 messages · Page 1 of 1 (latest)

worn igloo
#

Good day. MC 1.21
I'm trying to make custom effect to increase incoming damage to Warden if player(or attacker) has effect, but when I try to get effect using Java StatusEffectInstance effect = attacker.getStatusEffect(WardenToolsEffects.WARDEN_SLAYER_EFFECT); it's null
Mixin code:

 @Inject(method = "damage", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/entity/mob/HostileEntity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z"))
    private void applyExtraDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir,@Local(ordinal = 0) boolean bl) {
        if (bl) {
            System.out.println("1");
            if (source.getAttacker() instanceof LivingEntity attacker) {
                System.out.println("2 " + attacker);
                StatusEffectInstance effect = attacker.getStatusEffect(WardenToolsEffects.WARDEN_SLAYER_EFFECT);
                System.out.println(effect);
                if (effect != null) {
                    System.out.println("3");
                    this.timeUntilRegen = 0;
                    super.damage(source, amount * 2);
                }
            }
        }
    }

(System outs are for debugging)

gritty dome
#

i'll test this rl quick

worn igloo
#

When i tried, effect returned null

#

attacker.getActiveStatusEffecs() shows that effect exists ";3

gritty dome
#

I left a bit our since I don't have the full project file and this works:

    @Inject(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/mob/HostileEntity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z"))
    private void applyExtraDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
        if (source.getAttacker() instanceof LivingEntity attacker) {
            System.out.println("2 " + attacker);
            StatusEffectInstance effect = attacker.getStatusEffect(StatusEffects.STRENGTH);
            System.out.println(effect);
            if (effect != null) {

            }
        }
    }

with the console output of:

[13:03:07] [Render thread/INFO] (Minecraft) [STDOUT]: 2 ClientPlayerEntity['Player377'/19, l='ClientLevel', x=110.50, y=119.68, z=73.64]
[13:03:07] [Server thread/INFO] (Minecraft) [STDOUT]: 2 ServerPlayerEntity['Player377'/19, l='ServerLevel[New World]', x=110.50, y=119.68, z=73.64]
[13:03:07] [Render thread/INFO] (Minecraft) [STDOUT]: effect.minecraft.strength x 2, Duration: 1424
[13:03:07] [Server thread/INFO] (Minecraft) [STDOUT]: effect.minecraft.strength x 2, Duration: 1423
worn igloo
#

Effect

public class WardenToolsEffects {

    public static RegistryEntry<StatusEffect> WARDEN_SLAYER_EFFECT;

    public static void RegEffect(){
        WARDEN_SLAYER_EFFECT = RegistryEntry.of(Registry.register(Registries.STATUS_EFFECT,Identifier.of(WardenTools.MOD_ID, "warden_slayer"),new WardenSlayerEffect(StatusEffectCategory.BENEFICIAL,0x29DFEB)));

        WardenTools.LOGGER.info("Register "+ WardenTools.MOD_ID+" effect...");
    }

}
gritty dome
#

idk if it's an issue but the code I use, which I took out of mojangs source code, is different from yours:

    public static final RegistryEntry<StatusEffect> WARDEN_SLAYER_EFFECT= registerStatuesEffect("warden_slayer", new WardenSlayerEffect(StatusEffectCategory.BENEFICIAL,0x29DFEB));

    private static RegistryEntry<StatusEffect> registerStatuesEffect(String name, StatusEffect statusEffect) {
        return Registry.registerReference(Registries.STATUS_EFFECT,
                Identifier.of(WardenTools.MOD_ID, name),
                statusEffect
        );
    }

the difference is the use of Registry.registerReference() instead of RegistryEntry.of(Registry.register())

#

have you tried your code with a different potion effect to see where the issue lies?

worn igloo
#

I tried with Jump Boost and think issue with mod effect ";3

worn igloo
#

Okay

#

meh

#

it falls with error

gritty dome
#

hm?

worn igloo
#
[14:15:58] [Render thread/ERROR] (Minecraft) Unreported exception thrown!
 java.lang.ExceptionInInitializerError: null
#
[14:15:58] [Server thread/ERROR] (Minecraft) Encountered an unexpected exception
 java.lang.NoClassDefFoundError: Could not initialize class net.trique.wardentools.effect.WardenToolsEffects

maybe i missed smth

gritty dome
#

you still need an init function in the class btw. So a function which gets called on init.

#

mb

worn igloo
#

it works

#

Thanks!

gritty dome
#

nice

#

you're welcome

worn igloo
#

My issue were strange ";3

#

Have a good day!

#

btw

#

do you know how to override amount or when you use super.damage() you need to calculate in other ways?

gritty dome
#

uf idk. What do you mean with amount? The damage amount? So you want to change how much damage the entity takes?

worn igloo
gritty dome
#

I mean you could mixin before the ´boolean bl = super.damage(source, amount);´ and just go ´amout += 10´ or whatever.

worn igloo
#

okay. thanks!