// Native Minecraft 1.21.11
package com.xfestudio.mydimensionlord.platform;

import com.xfestudio.mydimensionlord.equipment.EquipmentRules;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

public final class EquipmentCombat {
    private EquipmentCombat() {}
    public static boolean cooling(Player player, ItemStack stack) { return player.getCooldowns().isOnCooldown(stack); }
    public static boolean hurt(Player player, LivingEntity target, float damage) { return target.hurtServer((ServerLevel) player.level(), player.damageSources().playerAttack(player), damage); }
    public static void spend(Player player, ItemStack stack, InteractionHand hand) {
        player.getCooldowns().addCooldown(stack, EquipmentRules.SLASH_COOLDOWN);
        stack.hurtAndBreak(EquipmentRules.SLASH_DURABILITY_COST, player, hand == InteractionHand.MAIN_HAND ? EquipmentSlot.MAINHAND : EquipmentSlot.OFFHAND);
    }
}
