use of net.minecraft.enchantment.EnchantmentData in project MineFactoryReloaded by powercrystals.
the class AutoEnchantmentHelper method buildEnchantmentList.
public static List<EnchantmentData> buildEnchantmentList(Random rand, ItemStack stack, int level) {
int itemEnchantability = stack.getItem().getItemEnchantability();
if (itemEnchantability <= 0) {
return null;
} else {
itemEnchantability /= 2;
itemEnchantability = 1 + rand.nextInt((itemEnchantability >> 1) + 1) + rand.nextInt((itemEnchantability >> 1) + 1);
int var5 = itemEnchantability + level;
float var6 = (rand.nextFloat() + rand.nextFloat() - 1.0F) * 0.15F;
int targetEnchantability = (int) (var5 * (1.0F + var6) + 0.5F);
if (targetEnchantability < 1) {
targetEnchantability = 1;
}
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);
}
}
}
}
return enchantmentList;
}
}
use of net.minecraft.enchantment.EnchantmentData in project RecurrentComplex by Ivorforce.
the class ArtifactItem method any.
@Nonnull
public static ItemStack any(Random random) {
Set<ItemStack> stacks = artifacts.keySet();
ItemStack[] stackArray = stacks.toArray(new ItemStack[stacks.size()]);
ItemStack origStack = stackArray[random.nextInt(stackArray.length)];
ItemStack artifactStack = origStack.copy();
int enchantLevel = random.nextInt(20);
List enchantments = EnchantmentHelper.buildEnchantmentList(random, artifactStack, enchantLevel, false);
if (enchantments.isEmpty()) {
enchantments = EnchantmentHelper.buildEnchantmentList(random, new ItemStack(Items.IRON_AXE), enchantLevel, false);
}
if (!enchantments.isEmpty()) {
for (Object enchantment : enchantments) {
EnchantmentData enchantmentdata = (EnchantmentData) enchantment;
artifactStack.addEnchantment(enchantmentdata.enchantment, enchantmentdata.enchantmentLevel);
}
}
List<String> possibleNames = artifacts.get(origStack);
Artifact artifact = Artifact.randomArtifact(random, possibleNames.get(random.nextInt(possibleNames.size())));
artifactStack.setStackDisplayName(artifact.getFullName());
return artifactStack;
}
Aggregations