// 装备变动事件
let $LivingEquipmentChangeEvent = Java.loadClass('net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent');

ItemEvents.rightClicked(event => {
    let player = event.entity
    let level = player.level
    let mainitem = player.getMainHandItem()
    let offitem = player.getOffHandItem()
    let viewVector = player.getViewVector(1.0);
    let normalizedVector = normalizeVector(viewVector)
    //player.addMotion(normalizedVector.x * 3, normalizedVector.y,normalizedVector.z * 3)
})
/*
NativeEvents.onEvent($LivingEquipmentChangeEvent, event => {
    if (!event.entity || !event.entity.isPlayer()) return;
    let player = event.entity
    let slot = event.getSlot()
    
    let item = ''
    if (slot == 'MAINHAND'){
         item = player.getMainHandItem()
    }else if (slot == 'OFFHAND'){
         item = player.getOffHandItem()
    }
    if (item != ''){
        getCommonAttributes(player).forEach(attribute => {
             
        })
    }
});
// 加载需要的Java类
let $ForgeRegistries = Java.loadClass("net.minecraftforge.registries.ForgeRegistries");

function getCommonAttributes(player) {
    let mainitem = player.getMainHandItem();
    let offitem = player.getOffHandItem();

    // 获取主手和副手物品的属性修饰符映射
    let mainModifiers = mainitem.getItem().getAttributeModifiers('mainhand', mainitem);
    let offModifiers = offitem.getItem().getAttributeModifiers('offhand', offitem);

    // 提取主手和副手的属性ID集合
    let getAttributeIds = (modifiers) => {
        let attributeIterator = modifiers.keySet().iterator();
        let attributeIds = [];
        while (attributeIterator.hasNext()) {
            let attribute = attributeIterator.next();
            let attributeId = $ForgeRegistries.ATTRIBUTES.getKey(attribute);
            if (attributeId) {
                attributeIds.push(attributeId.toString());
            }
        }
        return attributeIds;
    };

    let mainAttributeIds = getAttributeIds(mainModifiers);
    let offAttributeIds = getAttributeIds(offModifiers);

    // 找出相同的属性ID
    mainAttributeIds.filter(id => offAttributeIds.includes(id)).forEach(attribute => {
        player.tell(offitem.item.getAttributes(attribute).Operation)
    })
    return mainAttributeIds.filter(id => offAttributeIds.includes(id))
}
ItemEvents.rightClicked(event => {
    let player = event.entity
    let level = player.level
    let mainitem = player.getMainHandItem()
    let offitem = player.getOffHandItem()

})
*/