Search in sources :

Example 31 with Enchantment

use of net.minecraft.enchantment.Enchantment in project EnderIO by SleepyTrousers.

the class DarkSteelRecipeManager method getEnchantmentRepairCost.

private static int getEnchantmentRepairCost(@Nonnull ItemStack itemStack) {
    // derived from ContainerRepair
    int res = 0;
    Map<Enchantment, Integer> map1 = EnchantmentHelper.getEnchantments(itemStack);
    Iterator<Enchantment> iter = map1.keySet().iterator();
    while (iter.hasNext()) {
        Enchantment i1 = iter.next();
        Enchantment enchantment = i1;
        int level = map1.get(enchantment).intValue();
        if (enchantment.canApply(itemStack)) {
            if (level > enchantment.getMaxLevel()) {
                level = enchantment.getMaxLevel();
            }
            int costPerLevel = 0;
            switch(enchantment.getRarity()) {
                case VERY_RARE:
                    costPerLevel = 8;
                    break;
                case RARE:
                    costPerLevel = 4;
                case UNCOMMON:
                    costPerLevel = 2;
                    break;
                case COMMON:
                    costPerLevel = 1;
            }
            res += costPerLevel * level;
        }
    }
    return res;
}
Also used : Enchantment(net.minecraft.enchantment.Enchantment)

Example 32 with Enchantment

use of net.minecraft.enchantment.Enchantment in project EnderIO by SleepyTrousers.

the class DarkSteelUpgradeRecipeCategory method registerBookEnchantmentRecipes.

private static int registerBookEnchantmentRecipes(@Nonnull IModRegistry registry, @Nonnull NNList<ItemStack> ingredients) {
    int count = 0;
    Collection<Enchantment> enchantments = ForgeRegistries.ENCHANTMENTS.getValuesCollection();
    List<IRecipeWrapper> anvilRecipes = new ArrayList<>();
    IVanillaRecipeFactory factory = registry.getJeiHelpers().getVanillaRecipeFactory();
    for (ItemStack ingredient : ingredients) {
        if (ingredient.isItemEnchantable()) {
            for (Enchantment enchantment : enchantments) {
                if (enchantment.canApply(ingredient)) {
                    Item item = ingredient.getItem();
                    List<ItemStack> perLevelBooks = Lists.newArrayList();
                    List<ItemStack> perLevelOutputs = Lists.newArrayList();
                    for (int level = 1; level <= enchantment.getMaxLevel(); level++) {
                        Map<Enchantment, Integer> enchMap = Collections.singletonMap(enchantment, level);
                        ItemStack bookEnchant = new ItemStack(Items.ENCHANTED_BOOK);
                        EnchantmentHelper.setEnchantments(enchMap, bookEnchant);
                        if (item.isBookEnchantable(ingredient, bookEnchant)) {
                            perLevelBooks.add(bookEnchant);
                            ItemStack withEnchant = ingredient.copy();
                            EnchantmentHelper.setEnchantments(enchMap, withEnchant);
                            perLevelOutputs.add(withEnchant);
                        }
                    }
                    if (!perLevelBooks.isEmpty() && !perLevelOutputs.isEmpty()) {
                        anvilRecipes.add(factory.createAnvilRecipe(ingredient, perLevelBooks, perLevelOutputs));
                        count++;
                    }
                }
            }
        }
    }
    registry.addRecipes(anvilRecipes, VanillaRecipeCategoryUid.ANVIL);
    return count;
}
Also used : Item(net.minecraft.item.Item) IDarkSteelItem(crazypants.enderio.api.upgrades.IDarkSteelItem) ArrayList(java.util.ArrayList) IRecipeWrapper(mezz.jei.api.recipe.IRecipeWrapper) Enchantment(net.minecraft.enchantment.Enchantment) ItemStack(net.minecraft.item.ItemStack) IVanillaRecipeFactory(mezz.jei.api.recipe.IVanillaRecipeFactory)

Example 33 with Enchantment

use of net.minecraft.enchantment.Enchantment in project EnderIO by SleepyTrousers.

the class DarkSteelUpgradeSubtypeInterpreter method apply.

@Override
@Nonnull
public String apply(ItemStack itemStack) {
    if (itemStack == null) {
        throw new NullPointerException("You want me to return something Nonnull for a null ItemStack? F.U.");
    }
    String result = DarkSteelRecipeManager.getUpgradesAsString(itemStack);
    Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(itemStack);
    final List<Enchantment> keyList = new NNList<>(enchantments.keySet());
    keyList.sort(new Comparator<Enchantment>() {

        @Override
        public int compare(Enchantment o1, Enchantment o2) {
            return safeString(o1).compareTo(safeString(o2));
        }
    });
    for (Enchantment enchantment : keyList) {
        result += "/" + safeString(enchantment);
    }
    return "DS:" + result;
}
Also used : NNList(com.enderio.core.common.util.NNList) Enchantment(net.minecraft.enchantment.Enchantment) Nonnull(javax.annotation.Nonnull)

Example 34 with Enchantment

use of net.minecraft.enchantment.Enchantment in project EnderIO by SleepyTrousers.

the class TankRecipeCategory method register.

// -------------------------------------
public static void register(IModRegistry registry, IGuiHelper guiHelper) {
    registry.addRecipeCategories(new TankRecipeCategory(guiHelper));
    registry.addRecipeCategoryCraftingItem(new ItemStack(block_tank.getBlockNN(), 1, 0), TankRecipeCategory.UID);
    registry.addRecipeCategoryCraftingItem(new ItemStack(block_tank.getBlockNN(), 1, 1), TankRecipeCategory.UID);
    registry.addRecipeClickArea(GuiTank.class, 155, 42, 16, 16, TankRecipeCategory.UID);
    long start = System.nanoTime();
    Map<String, Fluid> fluids = FluidRegistry.getRegisteredFluids();
    List<ItemStack> validItems = registry.getIngredientRegistry().getIngredients(ItemStack.class);
    List<TankRecipeWrapper> result = new ArrayList<TankRecipeWrapper>();
    for (ItemStack stack : validItems) {
        ItemStack drainedStack = stack.copy();
        IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(drainedStack);
        if (fluidHandler != null) {
            FluidStack drain = fluidHandler.drain(16000, true);
            drainedStack = fluidHandler.getContainer();
            // Log.debug("Draining a " + stack + " gives " + fluidString(drain) + " and " + drainedStack);
            if (drain != null && drain.amount > 0) {
                // filled container
                result.add(new TankRecipeWrapper(null, drain, stack.copy(), drainedStack));
            } else {
                // empty container
                for (Fluid fluid : fluids.values()) {
                    ItemStack filledStack = stack.copy();
                    fluidHandler = FluidUtil.getFluidHandler(filledStack);
                    if (fluidHandler != null) {
                        int filled = fluidHandler.fill(new FluidStack(fluid, 16000), true);
                        filledStack = fluidHandler.getContainer();
                        if (filled > 0) {
                            // Log.debug("Filling a " + stack + " with " + fluidString(new FluidStack(fluid, filled)) + " gives " + filledStack);
                            result.add(new TankRecipeWrapper(new FluidStack(fluid, filled), null, stack.copy(), filledStack));
                        }
                    }
                }
            }
        }
    }
    // add mending recipes
    Map<Enchantment, Integer> enchMap = Collections.singletonMap(Enchantments.MENDING, 1);
    final int maxMendable = TileTank.xpToDurability(XpUtil.liquidToExperience(16000));
    for (ItemStack stack : validItems) {
        if (stack.isItemStackDamageable()) {
            ItemStack enchantedStack;
            if (EnchantmentHelper.getEnchantmentLevel(Enchantments.MENDING, stack) > 0) {
                enchantedStack = stack.copy();
            } else if (Enchantments.MENDING.canApply(stack)) {
                enchantedStack = stack.copy();
                EnchantmentHelper.setEnchantments(enchMap, enchantedStack);
            } else {
                continue;
            }
            ItemStack damagedStack = enchantedStack.copy();
            damagedStack.setItemDamage((damagedStack.getMaxDamage() * 3) / 4);
            int damageMendable = Math.min(maxMendable, damagedStack.getItemDamage());
            enchantedStack.setItemDamage(damagedStack.getItemDamage() - damageMendable);
            if (damagedStack.getItemDamage() != enchantedStack.getItemDamage()) {
                result.add(new TankRecipeWrapper(new FluidStack(Fluids.XP_JUICE.getFluid(), XpUtil.experienceToLiquid(TileTank.durabilityToXp(damageMendable))), null, damagedStack, enchantedStack));
            }
        }
    }
    long end = System.nanoTime();
    registry.addRecipes(result, UID);
    registry.getRecipeTransferRegistry().addRecipeTransferHandler(ContainerTank.class, TankRecipeCategory.UID, 0, 2, 3, 4 * 9);
    Log.info(String.format("TankRecipeCategory: Added %d tank recipes to JEI in %.3f seconds.", result.size(), (end - start) / 1000000000d));
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) ArrayList(java.util.ArrayList) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment)

Example 35 with Enchantment

use of net.minecraft.enchantment.Enchantment in project BloodMagic by WayofTime.

the class ItemSentientArmour method setContainedArmourStack.

public void setContainedArmourStack(ItemStack newArmour, ItemStack previousArmour) {
    if (newArmour == null || previousArmour == null) {
        return;
    }
    NBTTagCompound tag = new NBTTagCompound();
    previousArmour.writeToNBT(tag);
    NBTTagCompound omegaTag = newArmour.getTagCompound();
    if (omegaTag == null) {
        omegaTag = new NBTTagCompound();
        newArmour.setTagCompound(omegaTag);
    }
    omegaTag.setTag("armour", tag);
    Map<Enchantment, Integer> enchantmentMap = EnchantmentHelper.getEnchantments(previousArmour);
    EnchantmentHelper.setEnchantments(enchantmentMap, newArmour);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Enchantment(net.minecraft.enchantment.Enchantment)

Aggregations

Enchantment (net.minecraft.enchantment.Enchantment)55 ItemStack (net.minecraft.item.ItemStack)32 ArrayList (java.util.ArrayList)10 Map (java.util.Map)9 Item (net.minecraft.item.Item)9 EnchantmentData (net.minecraft.enchantment.EnchantmentData)8 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 NBTTagList (net.minecraft.nbt.NBTTagList)7 HashMap (java.util.HashMap)6 Iterator (java.util.Iterator)6 List (java.util.List)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 Block (net.minecraft.block.Block)3 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)3 EnchantmentHelper (net.minecraft.enchantment.EnchantmentHelper)3 Entity (net.minecraft.entity.Entity)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 ItemEnchantedBook (net.minecraft.item.ItemEnchantedBook)3 ImmutableList (com.google.common.collect.ImmutableList)2