Search in sources :

Example 1 with ItemEnchantedBook

use of net.minecraft.item.ItemEnchantedBook in project NetherEx by LogicTechCorp.

the class Trade method getRandomTrade.

public MerchantRecipe getRandomTrade(Random rand) {
    ItemStack outputStack = getItemToSell().copy();
    ItemStack inputA = getItemToBuy().copy();
    ItemStack inputB = getSecondItemToBuy().copy();
    outputStack.setCount(rand.nextInt((outputAmount.getMax() - outputAmount.getMin()) + 1) + outputAmount.getMin());
    inputA.setCount(rand.nextInt((inputAAmount.getMax() - inputAAmount.getMin()) + 1) + inputAAmount.getMin());
    inputB.setCount(rand.nextInt((inputBAmount.getMax() - inputBAmount.getMin()) + 1) + inputBAmount.getMin());
    if (outputEnchantments.size() > 0) {
        for (TradeOffer.Enchantment outputEnchantment : outputEnchantments) {
            Enchantment enchantment = Enchantment.getEnchantmentByLocation(outputEnchantment.getName());
            TradeOffer.Amount enchantmentAmount = outputEnchantment.getAmount();
            if (enchantment != null) {
                if (outputStack.getItem() instanceof ItemEnchantedBook) {
                    ((ItemEnchantedBook) outputStack.getItem()).addEnchantment(outputStack, new EnchantmentData(enchantment, rand.nextInt((enchantmentAmount.getMax() - enchantmentAmount.getMin()) + 1) + enchantmentAmount.getMin()));
                } else {
                    outputStack.addEnchantment(enchantment, rand.nextInt((enchantmentAmount.getMax() - enchantmentAmount.getMin()) + 1) + enchantmentAmount.getMin());
                }
            }
        }
    }
    return new MerchantRecipe(inputA, inputB, outputStack, 0, rand.nextInt((offerAmount.getMax() - offerAmount.getMin()) + 1) + offerAmount.getMin());
}
Also used : MerchantRecipe(net.minecraft.village.MerchantRecipe) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment) ItemEnchantedBook(net.minecraft.item.ItemEnchantedBook) EnchantmentData(net.minecraft.enchantment.EnchantmentData)

Example 2 with ItemEnchantedBook

use of net.minecraft.item.ItemEnchantedBook in project BetterStorage by copygirl.

the class CardboardEnchantmentRecipe method makeEnchantedBook.

private ItemStack makeEnchantedBook(Enchantment ench, int level) {
    ItemStack book = new ItemStack(Items.enchanted_book);
    ((ItemEnchantedBook) book.getItem()).addEnchantment(book, new EnchantmentData(ench, level));
    return book;
}
Also used : ItemStack(net.minecraft.item.ItemStack) RecipeInputItemStack(net.mcft.copy.betterstorage.api.crafting.RecipeInputItemStack) ItemEnchantedBook(net.minecraft.item.ItemEnchantedBook) EnchantmentData(net.minecraft.enchantment.EnchantmentData)

Example 3 with ItemEnchantedBook

use of net.minecraft.item.ItemEnchantedBook in project BetterStorage by copygirl.

the class RecipeInputEnchantedBook method matches.

@Override
public boolean matches(ItemStack stack) {
    if (validEnchantments == null) {
        validEnchantments = new HashSet<Enchantment>();
        ItemStack[] items = { new ItemStack(BetterStorageItems.cardboardHelmet), new ItemStack(BetterStorageItems.cardboardChestplate), new ItemStack(BetterStorageItems.cardboardLeggings), new ItemStack(BetterStorageItems.cardboardBoots), new ItemStack(BetterStorageItems.cardboardSword), new ItemStack(BetterStorageItems.cardboardPickaxe), new ItemStack(BetterStorageItems.cardboardShovel), new ItemStack(BetterStorageItems.cardboardAxe), new ItemStack(BetterStorageItems.cardboardHoe) };
        for (Enchantment ench : Enchantment.enchantmentsList) {
            if ((ench == null) || !ench.isAllowedOnBooks())
                continue;
            for (ItemStack item : items) if (item.getItem() != null && ench.canApply(item)) {
                validEnchantments.add(ench);
                break;
            }
        }
    }
    if (stack.getItem() instanceof ItemEnchantedBook) {
        Map<Integer, Integer> enchants = EnchantmentHelper.getEnchantments(stack);
        for (Enchantment ench : validEnchantments) if (enchants.containsKey(ench.effectId))
            return true;
    }
    return false;
}
Also used : Enchantment(net.minecraft.enchantment.Enchantment) ItemStack(net.minecraft.item.ItemStack) ItemEnchantedBook(net.minecraft.item.ItemEnchantedBook)

Aggregations

ItemEnchantedBook (net.minecraft.item.ItemEnchantedBook)3 ItemStack (net.minecraft.item.ItemStack)3 Enchantment (net.minecraft.enchantment.Enchantment)2 EnchantmentData (net.minecraft.enchantment.EnchantmentData)2 RecipeInputItemStack (net.mcft.copy.betterstorage.api.crafting.RecipeInputItemStack)1 MerchantRecipe (net.minecraft.village.MerchantRecipe)1