Heccology / Bountiful-Fares

Source Code for the Bountiful Fares Fabric Mod
Other
9 stars 4 forks source link

[Bug] RestorationEffect shares #29

Open Phoupraw opened 2 months ago

Phoupraw commented 2 months ago

All entities share one RestorationEffect instance so regenMax covers each other.

Here is the mixin I use to fix the bug.

AttachmentType<Float> INSTA_HEALTH = AttachmentRegistry.createPersistent(id, Codec.FLOAT);
@Mixin(RestorationEffect.class)
abstract class MRestorationEffect extends StatusEffect {
    protected MRestorationEffect(StatusEffectCategory category, int color) {
        super(category, color);
    }
    @Overwrite
    @Override
    public void applyUpdateEffect(LivingEntity entity, int amplifier) {
        super.applyUpdateEffect(entity, amplifier);
        float health = entity.getHealth();
        float maxHealth = entity.getMaxHealth();
        if (health < maxHealth && health < entity.getAttachedOrSet(INSTA_HEALTH, health)) {
            entity.heal(Math.min(maxHealth - health, 0.1f * (amplifier + 1)));
        }
    }
    @Overwrite
    @Override
    public void onRemoved(LivingEntity entity, AttributeContainer attributes, int amplifier) {
        super.onRemoved(entity, attributes, amplifier);
        entity.removeAttached(INSTA_HEALTH);
    }
    @Overwrite
    @Override
    public void onApplied(LivingEntity entity, AttributeContainer attributes, int amplifier) {
        super.onApplied(entity, attributes, amplifier);
        entity.setAttached(INSTA_HEALTH, entity.getHealth());
    }
}