package com.acethewildfire.acesbs.mixin;

import com.acethewildfire.acesbs.item.custom.SovsPlateCarrierArmorItem;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin {

    @ModifyVariable(
            method = "damage",
            at = @At("HEAD"),
            argsOnly = true
    )
    private float modifyDamage(float amount) {

        LivingEntity entity = (LivingEntity)(Object)this;

        if (entity instanceof PlayerEntity player) {

            ItemStack chest = player.getEquippedStack(EquipmentSlot.CHEST);

            if (chest.getItem() instanceof SovsPlateCarrierArmorItem) {

                float multiplier =
                        SovsPlateCarrierArmorItem.getDamageMultiplier(chest);

                amount *= multiplier;
            }
        }

        return amount;
    }
}
