本文整理汇总了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_;
}
示例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_;
}
示例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;
}
}
示例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;
}
}