本文整理汇总了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);
}
示例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);
}
}
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
}
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例15: onItemUseFinish
import net.minecraft.item.ItemStack; //导入方法依赖的package包/类
@Override
public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) {
stack.damageItem(1, entityLiving);
return stack;
}