public void Apply(ItemStack applyitem) { if (Enchantprobabilities.size() == 0) return; // no enchants to choose from. // otherwise, simplez. create an array of floats and a corresponding array of // EnchantmentAssignmentData's... // System.out.println("Applying enchantment. Choosing from " + Enchantprobabilities.size()); preCache(); // now, use the infamous Choose routine... Enchantment useenchant = null; EnchantmentAssignmentData chosen = null; chosen = RandomData.Choose(enchantdata, cacheprobabilities); if (chosen == null) return; // no enchant selected. useenchant = EnchantmentMapping.get(chosen.getName()); // System.out.println("chosen enchant:" + useenchant.getName()); if (useenchant == null) { // System.out.println("Null enchantment...."); return; } if (!applyitem.containsEnchantment(useenchant)) { applyitem.addUnsafeEnchantment(useenchant, chosen.getLevel()); } }
public void preCache() { /*if(cacheprobabilities ==null){ System.out.println("Precache enchantmentprobabilities->" + Enchantprobabilities.size());*/ cacheprobabilities = new float[Enchantprobabilities.size()]; enchantdata = new EnchantmentAssignmentData[Enchantprobabilities.size()]; int index = 0; for (EnchantmentAssignmentData ead : Enchantprobabilities) { cacheprobabilities[index] = ead.getWeight(); enchantdata[index] = ead; index++; } }