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


Java ItemStack.setItem方法代码示例

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


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

示例1: addRandomEnchantment

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Applys a random enchantment to the specified item.
 */
public static ItemStack addRandomEnchantment(Random random, ItemStack p_77504_1_, int p_77504_2_, boolean allowTreasure)
{
    boolean flag = p_77504_1_.getItem() == Items.BOOK;
    List<EnchantmentData> list = buildEnchantmentList(random, p_77504_1_, p_77504_2_, allowTreasure);

    if (flag)
    {
        p_77504_1_.setItem(Items.ENCHANTED_BOOK);
    }

    for (EnchantmentData enchantmentdata : list)
    {
        if (flag)
        {
            Items.ENCHANTED_BOOK.addEnchantment(p_77504_1_, enchantmentdata);
        }
        else
        {
            p_77504_1_.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
        }
    }

    return p_77504_1_;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:28,代码来源:EnchantmentHelper.java

示例2: addRandomEnchantment

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Adds a random enchantment to the specified item. Args: random, itemStack, enchantabilityLevel
 */
public static ItemStack addRandomEnchantment(Random p_77504_0_, ItemStack p_77504_1_, int p_77504_2_)
{
    List<EnchantmentData> list = buildEnchantmentList(p_77504_0_, p_77504_1_, p_77504_2_);
    boolean flag = p_77504_1_.getItem() == Items.book;

    if (flag)
    {
        p_77504_1_.setItem(Items.enchanted_book);
    }

    if (list != null)
    {
        for (EnchantmentData enchantmentdata : list)
        {
            if (flag)
            {
                Items.enchanted_book.addEnchantment(p_77504_1_, enchantmentdata);
            }
            else
            {
                p_77504_1_.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
            }
        }
    }

    return p_77504_1_;
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:31,代码来源:EnchantmentHelper.java

示例3: enchantItem

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Handles the given Button-click on the server, currently only used by enchanting. Name is for legacy.
 */
public boolean enchantItem(EntityPlayer playerIn, int id)
{
    ItemStack itemstack = this.tableInventory.getStackInSlot(0);
    ItemStack itemstack1 = this.tableInventory.getStackInSlot(1);
    int i = id + 1;

    if ((itemstack1 == null || itemstack1.stackSize < i) && !playerIn.capabilities.isCreativeMode)
    {
        return false;
    }
    else if (this.enchantLevels[id] > 0 && itemstack != null && (playerIn.experienceLevel >= i && playerIn.experienceLevel >= this.enchantLevels[id] || playerIn.capabilities.isCreativeMode))
    {
        if (!this.worldPointer.isRemote)
        {
            List<EnchantmentData> list = this.func_178148_a(itemstack, id, this.enchantLevels[id]);
            boolean flag = itemstack.getItem() == Items.book;

            if (list != null)
            {
                playerIn.removeExperienceLevel(i);

                if (flag)
                {
                    itemstack.setItem(Items.enchanted_book);
                }

                for (int j = 0; j < list.size(); ++j)
                {
                    EnchantmentData enchantmentdata = (EnchantmentData)list.get(j);

                    if (flag)
                    {
                        Items.enchanted_book.addEnchantment(itemstack, enchantmentdata);
                    }
                    else
                    {
                        itemstack.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
                    }
                }

                if (!playerIn.capabilities.isCreativeMode)
                {
                    itemstack1.stackSize -= i;

                    if (itemstack1.stackSize <= 0)
                    {
                        this.tableInventory.setInventorySlotContents(1, (ItemStack)null);
                    }
                }

                playerIn.triggerAchievement(StatList.field_181739_W);
                this.tableInventory.markDirty();
                this.xpSeed = playerIn.getXPSeed();
                this.onCraftMatrixChanged(this.tableInventory);
            }
        }

        return true;
    }
    else
    {
        return false;
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:68,代码来源:ContainerEnchantment.java

示例4: enchantItem

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Handles the given Button-click on the server, currently only used by enchanting. Name is for legacy.
 */
public boolean enchantItem(EntityPlayer playerIn, int id)
{
    ItemStack itemstack = this.tableInventory.getStackInSlot(0);
    ItemStack itemstack1 = this.tableInventory.getStackInSlot(1);
    int i = id + 1;

    if ((itemstack1 == null || itemstack1.stackSize < i) && !playerIn.capabilities.isCreativeMode)
    {
        return false;
    }
    else if (this.enchantLevels[id] > 0 && itemstack != null && (playerIn.experienceLevel >= i && playerIn.experienceLevel >= this.enchantLevels[id] || playerIn.capabilities.isCreativeMode))
    {
        if (!this.worldPointer.isRemote)
        {
            List<EnchantmentData> list = this.getEnchantmentList(itemstack, id, this.enchantLevels[id]);
            boolean flag = itemstack.getItem() == Items.BOOK;

            if (list != null)
            {
                playerIn.removeExperienceLevel(i);

                if (flag)
                {
                    itemstack.setItem(Items.ENCHANTED_BOOK);
                }

                for (int j = 0; j < list.size(); ++j)
                {
                    EnchantmentData enchantmentdata = (EnchantmentData)list.get(j);

                    if (flag)
                    {
                        Items.ENCHANTED_BOOK.addEnchantment(itemstack, enchantmentdata);
                    }
                    else
                    {
                        itemstack.addEnchantment(enchantmentdata.enchantmentobj, enchantmentdata.enchantmentLevel);
                    }
                }

                if (!playerIn.capabilities.isCreativeMode)
                {
                    itemstack1.stackSize -= i;

                    if (itemstack1.stackSize <= 0)
                    {
                        this.tableInventory.setInventorySlotContents(1, (ItemStack)null);
                    }
                }

                playerIn.addStat(StatList.ITEM_ENCHANTED);
                this.tableInventory.markDirty();
                this.xpSeed = playerIn.getXPSeed();
                this.onCraftMatrixChanged(this.tableInventory);
                this.worldPointer.playSound((EntityPlayer)null, this.position, SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, SoundCategory.BLOCKS, 1.0F, this.worldPointer.rand.nextFloat() * 0.1F + 0.9F);
            }
        }

        return true;
    }
    else
    {
        return false;
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:69,代码来源:ContainerEnchantment.java


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