Search in sources :

Example 16 with Enchantment

use of net.minecraft.enchantment.Enchantment in project pnc-repressurized by TeamPneumatic.

the class GuiSearcher method getSearchEntries.

/**
 * Lazy cache.
 * @return
 */
private Stream<SearchEntry> getSearchEntries() {
    if (cachedSearchEntries == null) {
        NonNullList<ItemStack> itemList = NonNullList.create();
        for (Item item : Item.REGISTRY) {
            if (item != null && item.getCreativeTab() != null) {
                item.getSubItems(item.getCreativeTab(), itemList);
            }
        }
        for (Enchantment enchantment : Enchantment.REGISTRY) {
            if (enchantment != null && enchantment.type != null) {
                getAllEnchantedBooks(enchantment, itemList);
            }
        }
        cachedSearchEntries = itemList.stream().map(SearchEntry::new).collect(Collectors.toList());
    }
    return cachedSearchEntries.stream();
}
Also used : Item(net.minecraft.item.Item) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment)

Example 17 with Enchantment

use of net.minecraft.enchantment.Enchantment in project GregTech by GregTechCE.

the class SolidMaterial method ctAddEnchantmentForTools.

@ZenMethod("addToolEnchantment")
@Method(modid = GTValues.MODID_CT)
public void ctAddEnchantmentForTools(IEnchantment enchantment) {
    Enchantment enchantmentType = (Enchantment) enchantment.getDefinition().getInternal();
    toolEnchantments.add(new EnchantmentData(enchantmentType, enchantment.getLevel()));
}
Also used : Enchantment(net.minecraft.enchantment.Enchantment) IEnchantment(crafttweaker.api.enchantments.IEnchantment) EnchantmentData(gregtech.api.enchants.EnchantmentData) ZenMethod(stanhebben.zenscript.annotations.ZenMethod) Method(net.minecraftforge.fml.common.Optional.Method) ZenMethod(stanhebben.zenscript.annotations.ZenMethod)

Example 18 with Enchantment

use of net.minecraft.enchantment.Enchantment in project SilentGems by SilentChaos512.

the class SilentGemsPlugin method registerItemSubtypes.

@Override
public void registerItemSubtypes(ISubtypeRegistry reg) {
    // Tools
    for (Item item : new Item[] { ModItems.sword, ModItems.katana, ModItems.scepter, ModItems.tomahawk, ModItems.pickaxe, ModItems.shovel, ModItems.axe, ModItems.paxel, ModItems.hoe, ModItems.sickle, ModItems.bow, ModItems.shield }) {
        reg.registerSubtypeInterpreter(item, new ISubtypeInterpreter() {

            @Override
            public String getSubtypeInfo(ItemStack stack) {
                ToolPart[] parts = ToolHelper.getConstructionParts(stack);
                if (parts.length == 0)
                    return "unknown";
                return parts[0].getKey();
            }
        });
    }
    // Enchantment tokens
    reg.registerSubtypeInterpreter(ModItems.enchantmentToken, new ISubtypeInterpreter() {

        @Override
        public String getSubtypeInfo(ItemStack stack) {
            Enchantment ench = ModItems.enchantmentToken.getSingleEnchantment(stack);
            if (ench == null)
                return "none";
            return ench.getName();
        }
    });
    // Chaos Runes
    reg.registerSubtypeInterpreter(ModItems.chaosRune, new ISubtypeInterpreter() {

        @Override
        public String getSubtypeInfo(ItemStack stack) {
            ChaosBuff buff = ModItems.chaosRune.getBuff(stack);
            if (buff == null)
                return "none";
            return buff.getKey();
        }
    });
}
Also used : Item(net.minecraft.item.Item) ISubtypeInterpreter(mezz.jei.api.ISubtypeRegistry.ISubtypeInterpreter) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment) ChaosBuff(net.silentchaos512.gems.lib.ChaosBuff)

Example 19 with Enchantment

use of net.minecraft.enchantment.Enchantment in project SilentGems by SilentChaos512.

the class ItemEnchantmentToken method addEnchantment.

public ItemStack addEnchantment(ItemStack stack, Enchantment enchantment, int level) {
    ItemStack result = StackHelper.safeCopy(stack);
    try {
        Map<Enchantment, Integer> map = getEnchantments(stack);
        map.put(enchantment, level);
        setEnchantments(result, map);
    } catch (NullPointerException ex) {
        String str = "Failed to construct an enchantment token! This will likely result in a broken recipe.\n";
        str += "The following is a list of details on the enchantment at fault. Please direct your anger at:\n";
        str += getEnchantmentDebugInfo(enchantment);
        SilentGems.logHelper.warning(str);
    }
    return result;
}
Also used : ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment)

Example 20 with Enchantment

use of net.minecraft.enchantment.Enchantment in project SilentGems by SilentChaos512.

the class ItemEnchantmentToken method clGetSubItems.

@Override
protected void clGetSubItems(Item item, CreativeTabs tab, List<ItemStack> list) {
    List<ItemStack> tokens = Lists.newArrayList();
    for (ResourceLocation key : Enchantment.REGISTRY.getKeys()) tokens.add(constructToken(Enchantment.REGISTRY.getObject(key)));
    // Sort by type, then enchantment name.
    tokens.sort(new Comparator<ItemStack>() {

        @Override
        public int compare(ItemStack o1, ItemStack o2) {
            int k = -getModelKey(o1).compareTo(getModelKey(o2));
            if (k == 0) {
                Enchantment ench1 = getSingleEnchantment(o1);
                Enchantment ench2 = getSingleEnchantment(o2);
                if (ench1 == null || ench2 == null)
                    return 0;
                return ench1.getTranslatedName(1).compareTo(ench2.getTranslatedName(1));
            }
            return k;
        }
    });
    // Empty token first.
    tokens.add(0, new ItemStack(this, 1, BLANK_META));
    list.addAll(tokens);
}
Also used : ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack) 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