当前位置: 首页>>代码示例>>Java>>正文


Java Enchantment.getTranslatedName方法代码示例

本文整理汇总了Java中net.minecraft.enchantment.Enchantment.getTranslatedName方法的典型用法代码示例。如果您正苦于以下问题:Java Enchantment.getTranslatedName方法的具体用法?Java Enchantment.getTranslatedName怎么用?Java Enchantment.getTranslatedName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.minecraft.enchantment.Enchantment的用法示例。


在下文中一共展示了Enchantment.getTranslatedName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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.getTranslatedName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。