// priority: 999
ItemEvents.rightClicked(event => {
    let player = event.entity;
    let mainitem = player.getMainHandItem();
    let level = player.level
    if (event.hand != 'MAIN_HAND') return;

    // 重载脚本
    if (mainitem == 'minecraft:bedrock') {
        player.tell('已重载');
        player.server.runCommand('kl reload all');
        return; // 避免执行后续逻辑
    }


});             
NativeEvents.onEvent(Java.loadClass('net.minecraftforge.event.entity.living.ShieldBlockEvent'), event => {
    //event.setBlockedDamage(event.getOriginalBlockedDamage())
    //event.setCanceled(true)
})

//测试
NativeEvents.onEvent($LivingHurtEvent, event => {
    if (event.entity && event.source.actual && event.source.actual.isPlayer()) {
        let player = event.source.actual
        let mainHandItem = player.getMainHandItem();
        let entity = event.entity
        let level = player.level
        let type = event.getSource().getType().toString()
    }
    if (event.entity && event.source.actual && event.entity.isPlayer()) {
        let player = event.entity

        let name = '伤害来源:无；伤害大小'
        if (event.source.actual) {
            name = '伤害来源:' + event.source.actual.type + '；伤害大小'
        }
        if (event.amount > 130) {
            player.tell('kubejs_warn_warn:' + event.amount)
        }
    }
});

PlayerEvents.tick(event => {
    let player = event.entity
    if (!player) return
    if (player.age % 20 * 60 * 10 != 0) return
})

PlayerEvents.loggedIn(event => {
})

BlockEvents.broken(event => {
    let player = event.getPlayer()
});

//生物生成事件
EntityEvents.spawned(event => {
    //获取生成的实体
    let entity = event.entity
    //entity.server.tell(entity)
    if (entity.type == "alexscaves:dinosaur_spirit") {
        //entity.server.tell(entity.nbt)
    }

})

TetraJSEvents.workbenchCraft(event => {
    let { player, level, currentSchematic, currentSlot, targetStack, upgradedStack, materials } = event
    //防止单人的时候client侧出问题
    if (level.clientSide) return
})


/**
 * 在两个坐标点之间生成粒子效果
 * @param {Level} level - 维度对象（如 server.overworld）
 * @param {number} startX - 起始点X坐标
 * @param {number} startY - 起始点Y坐标
 * @param {number} startZ - 起始点Z坐标
 * @param {number} endX - 结束点X坐标
 * @param {number} endY - 结束点Y坐标
 * @param {number} endZ - 结束点Z坐标
 * @param {string} particleType - 粒子类型标识符
 * @param {number} count - 要生成的粒子数量，默认为10
 */
function spawnParticlesAdvanced(level, startX, startY, startZ, endX, endY, endZ, particleType, count) {

    // 循环生成指定数量的粒子
    for (let i = 0; i <= count; i++) {
        let ratio = i / count;

        // 根据比例计算当前粒子的坐标
        let x = startX + (endX - startX) * ratio;
        let y = startY + (endY - startY) * ratio;
        let z = startZ + (endZ - startZ) * ratio;

        // 粒子位置随机偏移（范围：-0.2 到 0.2）
        let offsetRange = 0.4;
        x += (Math.random() - 0.5) * 2 * offsetRange;
        y += (Math.random() - 0.5) * 2 * offsetRange;
        z += (Math.random() - 0.5) * 2 * offsetRange;

        // 生成粒子
        level.spawnParticles(
            particleType,
            true,
            x, y, z,
            0.5, 0.5, 0.5, 0.1, 5
        );
    }
}


