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


Java ItemStack.isItemDamaged方法代码示例

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


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

示例1: call

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void call(String[] args) throws CmdException
{
	if(args.length > 0)
		throw new CmdSyntaxError();
	
	// check for creative mode
	EntityPlayerSP player = WMinecraft.getPlayer();
	if(!player.capabilities.isCreativeMode)
		throw new CmdError("Creative mode only.");
	
	// validate item
	ItemStack item = player.inventory.getCurrentItem();
	if(item == null)
		throw new CmdError("You need an item in your hand.");
	if(!item.isItemStackDamageable())
		throw new CmdError("This item can't take damage.");
	if(!item.isItemDamaged())
		throw new CmdError("This item is not damaged.");
	
	// repair item
	item.setItemDamage(0);
	WConnection.sendPacket(new CPacketCreativeInventoryAction(
		36 + player.inventory.currentItem, item));
}
 
开发者ID:Wurst-Imperium,项目名称:Wurst-MC-1.12,代码行数:26,代码来源:RepairCmd.java

示例2: onBlockActivated

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack stack, EnumFacing side, float hitX, float hitY, float hitZ) {

	if (this.getAge(state) < getMaxAge()) return false;
	
	if (!world.isRemote && hand == EnumHand.MAIN_HAND) {
		ItemStack stacky = player.getHeldItemMainhand();
		if (stacky == null || (stacky != null && !stacky.isItemDamaged())) return false;
		
		int repair = stacky.getMaxDamage() / 2;
		stacky.setItemDamage(Math.max(stacky.getItemDamage() - repair, 0));
		world.setBlockState(pos, this.withAge(0), 2);
		return true;
	}
	return false;
}
 
开发者ID:bafomdad,项目名称:uniquecrops,代码行数:17,代码来源:Malleatoris.java

示例3: onCollideWithPlayer

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Called by a player entity when they collide with an entity
 */
public void onCollideWithPlayer(EntityPlayer entityIn)
{
    if (!this.world.isRemote)
    {
        if (this.delayBeforeCanPickup == 0 && entityIn.xpCooldown == 0)
        {
            entityIn.xpCooldown = 2;
            entityIn.onItemPickup(this, 1);
            ItemStack itemstack = EnchantmentHelper.getEnchantedItem(Enchantments.MENDING, entityIn);

            if (!itemstack.func_190926_b() && itemstack.isItemDamaged())
            {
                int i = Math.min(this.xpToDurability(this.xpValue), itemstack.getItemDamage());
                this.xpValue -= this.durabilityToXp(i);
                itemstack.setItemDamage(itemstack.getItemDamage() - i);
            }

            if (this.xpValue > 0)
            {
                entityIn.addExperience(this.xpValue);
            }

            this.setDead();
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:30,代码来源:EntityXPOrb.java

示例4: onCollideWithPlayer

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Called by a player entity when they collide with an entity
 */
public void onCollideWithPlayer(EntityPlayer entityIn)
{
    if (!this.worldObj.isRemote)
    {
        if (this.delayBeforeCanPickup == 0 && entityIn.xpCooldown == 0)
        {
            if (net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.entity.player.PlayerPickupXpEvent(entityIn, this))) return;
            entityIn.xpCooldown = 2;
            this.worldObj.playSound((EntityPlayer)null, entityIn.posX, entityIn.posY, entityIn.posZ, SoundEvents.ENTITY_EXPERIENCE_ORB_TOUCH, SoundCategory.PLAYERS, 0.1F, 0.5F * ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.8F));
            entityIn.onItemPickup(this, 1);
            ItemStack itemstack = EnchantmentHelper.getEnchantedItem(Enchantments.MENDING, entityIn);

            if (itemstack != null && itemstack.isItemDamaged())
            {
                int i = Math.min(this.xpToDurability(this.xpValue), itemstack.getItemDamage());
                this.xpValue -= this.durabilityToXp(i);
                itemstack.setItemDamage(itemstack.getItemDamage() - i);
            }

            if (this.xpValue > 0)
            {
                entityIn.addExperience(this.xpValue);
            }

            this.setDead();
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:32,代码来源:EntityXPOrb.java

示例5: processingLogic

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@SuppressWarnings("ConstantConditions")
public boolean processingLogic(ItemStack stack) {
	if (!isBoiling() || hasIngredients() || stack.getCount() > 8192) return false;
	Map<Item, ItemValidator<ItemStack>> processing = CauldronRegistry.getItemProcessing(inv.getInnerFluid());
	if (processing != null && processing.containsKey(stack.getItem())) {
		ItemValidator<ItemStack> validator = processing.get(stack.getItem());
		Optional<ItemStack> optional = validator.getMatchFor(stack);
		if (optional.isPresent()) {
			ItemStack out = optional.get().copy();
			if (stack.isItemDamaged() && out.isItemStackDamageable())
				out.setItemDamage(stack.getItemDamage());
			int fluidAmount = inv.getFluidAmount();
			int fluidTaken = 250;
			out.setCount(0);

			if (stack.getCount() <= 16) {
				out.setCount(stack.getCount());
				stack.setCount(0);
			} else {
				while (stack.getCount() > 0 && fluidTaken <= fluidAmount) {
					stack.shrink(1);
					out.grow(1);
					if (out.getCount() % 16 == 0) {
						if (fluidTaken >= fluidAmount) {
							fluidTaken = fluidAmount;
							break;
						}
						fluidTaken += 250;
					}
				}
			}

			if (out.getCount() > 0) {
				final double x = getPos().getX();
				final double y = getPos().getY() + 1D;
				final double z = getPos().getZ();
				final EntityItem item = new EntityItem(world, x + 0.5D, y, z + 0.5D, out);
				item.motionX = world.rand.nextDouble() * 2 - 1;
				item.motionZ = world.rand.nextDouble() * 2 - 1;
				item.motionY = 0.1D;
				item.setPickupDelay(0);
				world.spawnEntity(item);

				play(SoundEvents.BLOCK_FIRE_EXTINGUISH, 1F, 1F);
				for (int i = 0; i < 4; i++) {
					PacketHandler.spawnParticle(ParticleF.STEAM, world, x + world.rand.nextFloat(), getParticleLevel(), z + world.rand.nextFloat(), 5, 0, 0, 0);
				}

				inv.drain(fluidTaken, true);
				return true;
			}
		}
	}
	return false;
}
 
开发者ID:Um-Mitternacht,项目名称:Bewitchment,代码行数:56,代码来源:TileCauldron.java

示例6: addItemStackToInventory

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Adds the item stack to the inventory, returns false if it is impossible.
 */
public boolean addItemStackToInventory(final ItemStack itemStackIn)
{
    if (itemStackIn != null && itemStackIn.stackSize != 0 && itemStackIn.getItem() != null)
    {
        try
        {
            if (itemStackIn.isItemDamaged())
            {
                int j = this.getFirstEmptyStack();

                if (j >= 0)
                {
                    this.mainInventory[j] = ItemStack.copyItemStack(itemStackIn);
                    this.mainInventory[j].animationsToGo = 5;
                    itemStackIn.stackSize = 0;
                    return true;
                }
                else if (this.player.capabilities.isCreativeMode)
                {
                    itemStackIn.stackSize = 0;
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                int i;

                while (true)
                {
                    i = itemStackIn.stackSize;
                    itemStackIn.stackSize = this.storePartialItemStack(itemStackIn);

                    if (itemStackIn.stackSize <= 0 || itemStackIn.stackSize >= i)
                    {
                        break;
                    }
                }

                if (itemStackIn.stackSize == i && this.player.capabilities.isCreativeMode)
                {
                    itemStackIn.stackSize = 0;
                    return true;
                }
                else
                {
                    return itemStackIn.stackSize < i;
                }
            }
        }
        catch (Throwable throwable)
        {
            CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Adding item to inventory");
            CrashReportCategory crashreportcategory = crashreport.makeCategory("Item being added");
            crashreportcategory.addCrashSection("Item ID", Integer.valueOf(Item.getIdFromItem(itemStackIn.getItem())));
            crashreportcategory.addCrashSection("Item data", Integer.valueOf(itemStackIn.getMetadata()));
            crashreportcategory.addCrashSectionCallable("Item name", new Callable<String>()
            {
                public String call() throws Exception
                {
                    return itemStackIn.getDisplayName();
                }
            });
            throw new ReportedException(crashreport);
        }
    }
    else
    {
        return false;
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:78,代码来源:InventoryPlayer.java

示例7: renderItemOverlayIntoGUI

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Renders the stack size and/or damage bar for the given ItemStack.
 */
public void renderItemOverlayIntoGUI(FontRenderer fr, ItemStack stack, int xPosition, int yPosition, String text)
{
    if (stack != null)
    {
        if (stack.stackSize != 1 || text != null)
        {
            String s = text == null ? String.valueOf(stack.stackSize) : text;

            if (text == null && stack.stackSize < 1)
            {
                s = EnumChatFormatting.RED + String.valueOf(stack.stackSize);
            }

            GlStateManager.disableLighting();
            GlStateManager.disableDepth();
            GlStateManager.disableBlend();
            fr.drawStringWithShadow(s, (float)(xPosition + 19 - 2 - fr.getStringWidth(s)), (float)(yPosition + 6 + 3), 16777215);
            GlStateManager.enableLighting();
            GlStateManager.enableDepth();
        }

        if (stack.isItemDamaged())
        {
            int j = (int)Math.round(13.0D - (double)stack.getItemDamage() * 13.0D / (double)stack.getMaxDamage());
            int i = (int)Math.round(255.0D - (double)stack.getItemDamage() * 255.0D / (double)stack.getMaxDamage());
            GlStateManager.disableLighting();
            GlStateManager.disableDepth();
            GlStateManager.disableTexture2D();
            GlStateManager.disableAlpha();
            GlStateManager.disableBlend();
            Tessellator tessellator = Tessellator.getInstance();
            WorldRenderer worldrenderer = tessellator.getWorldRenderer();
            this.func_181565_a(worldrenderer, xPosition + 2, yPosition + 13, 13, 2, 0, 0, 0, 255);
            this.func_181565_a(worldrenderer, xPosition + 2, yPosition + 13, 12, 1, (255 - i) / 4, 64, 0, 255);
            this.func_181565_a(worldrenderer, xPosition + 2, yPosition + 13, j, 1, 255 - i, i, 0, 255);
            GlStateManager.enableBlend();
            GlStateManager.enableAlpha();
            GlStateManager.enableTexture2D();
            GlStateManager.enableLighting();
            GlStateManager.enableDepth();
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:47,代码来源:RenderItem.java

示例8: isItemDamaged

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
public static boolean isItemDamaged(ItemStack p_isItemDamaged_0_)
{
    return !Reflector.ForgeItem_showDurabilityBar.exists() ? p_isItemDamaged_0_.isItemDamaged() : Reflector.callBoolean(p_isItemDamaged_0_.getItem(), Reflector.ForgeItem_showDurabilityBar, new Object[] {p_isItemDamaged_0_});
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:5,代码来源:ReflectorForge.java

示例9: renderItemOverlayIntoGUI

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Renders the stack size and/or damage bar for the given ItemStack.
 */
public void renderItemOverlayIntoGUI(FontRenderer fr, ItemStack stack, int xPosition, int yPosition, String text)
{
    if (stack != null)
    {
        if (stack.stackSize != 1 || text != null)
        {
            String s = text == null ? String.valueOf(stack.stackSize) : text;

            if (text == null && stack.stackSize < 1)
            {
                s = EnumChatFormatting.RED + String.valueOf(stack.stackSize);
            }

            GlStateManager.disableLighting();
            GlStateManager.disableDepth();
            GlStateManager.disableBlend();
            fr.drawStringWithShadow(s, (float)(xPosition + 19 - 2 - fr.getStringWidth(s)), (float)(yPosition + 6 + 3), 16777215);
            GlStateManager.enableLighting();
            GlStateManager.enableDepth();
        }

        boolean flag = stack.isItemDamaged();

        if (Reflector.ForgeItem_showDurabilityBar.exists())
        {
            flag = Reflector.callBoolean(stack.getItem(), Reflector.ForgeItem_showDurabilityBar, new Object[] {stack});
        }

        if (flag)
        {
            int i = (int)Math.round(13.0D - (double)stack.getItemDamage() * 13.0D / (double)stack.getMaxDamage());
            int j = (int)Math.round(255.0D - (double)stack.getItemDamage() * 255.0D / (double)stack.getMaxDamage());

            if (Reflector.ForgeItem_getDurabilityForDisplay.exists())
            {
                double d0 = Reflector.callDouble(stack.getItem(), Reflector.ForgeItem_getDurabilityForDisplay, new Object[] {stack});
                i = (int)Math.round(13.0D - d0 * 13.0D);
                j = (int)Math.round(255.0D - d0 * 255.0D);
            }

            GlStateManager.disableLighting();
            GlStateManager.disableDepth();
            GlStateManager.disableTexture2D();
            GlStateManager.disableAlpha();
            GlStateManager.disableBlend();
            Tessellator tessellator = Tessellator.getInstance();
            WorldRenderer worldrenderer = tessellator.getWorldRenderer();
            this.func_181565_a(worldrenderer, xPosition + 2, yPosition + 13, 13, 2, 0, 0, 0, 255);
            this.func_181565_a(worldrenderer, xPosition + 2, yPosition + 13, 12, 1, (255 - j) / 4, 64, 0, 255);
            this.func_181565_a(worldrenderer, xPosition + 2, yPosition + 13, i, 1, 255 - j, j, 0, 255);

            if (!Reflector.ForgeHooksClient.exists())
            {
                GlStateManager.enableBlend();
            }

            GlStateManager.enableAlpha();
            GlStateManager.enableTexture2D();
            GlStateManager.enableLighting();
            GlStateManager.enableDepth();
        }
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:67,代码来源:RenderItem.java

示例10: addItemStackToInventory

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Adds the item stack to the inventory, returns false if it is impossible.
 */
public boolean addItemStackToInventory(final ItemStack itemStackIn)
{
    if (itemStackIn.func_190926_b())
    {
        return false;
    }
    else
    {
        try
        {
            if (itemStackIn.isItemDamaged())
            {
                int j = this.getFirstEmptyStack();

                if (j >= 0)
                {
                    this.mainInventory.set(j, itemStackIn.copy());
                    ((ItemStack)this.mainInventory.get(j)).func_190915_d(5);
                    itemStackIn.func_190920_e(0);
                    return true;
                }
                else if (this.player.capabilities.isCreativeMode)
                {
                    itemStackIn.func_190920_e(0);
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                int i;

                while (true)
                {
                    i = itemStackIn.func_190916_E();
                    itemStackIn.func_190920_e(this.storePartialItemStack(itemStackIn));

                    if (itemStackIn.func_190926_b() || itemStackIn.func_190916_E() >= i)
                    {
                        break;
                    }
                }

                if (itemStackIn.func_190916_E() == i && this.player.capabilities.isCreativeMode)
                {
                    itemStackIn.func_190920_e(0);
                    return true;
                }
                else
                {
                    return itemStackIn.func_190916_E() < i;
                }
            }
        }
        catch (Throwable throwable)
        {
            CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Adding item to inventory");
            CrashReportCategory crashreportcategory = crashreport.makeCategory("Item being added");
            crashreportcategory.addCrashSection("Item ID", Integer.valueOf(Item.getIdFromItem(itemStackIn.getItem())));
            crashreportcategory.addCrashSection("Item data", Integer.valueOf(itemStackIn.getMetadata()));
            crashreportcategory.setDetail("Item name", new ICrashReportDetail<String>()
            {
                public String call() throws Exception
                {
                    return itemStackIn.getDisplayName();
                }
            });
            throw new ReportedException(crashreport);
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:78,代码来源:InventoryPlayer.java

示例11: addItemStackToInventory

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Adds the item stack to the inventory, returns false if it is impossible.
 */
public boolean addItemStackToInventory(@Nullable final ItemStack itemStackIn)
{
    if (itemStackIn != null && itemStackIn.stackSize != 0 && itemStackIn.getItem() != null)
    {
        try
        {
            if (itemStackIn.isItemDamaged())
            {
                int j = this.getFirstEmptyStack();

                if (j >= 0)
                {
                    this.mainInventory[j] = ItemStack.copyItemStack(itemStackIn);
                    this.mainInventory[j].animationsToGo = 5;
                    itemStackIn.stackSize = 0;
                    return true;
                }
                else if (this.player.capabilities.isCreativeMode)
                {
                    itemStackIn.stackSize = 0;
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                int i;

                while (true)
                {
                    i = itemStackIn.stackSize;
                    itemStackIn.stackSize = this.storePartialItemStack(itemStackIn);

                    if (itemStackIn.stackSize <= 0 || itemStackIn.stackSize >= i)
                    {
                        break;
                    }
                }

                if (itemStackIn.stackSize == i && this.player.capabilities.isCreativeMode)
                {
                    itemStackIn.stackSize = 0;
                    return true;
                }
                else
                {
                    return itemStackIn.stackSize < i;
                }
            }
        }
        catch (Throwable throwable)
        {
            CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Adding item to inventory");
            CrashReportCategory crashreportcategory = crashreport.makeCategory("Item being added");
            crashreportcategory.addCrashSection("Item ID", Integer.valueOf(Item.getIdFromItem(itemStackIn.getItem())));
            crashreportcategory.addCrashSection("Item data", Integer.valueOf(itemStackIn.getMetadata()));
            crashreportcategory.setDetail("Item name", new ICrashReportDetail<String>()
            {
                public String call() throws Exception
                {
                    return itemStackIn.getDisplayName();
                }
            });
            throw new ReportedException(crashreport);
        }
    }
    else
    {
        return false;
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:78,代码来源:InventoryPlayer.java


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