Search in sources :

Example 41 with Enchantment

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

the class ItemEnchantmentToken method setEnchantments.

public void setEnchantments(ItemStack token, Map<Enchantment, Integer> map) {
    if (StackHelper.isEmpty(token))
        return;
    if (!token.hasTagCompound())
        token.setTagCompound(new NBTTagCompound());
    if (token.getTagCompound().hasKey(NBT_ENCHANTMENTS))
        token.getTagCompound().removeTag(NBT_ENCHANTMENTS);
    NBTTagList tagList = new NBTTagList();
    for (Entry<Enchantment, Integer> entry : map.entrySet()) {
        String name = entry.getKey().getRegistryName().toString();
        int level = entry.getValue();
        NBTTagCompound compound = new NBTTagCompound();
        compound.setString("name", name);
        compound.setShort("lvl", (short) level);
        tagList.appendTag(compound);
    }
    token.getTagCompound().setTag(NBT_ENCHANTMENTS, tagList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Enchantment(net.minecraft.enchantment.Enchantment)

Example 42 with Enchantment

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

the class ItemEnchantmentToken method addModTokenRecipe.

public void addModTokenRecipe(String enchantmentName, EnumGem gem, Object other, int otherCount) {
    SilentGems.logHelper.info("    Attempting to add token recipe for " + enchantmentName + "...");
    Enchantment enchantment = Enchantment.REGISTRY.getObject(new ResourceLocation(enchantmentName));
    if (enchantment == null) {
        SilentGems.logHelper.info("    Failed to add! Enchantment is null?");
        return;
    }
    addTokenRecipe(enchantment, gem, other, otherCount);
}
Also used : ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) Enchantment(net.minecraft.enchantment.Enchantment)

Example 43 with Enchantment

use of net.minecraft.enchantment.Enchantment in project RFTools by McJty.

the class EnvironmentalSetup method createEnchantedItem.

public static ItemStack createEnchantedItem(Item item, Enchantment effectId, int amount) {
    ItemStack stack = new ItemStack(item);
    Map<Enchantment, Integer> enchant = new HashMap<>();
    enchant.put(effectId, amount);
    EnchantmentHelper.setEnchantments(enchant, stack);
    return stack;
}
Also used : HashMap(java.util.HashMap) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment)

Example 44 with Enchantment

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

the class IntegratorPressureChamber method handleDisenchanting.

private void handleDisenchanting(int x, int y, List<LocatedStack> locatedStacks) {
    List<ItemStack> input = new ArrayList<ItemStack>();
    List<ItemStack> output = new ArrayList<ItemStack>();
    ItemStack enchantedItem = new ItemStack(Items.DIAMOND_SWORD);
    EnchantmentHelper.addRandomEnchantment(new Random(), enchantedItem, 30, true);
    input.add(enchantedItem);
    output.add(new ItemStack(Items.DIAMOND_SWORD));
    Map<Enchantment, Integer> enchants = EnchantmentHelper.getEnchantments(enchantedItem);
    for (Map.Entry<Enchantment, Integer> enchant : enchants.entrySet()) {
        ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK);
        Map<Enchantment, Integer> newMap = new HashMap<>();
        newMap.put(enchant.getKey(), enchant.getValue());
        EnchantmentHelper.setEnchantments(newMap, enchantedBook);
        output.add(enchantedBook);
        input.add(new ItemStack(Items.BOOK));
    }
    for (int i = 0; i < input.size(); i++) {
        LocatedStack stack = new LocatedStack(input.get(i), (int) ((x + 36 + i % 3 * 34) * GuiWiki.TEXT_SCALE), (int) ((y + 102 - i / 3 * 34) * GuiWiki.TEXT_SCALE));
        locatedStacks.add(stack);
    }
    for (int i = 0; i < output.size(); i++) {
        LocatedStack stack = new LocatedStack(output.get(i), (int) ((x + 180 + i % 3 * 36) * GuiWiki.TEXT_SCALE), (int) ((y + 60 + i / 3 * 36) * GuiWiki.TEXT_SCALE));
        locatedStacks.add(stack);
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment)

Example 45 with Enchantment

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

the class PressureChamberVacuumEnchantHandler method craftRecipe.

@Override
public NonNullList<ItemStack> craftRecipe(ItemStackHandler inputStacks) {
    ItemStack enchantedStack = getDisenchantableItem(inputStacks);
    getBook(inputStacks).shrink(1);
    // take a random enchantment off the enchanted item...
    Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(enchantedStack);
    List<Enchantment> l = new ArrayList<>(enchantments.keySet());
    Enchantment strippedEnchantment = l.get(new Random().nextInt(l.size()));
    int level = enchantments.get(strippedEnchantment);
    enchantments.remove(strippedEnchantment);
    EnchantmentHelper.setEnchantments(enchantments, enchantedStack);
    // ...and create an enchanted book with it
    ItemStack enchantedBook = new ItemStack(Items.ENCHANTED_BOOK);
    EnchantmentHelper.setEnchantments(ImmutableMap.of(strippedEnchantment, level), enchantedBook);
    return NonNullList.from(ItemStack.EMPTY, enchantedBook);
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) 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