// priority: 500
let totalWeight = 0;
for (let i = 0; i < lootList_1.length; i++) {
    totalWeight += lootList_1[i].weight;
}
let totalWeight_stage_2 = 0;
for (let i = 0; i < stage_2.length; i++) {
    totalWeight_stage_2 += stage_2[i].weight;
}
LootJS.modifiers(event => {
    event.addLootTypeModifier(LootType.CHEST)
        .apply(event => {
            // 生成一个 0 到总权重之间的随机数
            let randomValue = Math.random() * totalWeight;

            // 根据随机数选择物品
            let currentWeight = 0;
            for (let i = 0; i < lootList_1.length; i++) {
                currentWeight += lootList_1[i].weight;
                if (randomValue < currentWeight) {
                    event.addLoot(lootList_1[i].item);
                    break;
                }
            }
        });
    //远古树苗
    event.addLootTypeModifier(LootType.CHEST)
        .anyStructure(['minecraft:ancient_city'], false)
        .addLoot(LootEntry.of('quark:ancient_sapling').when((c) => c.randomChance(0.5)))
    //狂战士卷轴
    event.addLootTypeModifier(LootType.CHEST)
        .anyStructure(['cataclysm:frosted_prison'], false)
        .addLoot(LootEntry.of(
            Item.of('tetra:scroll_rolled', '{BlockEntityTag:{data:[{details:"relic",glyphs:[I;6,15,4,8],intricate:0b,key:"armor/chestplate/berserker_chestplate",material:0,ribbon:"ff66",schematics:["tetra:armor/chestplate/berserker_chestplate"]}]}}')
        ).when((c) => c.randomChance(0.3)))
});

//海底白澜水晶
LootJS.modifiers(event => {
    event.addLootTypeModifier(LootType.CHEST)
        .apply(event => {
            let player = event.player;
            let random = Math.random();
            if (!player) return
            if (!player.inWater || random < 0.5) return;
            event.addLoot('art_of_forging:vobrite_crystal');
        });
});


LootJS.modifiers(event => {
    event.addLootTypeModifier(LootType.CHEST)
        .apply(event => {
            let player = event.player;
            let random = Math.random();
            if (!player || random < 0.5) return;
            let dimension = player.level.getDimension();
            if (dimension !== "pasterdream:aaroncos_arena_world" &&
                dimension !== "pasterdream:dyedream_world" &&
                dimension !== "pasterdream:lamp_shadow_world" &&
                dimension !== "minecraft:the_nether"
            ) return;
            let randomValue = Math.random() * totalWeight_stage_2;

            // 根据随机数选择物品
            let currentWeight = 0;
            for (let i = 0; i < stage_2.length; i++) {
                currentWeight += stage_2[i].weight;
                if (randomValue < currentWeight) {
                    event.addLoot(stage_2[i].item);
                    break;
                }
            }
        });
});


let totalWeight_stage_3 = 0;
for (let i = 0; i < stage_3.length; i++) {
    totalWeight_stage_3 += stage_3[i].weight;
}

LootJS.modifiers(event => {
    event.addLootTypeModifier(LootType.CHEST)
        .apply(event => {
            let player = event.player;
            let random = Math.random();
            if (!player || random < 0.2) return;
            let dimension = player.level.getDimension();
            if (dimension !== "jerotesvillage:second_round_world" &&
                dimension !== "minecraft:the_end"
            ) return;
            let randomValue = Math.random() * totalWeight_stage_3;

            // 根据随机数选择物品
            let currentWeight = 0;
            for (let i = 0; i < stage_3.length; i++) {
                currentWeight += stage_3[i].weight;
                if (randomValue < currentWeight) {
                    event.addLoot(stage_3[i].item);
                    break;
                }
            }
        });
});


