Search in sources :

Example 6 with EnchantmentData

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;
    }
}
Also used : EnchantmentData(net.minecraft.enchantment.EnchantmentData)

Example 7 with EnchantmentData

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;
}
Also used : ItemStack(net.minecraft.item.ItemStack) EnchantmentData(net.minecraft.enchantment.EnchantmentData) Artifact(ivorius.reccomplex.random.Artifact) Nonnull(javax.annotation.Nonnull)

Aggregations

EnchantmentData (net.minecraft.enchantment.EnchantmentData)7 ItemStack (net.minecraft.item.ItemStack)5 Enchantment (net.minecraft.enchantment.Enchantment)2 ItemEnchantedBook (net.minecraft.item.ItemEnchantedBook)2 Artifact (ivorius.reccomplex.random.Artifact)1 Entry (java.util.Map.Entry)1 Nonnull (javax.annotation.Nonnull)1 RecipeInputItemStack (net.mcft.copy.betterstorage.api.crafting.RecipeInputItemStack)1 MerchantRecipe (net.minecraft.village.MerchantRecipe)1