List<EnchantmentData> enchantmentList = null;
Map<Integer, EnchantmentData> enchantmentMap = mapEnchantmentData(targetEnchantability, stack);
if(enchantmentMap != null && !enchantmentMap.isEmpty())
{
EnchantmentData enchData = (EnchantmentData)WeightedRandom.getRandomItem(rand, enchantmentMap.values());
if(enchData != null)
{
enchantmentList = new ArrayList<EnchantmentData>();
enchantmentList.add(enchData);
for(int i = targetEnchantability; rand.nextInt(50) <= i; i >>= 1)
{
for(Integer enchIndex : enchantmentMap.keySet())
{
boolean validWithPreviousEnchants = true;
for(EnchantmentData newEnchantment : enchantmentList)
{
if (newEnchantment.enchantmentobj.canApplyTogether(Enchantment.enchantmentsList[enchIndex]))
{
continue;
}
validWithPreviousEnchants = false;
}
if(!validWithPreviousEnchants)
{
enchantmentMap.remove(enchIndex);
}
break;
}
if(!enchantmentMap.isEmpty())
{
EnchantmentData randomEnchant = (EnchantmentData)WeightedRandom.getRandomItem(rand, enchantmentMap.values());
enchantmentList.add(randomEnchant);
}
}
}
}