當前位置: 首頁>>代碼示例>>Java>>正文


Java Enchantment.getEnchantmentByID方法代碼示例

本文整理匯總了Java中net.minecraft.enchantment.Enchantment.getEnchantmentByID方法的典型用法代碼示例。如果您正苦於以下問題:Java Enchantment.getEnchantmentByID方法的具體用法?Java Enchantment.getEnchantmentByID怎麽用?Java Enchantment.getEnchantmentByID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在net.minecraft.enchantment.Enchantment的用法示例。


在下文中一共展示了Enchantment.getEnchantmentByID方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getBookLootingLevel

import net.minecraft.enchantment.Enchantment; //導入方法依賴的package包/類
static int getBookLootingLevel(ItemStack stack) {
   NBTTagList nbttaglist = Items.ENCHANTED_BOOK.getEnchantments(stack);

   if (nbttaglist != null) {
      for (int i = 0; i < nbttaglist.tagCount(); ++i)
      {
         Enchantment enchantment = Enchantment.getEnchantmentByID(
               nbttaglist.getCompoundTagAt(i).getShort("id"));
         int j = nbttaglist.getCompoundTagAt(i).getShort("lvl");
         if (Enchantments.LOOTING == enchantment)
            return j;
      }
   }

   return 0;
}
 
開發者ID:arucil,項目名稱:mc-Slingshot,代碼行數:17,代碼來源:RecipeLooting.java

示例2: addInformation

import net.minecraft.enchantment.Enchantment; //導入方法依賴的package包/類
/**
 * allows items to add custom lines of information to the mouseover description
 */
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
{
    super.addInformation(stack, playerIn, tooltip, advanced);
    NBTTagList nbttaglist = this.getEnchantments(stack);

    if (nbttaglist != null)
    {
        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            int j = nbttaglist.getCompoundTagAt(i).getShort("id");
            int k = nbttaglist.getCompoundTagAt(i).getShort("lvl");

            if (Enchantment.getEnchantmentByID(j) != null)
            {
                tooltip.add(Enchantment.getEnchantmentByID(j).getTranslatedName(k));
            }
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:23,代碼來源:ItemEnchantedBook.java

示例3: addInformation

import net.minecraft.enchantment.Enchantment; //導入方法依賴的package包/類
/**
 * allows items to add custom lines of information to the mouseover description
 */
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced)
{
    super.addInformation(stack, playerIn, tooltip, advanced);
    NBTTagList nbttaglist = this.getEnchantments(stack);

    if (nbttaglist != null)
    {
        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            int j = nbttaglist.getCompoundTagAt(i).getShort("id");
            int k = nbttaglist.getCompoundTagAt(i).getShort("lvl");

            if (Enchantment.getEnchantmentByID(j) != null)
            {
                tooltip.add(Enchantment.getEnchantmentByID(j).getTranslatedName(k));
            }
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:24,代碼來源:ItemEnchantedBook.java

示例4: addEnchantment

import net.minecraft.enchantment.Enchantment; //導入方法依賴的package包/類
/**
 * Adds an stored enchantment to an enchanted book ItemStack
 */
public void addEnchantment(ItemStack stack, EnchantmentData enchantment)
{
    NBTTagList nbttaglist = this.getEnchantments(stack);
    boolean flag = true;

    for (int i = 0; i < nbttaglist.tagCount(); ++i)
    {
        NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);

        if (Enchantment.getEnchantmentByID(nbttagcompound.getShort("id")) == enchantment.enchantmentobj)
        {
            if (nbttagcompound.getShort("lvl") < enchantment.enchantmentLevel)
            {
                nbttagcompound.setShort("lvl", (short)enchantment.enchantmentLevel);
            }

            flag = false;
            break;
        }
    }

    if (flag)
    {
        NBTTagCompound nbttagcompound1 = new NBTTagCompound();
        nbttagcompound1.setShort("id", (short)Enchantment.getEnchantmentID(enchantment.enchantmentobj));
        nbttagcompound1.setShort("lvl", (short)enchantment.enchantmentLevel);
        nbttaglist.appendTag(nbttagcompound1);
    }

    if (!stack.hasTagCompound())
    {
        stack.setTagCompound(new NBTTagCompound());
    }

    stack.getTagCompound().setTag("StoredEnchantments", nbttaglist);
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:40,代碼來源:ItemEnchantedBook.java

示例5: EntityEnchantment

import net.minecraft.enchantment.Enchantment; //導入方法依賴的package包/類
public EntityEnchantment(int id, int level) {
    this(Enchantment.getEnchantmentByID(id), level);
}
 
開發者ID:fr1kin,項目名稱:ForgeHax,代碼行數:4,代碼來源:EnchantmentUtils.java

示例6: drawScreen

import net.minecraft.enchantment.Enchantment; //導入方法依賴的package包/類
/**
 * Draws the screen and all the components in it.
 */
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
    super.drawScreen(mouseX, mouseY, partialTicks);
    boolean flag = this.mc.player.capabilities.isCreativeMode;
    int i = this.container.getLapisAmount();

    for (int j = 0; j < 3; ++j)
    {
        int k = this.container.enchantLevels[j];
        Enchantment enchantment = Enchantment.getEnchantmentByID(this.container.enchantClue[j]);
        int l = this.container.worldClue[j];
        int i1 = j + 1;

        if (this.isPointInRegion(60, 14 + 19 * j, 108, 17, mouseX, mouseY) && k > 0 && l >= 0 && enchantment != null)
        {
            List<String> list = Lists.<String>newArrayList();
            list.add("" + TextFormatting.WHITE + TextFormatting.ITALIC + I18n.format("container.enchant.clue", new Object[] {enchantment.getTranslatedName(l)}));

            if (!flag)
            {
                list.add("");

                if (this.mc.player.experienceLevel < k)
                {
                    list.add(TextFormatting.RED + "Level Requirement: " + this.container.enchantLevels[j]);
                }
                else
                {
                    String s;

                    if (i1 == 1)
                    {
                        s = I18n.format("container.enchant.lapis.one", new Object[0]);
                    }
                    else
                    {
                        s = I18n.format("container.enchant.lapis.many", new Object[] {Integer.valueOf(i1)});
                    }

                    TextFormatting textformatting = i >= i1 ? TextFormatting.GRAY : TextFormatting.RED;
                    list.add(textformatting + "" + s);

                    if (i1 == 1)
                    {
                        s = I18n.format("container.enchant.level.one", new Object[0]);
                    }
                    else
                    {
                        s = I18n.format("container.enchant.level.many", new Object[] {Integer.valueOf(i1)});
                    }

                    list.add(TextFormatting.GRAY + "" + s);
                }
            }

            this.drawHoveringText(list, mouseX, mouseY);
            break;
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:64,代碼來源:GuiEnchantment.java

示例7: execute

import net.minecraft.enchantment.Enchantment; //導入方法依賴的package包/類
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 2)
    {
        throw new WrongUsageException("commands.enchant.usage", new Object[0]);
    }
    else
    {
        EntityLivingBase entitylivingbase = (EntityLivingBase)getEntity(server, sender, args[0], EntityLivingBase.class);
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, 0);
        Enchantment enchantment;

        try
        {
            enchantment = Enchantment.getEnchantmentByID(parseInt(args[1], 0));
        }
        catch (NumberInvalidException var12)
        {
            enchantment = Enchantment.getEnchantmentByLocation(args[1]);
        }

        if (enchantment == null)
        {
            throw new NumberInvalidException("commands.enchant.notFound", new Object[] {args[1]});
        }
        else
        {
            int i = 1;
            ItemStack itemstack = entitylivingbase.getHeldItemMainhand();

            if (itemstack.func_190926_b())
            {
                throw new CommandException("commands.enchant.noItem", new Object[0]);
            }
            else if (!enchantment.canApply(itemstack))
            {
                throw new CommandException("commands.enchant.cantEnchant", new Object[0]);
            }
            else
            {
                if (args.length >= 3)
                {
                    i = parseInt(args[2], enchantment.getMinLevel(), enchantment.getMaxLevel());
                }

                if (itemstack.hasTagCompound())
                {
                    NBTTagList nbttaglist = itemstack.getEnchantmentTagList();

                    if (nbttaglist != null)
                    {
                        for (int j = 0; j < nbttaglist.tagCount(); ++j)
                        {
                            int k = nbttaglist.getCompoundTagAt(j).getShort("id");

                            if (Enchantment.getEnchantmentByID(k) != null)
                            {
                                Enchantment enchantment1 = Enchantment.getEnchantmentByID(k);

                                if (!enchantment.func_191560_c(enchantment1))
                                {
                                    throw new CommandException("commands.enchant.cantCombine", new Object[] {enchantment.getTranslatedName(i), enchantment1.getTranslatedName(nbttaglist.getCompoundTagAt(j).getShort("lvl"))});
                                }
                            }
                        }
                    }
                }

                itemstack.addEnchantment(enchantment, i);
                notifyCommandListener(sender, this, "commands.enchant.success", new Object[0]);
                sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, 1);
            }
        }
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:79,代碼來源:CommandEnchant.java

示例8: drawScreen

import net.minecraft.enchantment.Enchantment; //導入方法依賴的package包/類
/**
 * Draws the screen and all the components in it.
 */
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
    super.drawScreen(mouseX, mouseY, partialTicks);
    boolean flag = this.mc.thePlayer.capabilities.isCreativeMode;
    int i = this.container.getLapisAmount();

    for (int j = 0; j < 3; ++j)
    {
        int k = this.container.enchantLevels[j];
        Enchantment enchantment = Enchantment.getEnchantmentByID(this.container.enchantClue[j]);
        int l = this.container.worldClue[j];
        int i1 = j + 1;

        if (this.isPointInRegion(60, 14 + 19 * j, 108, 17, mouseX, mouseY) && k > 0 && l >= 0 && enchantment != null)
        {
            List<String> list = Lists.<String>newArrayList();
            list.add("" + TextFormatting.WHITE + TextFormatting.ITALIC + I18n.format("container.enchant.clue", new Object[] {enchantment.getTranslatedName(l)}));

            if (!flag)
            {
                list.add("");

                if (this.mc.thePlayer.experienceLevel < k)
                {
                    list.add(TextFormatting.RED + "Level Requirement: " + this.container.enchantLevels[j]);
                }
                else
                {
                    String s;

                    if (i1 == 1)
                    {
                        s = I18n.format("container.enchant.lapis.one", new Object[0]);
                    }
                    else
                    {
                        s = I18n.format("container.enchant.lapis.many", new Object[] {Integer.valueOf(i1)});
                    }

                    TextFormatting textformatting = i >= i1 ? TextFormatting.GRAY : TextFormatting.RED;
                    list.add(textformatting + "" + s);

                    if (i1 == 1)
                    {
                        s = I18n.format("container.enchant.level.one", new Object[0]);
                    }
                    else
                    {
                        s = I18n.format("container.enchant.level.many", new Object[] {Integer.valueOf(i1)});
                    }

                    list.add(TextFormatting.GRAY + "" + s);
                }
            }

            this.drawHoveringText(list, mouseX, mouseY);
            break;
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:64,代碼來源:GuiEnchantment.java

示例9: execute

import net.minecraft.enchantment.Enchantment; //導入方法依賴的package包/類
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 2)
    {
        throw new WrongUsageException("commands.enchant.usage", new Object[0]);
    }
    else
    {
        EntityLivingBase entitylivingbase = (EntityLivingBase)getEntity(server, sender, args[0], EntityLivingBase.class);
        sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, 0);
        Enchantment enchantment;

        try
        {
            enchantment = Enchantment.getEnchantmentByID(parseInt(args[1], 0));
        }
        catch (NumberInvalidException var12)
        {
            enchantment = Enchantment.getEnchantmentByLocation(args[1]);
        }

        if (enchantment == null)
        {
            throw new NumberInvalidException("commands.enchant.notFound", new Object[] {Integer.valueOf(Enchantment.getEnchantmentID(enchantment))});
        }
        else
        {
            int i = 1;
            ItemStack itemstack = entitylivingbase.getHeldItemMainhand();

            if (itemstack == null)
            {
                throw new CommandException("commands.enchant.noItem", new Object[0]);
            }
            else if (!enchantment.canApply(itemstack))
            {
                throw new CommandException("commands.enchant.cantEnchant", new Object[0]);
            }
            else
            {
                if (args.length >= 3)
                {
                    i = parseInt(args[2], enchantment.getMinLevel(), enchantment.getMaxLevel());
                }

                if (itemstack.hasTagCompound())
                {
                    NBTTagList nbttaglist = itemstack.getEnchantmentTagList();

                    if (nbttaglist != null)
                    {
                        for (int j = 0; j < nbttaglist.tagCount(); ++j)
                        {
                            int k = nbttaglist.getCompoundTagAt(j).getShort("id");

                            if (Enchantment.getEnchantmentByID(k) != null)
                            {
                                Enchantment enchantment1 = Enchantment.getEnchantmentByID(k);

                                if (!enchantment.canApplyTogether(enchantment1) || !enchantment1.canApplyTogether(enchantment)) //Forge BugFix: Let Both enchantments veto being together
                                {
                                    throw new CommandException("commands.enchant.cantCombine", new Object[] {enchantment.getTranslatedName(i), enchantment1.getTranslatedName(nbttaglist.getCompoundTagAt(j).getShort("lvl"))});
                                }
                            }
                        }
                    }
                }

                itemstack.addEnchantment(enchantment, i);
                notifyCommandListener(sender, this, "commands.enchant.success", new Object[0]);
                sender.setCommandStat(CommandResultStats.Type.AFFECTED_ITEMS, 1);
            }
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:79,代碼來源:CommandEnchant.java


注:本文中的net.minecraft.enchantment.Enchantment.getEnchantmentByID方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。