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


Java ItemStack.damageItem方法代码示例

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


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

示例1: processInteract

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
protected boolean processInteract(EntityPlayer player, EnumHand hand)
{
    ItemStack itemstack = player.getHeldItem(hand);

    if (itemstack.getItem() == Items.FLINT_AND_STEEL)
    {
        this.world.playSound(player, this.posX, this.posY, this.posZ, SoundEvents.ITEM_FLINTANDSTEEL_USE, this.getSoundCategory(), 1.0F, this.rand.nextFloat() * 0.4F + 0.8F);
        player.swingArm(hand);

        if (!this.world.isRemote)
        {
            this.ignite();
            itemstack.damageItem(1, player);
            return true;
        }
    }

    return super.processInteract(player, hand);
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:20,代码来源:EntityCreeper.java

示例2: onWitherBoneHarvestEvent

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onWitherBoneHarvestEvent(BlockEvent.HarvestDropsEvent event) {
	if (event.getHarvester() == null) {
		return;
	}

	EntityPlayer player = event.getHarvester();
	ItemStack stack = player.getHeldItemMainhand();

	boolean flag = false;

	if (stack.getItem() instanceof IHaftTool) {
		if (IHaftTool.getHaftMat(stack) == ModMaterials.HAFT_WITHER_BONE) {
			flag = true;
		}
	}

	if (flag) {
		if (player.dimension != DimensionType.NETHER.getId()) {
			stack.damageItem(7, player);
		}
	}
}
 
开发者ID:the-realest-stu,项目名称:Adventurers-Toolbox,代码行数:24,代码来源:SpecialToolAbilityHandler.java

示例3: interact

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
protected boolean interact(EntityPlayer player)
{
    ItemStack itemstack = player.inventory.getCurrentItem();

    if (itemstack != null && itemstack.getItem() == Items.flint_and_steel)
    {
        this.worldObj.playSoundEffect(this.posX + 0.5D, this.posY + 0.5D, this.posZ + 0.5D, "fire.ignite", 1.0F, this.rand.nextFloat() * 0.4F + 0.8F);
        player.swingItem();

        if (!this.worldObj.isRemote)
        {
            this.ignite();
            itemstack.damageItem(1, player);
            return true;
        }
    }

    return super.interact(player);
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:23,代码来源:EntityCreeper.java

示例4: damageArmor

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Damages armor in each slot by the specified amount.
 */
public void damageArmor(float damage)
{
    damage = damage / 4.0F;

    if (damage < 1.0F)
    {
        damage = 1.0F;
    }

    for (int i = 0; i < this.armorInventory.size(); ++i)
    {
        ItemStack itemstack = (ItemStack)this.armorInventory.get(i);

        if (itemstack.getItem() instanceof ItemArmor)
        {
            itemstack.damageItem((int)damage, this.player);
        }
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:23,代码来源:InventoryPlayer.java

示例5: processInteract

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
protected boolean processInteract(EntityPlayer player, EnumHand hand)
{
	ItemStack stack = player.getHeldItem(hand);
	if (!stack.isEmpty() && stack.getItem() == Items.FLINT_AND_STEEL)
	{
		this.world.playSound(player, this.posX, this.posY, this.posZ, SoundEvents.ITEM_FLINTANDSTEEL_USE, this.getSoundCategory(), 1.0F, this.rand.nextFloat() * 0.4F + 0.8F);
		player.swingArm(hand);

		if (!this.world.isRemote)
		{
			this.ignite();
			stack.damageItem(1, player);
			return true;
		}
	}
	return super.processInteract(player, hand);
}
 
开发者ID:crazysnailboy,项目名称:Halloween,代码行数:19,代码来源:EntityCreeperween.java

示例6: onExecutionTick

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void onExecutionTick(EntityPlayer player, int progress)
{
	player.world.playSound(player, player.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, SoundCategory.PLAYERS, 1, 2F);
	Vec3d look = player.getLookVec().scale(3);
	Vec3d pos = player.getPositionVector();
	List<EntityLivingBase> targets = Helpers.rayTraceEntities(player.world, pos.addVector(0, player.getEyeHeight(), 0), look, Optional.of(e -> e != player), EntityLivingBase.class);
	EntityLivingBase assumedToBeLookedAt = Helpers.getClosest(targets, player);
	if (assumedToBeLookedAt != null)
	{
		assumedToBeLookedAt.hurtResistantTime = 0;
		assumedToBeLookedAt.attackEntityFrom(DamageSource.causePlayerDamage(player), Math.max(1, (float) player.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue() / 10));
		player.world.playSound(player, player.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, SoundCategory.PLAYERS, 1, 0.1F);
		Vec3d targetPos = assumedToBeLookedAt.getPositionVector();
		player.world.spawnParticle(EnumParticleTypes.CRIT, targetPos.x + player.world.rand.nextDouble() / 2 - player.world.rand.nextDouble() / 2, targetPos.y + assumedToBeLookedAt.getEyeHeight() + player.world.rand.nextDouble() / 2 - player.world.rand.nextDouble() / 2, targetPos.z + player.world.rand.nextDouble() / 2 - player.world.rand.nextDouble() / 2, 0, 0, 0);
		if (!player.world.isRemote)
		{
			ItemStack is = player.getHeldItemMainhand().isEmpty() ? player.getHeldItemOffhand() : player.getHeldItemMainhand();
			is.damageItem(1, player);
		}
	}
}
 
开发者ID:V0idWa1k3r,项目名称:ExPetrum,代码行数:23,代码来源:Stab.java

示例7: hitEntity

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, @Nonnull EntityLivingBase attacker) {
	if (!target.world.isRemote) {
		if (target.getCreatureAttribute() == EnumCreatureAttribute.UNDEAD && attacker instanceof EntityPlayer) {
			target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 12);
			stack.damageItem(25, attacker);
		} else {
			stack.damageItem(1, attacker);
		}
	}

	return true;
}
 
开发者ID:Um-Mitternacht,项目名称:Bewitchment,代码行数:14,代码来源:ItemSilverAxe.java

示例8: onArmorTick

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack armor) {
	if(!world.isRemote) {

		// ecological I: repair 1 damage per 5 seconds when wet
		// repair 1 damage per 60 seconds when not wet
		if(armor.getItemDamage() > 0) {
			if((player.isWet() && player.ticksExisted % 100 == 0) || player.ticksExisted % 1200 == 0) {
				armor.damageItem(-1, player);
			}
		}
		
	}
}
 
开发者ID:sblectric,项目名称:AdvancedCombat,代码行数:15,代码来源:ItemArmorStone.java

示例9: hitEntity

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) {
	super.hitEntity(stack, target, attacker);

	for (ItemStack armor : target.getArmorInventoryList()) {
		if (armor.isItemStackDamageable() && this.itemRand.nextFloat() < 0.3F) {
			armor.damageItem((int) (this.getAttackDamage(stack) / 2) + 1, target);
		}
	}

	return true;
}
 
开发者ID:the-realest-stu,项目名称:Adventurers-Toolbox,代码行数:13,代码来源:ItemATMace.java

示例10: updateElytra

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Called each tick. Updates state for the elytra.
 */
private void updateElytra()
{
    boolean flag = this.getFlag(7);

    if (flag && !this.onGround && !this.isRiding())
    {
        ItemStack itemstack = this.getItemStackFromSlot(EntityEquipmentSlot.CHEST);

        if (itemstack != null && itemstack.getItem() == Items.ELYTRA && ItemElytra.isBroken(itemstack))
        {
            flag = true;

            if (!this.worldObj.isRemote && (this.ticksElytraFlying + 1) % 20 == 0)
            {
                itemstack.damageItem(1, this);
            }
        }
        else
        {
            flag = false;
        }
    }
    else
    {
        flag = false;
    }

    if (!this.worldObj.isRemote)
    {
        this.setFlag(7, flag);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:36,代码来源:EntityLivingBase.java

示例11: onPlayerStoppedUsing

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
	if(getMaxItemUseDuration(stack) - timeLeft < 10)
		return;
	float f = ItemBow.getArrowVelocity(getMaxItemUseDuration(stack) - timeLeft);
	spawnThrownEntity(worldIn, entityLiving, 3f * f, new HarshenEnderArrow(f), new EntityThrowSpawnData(1).setIgnoreBlocks(true));
       worldIn.playSound((EntityPlayer)null, entityLiving.posX, entityLiving.posY, entityLiving.posZ, SoundEvents.ENTITY_ENDERMITE_AMBIENT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
	stack.damageItem(1, entityLiving);
}
 
开发者ID:kenijey,项目名称:harshencastle,代码行数:10,代码来源:EnderBow.java

示例12: consumePower

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
protected boolean consumePower(EntityPlayer player) {
	ItemStack stack = player.getHeldItem(EnumHand.OFF_HAND);
	if (stack.getItem() instanceof IInfernalPowerItem) {
		if ((stack.getMaxDamage() - stack.getItemDamage()) >= getCost()) {
			stack.damageItem(cost, player);
			return true;
		}
	}
	return false;
}
 
开发者ID:the-realest-stu,项目名称:Infernum,代码行数:11,代码来源:Spell.java

示例13: interact

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
/**
 * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig.
 */
public boolean interact(EntityPlayer player)
{
    ItemStack itemstack = player.inventory.getCurrentItem();

    if (itemstack != null && itemstack.getItem() == Items.shears && !this.getSheared() && !this.isChild())
    {
        if (!this.worldObj.isRemote)
        {
            this.setSheared(true);
            int i = 1 + this.rand.nextInt(3);

            for (int j = 0; j < i; ++j)
            {
                EntityItem entityitem = this.entityDropItem(new ItemStack(Item.getItemFromBlock(Blocks.wool), 1, this.getFleeceColor().getMetadata()), 1.0F);
                entityitem.motionY += (double)(this.rand.nextFloat() * 0.05F);
                entityitem.motionX += (double)((this.rand.nextFloat() - this.rand.nextFloat()) * 0.1F);
                entityitem.motionZ += (double)((this.rand.nextFloat() - this.rand.nextFloat()) * 0.1F);
            }
        }

        itemstack.damageItem(1, player);
        this.playSound("mob.sheep.shear", 1.0F, 1.0F);
    }

    return super.interact(player);
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:30,代码来源:EntitySheep.java

示例14: onExecutionStart

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public void onExecutionStart(EntityPlayer player)
{
	ItemStack is = player.getHeldItemMainhand().isEmpty() ? player.getHeldItemOffhand() : player.getHeldItemMainhand();
	player.world.playSound(player, player.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, SoundCategory.PLAYERS, 1, 1F);
	Vec3d look = player.getLookVec().scale(5);
	Vec3d pos = player.getPositionVector();
	List<EntityLivingBase> targets = Helpers.rayTraceEntities(player.world, pos.addVector(0, player.getEyeHeight(), 0), look, Optional.of(e -> e != player), EntityLivingBase.class);
	EntityLivingBase assumedToBeLookedAt = Helpers.getClosest(targets, player);
	if (assumedToBeLookedAt != null)
	{
		if (!player.world.isRemote)
		{
			is.damageItem(1, player);
		}
		
		assumedToBeLookedAt.attackEntityFrom(DamageSource.causePlayerDamage(player), (float) player.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue());
		player.world.playSound(player, player.getPosition(), SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, SoundCategory.PLAYERS, 1, 0.1F);
		Vec3d targetPos = assumedToBeLookedAt.getPositionVector();
		player.world.spawnParticle(EnumParticleTypes.SWEEP_ATTACK, targetPos.x, targetPos.y + assumedToBeLookedAt.getEyeHeight(), targetPos.z, 0, 0, 0);
		float chance = (1 - assumedToBeLookedAt.getHealth() / assumedToBeLookedAt.getMaxHealth());
		if (!player.world.isRemote && player.world.rand.nextFloat() < chance / 10)
		{
			assumedToBeLookedAt.hurtResistantTime = assumedToBeLookedAt.hurtTime = 0;
			assumedToBeLookedAt.attackEntityFrom(DamageSource.causePlayerDamage(player), Float.MAX_VALUE);
		}
	}
}
 
开发者ID:V0idWa1k3r,项目名称:ExPetrum,代码行数:29,代码来源:Behead.java

示例15: onItemUseFinish

import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) {
	stack.damageItem(1, entityLiving);
	return stack;
}
 
开发者ID:sblectric,项目名称:AdvancedCombat,代码行数:6,代码来源:ItemShieldAdvanced.java


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