/*
 * Copyright (c) 2026 盐灯水母
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 */

package com.remains_cave.item.custom;

import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public class DoomStaffItem extends SwordItem {

    public DoomStaffItem(Tier tier, Properties properties) {
        super(tier, properties);
    }

    /**
     * 公开方法：施加范围再生效果
     * 供事件监听器调用
     */
    public void applyAura(Player source) {
        Level level = source.level();
        double radiusXZ = 12.0;
        double radiusY = 5.0;

        AABB area = new AABB(
                source.getX() - radiusXZ,
                source.getY() - radiusY,
                source.getZ() - radiusXZ,
                source.getX() + radiusXZ,
                source.getY() + radiusY,
                source.getZ() + radiusXZ
        );

        List<Player> nearbyPlayers = level.getEntitiesOfClass(Player.class, area, Player::isAlive);
        MobEffectInstance effect = new MobEffectInstance(MobEffects.REGENERATION, 120, 0, false, true);
        for (Player player : nearbyPlayers) {
            player.addEffect(effect);
        }
    }

    // inventoryTick 方法不再需要，可以完全移除（或留空）
    @Override
    public void inventoryTick(@NotNull ItemStack stack, @NotNull Level level, net.minecraft.world.entity.@NotNull Entity entity,
                              int slotId, boolean isSelected) {
        // 无需任何逻辑
    }
}