本文整理了Java中net.minecraft.item.ItemStack.damageItem()
方法的一些代码示例,展示了ItemStack.damageItem()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ItemStack.damageItem()
方法的具体详情如下:
包路径:net.minecraft.item.ItemStack
类名称:ItemStack
方法名:damageItem
暂无
代码示例来源:origin: Vazkii/Botania
public static void damageItem(ItemStack stack, int dmg, EntityLivingBase entity, int manaPerDamage) {
int manaToRequest = dmg * manaPerDamage;
boolean manaRequested = entity instanceof EntityPlayer && ManaItemHandler.requestManaExactForTool(stack, (EntityPlayer) entity, manaToRequest, true);
if(!manaRequested)
stack.damageItem(dmg, entity);
}
代码示例来源:origin: Vazkii/Botania
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, @Nonnull EntityLivingBase attacker) {
if(!target.world.isRemote
&& target instanceof EntityEnderman
&& attacker instanceof EntityPlayer) {
target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 20);
}
stack.damageItem(1, attacker);
return true;
}
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
@Override
public boolean onActivated( final World w, final BlockPos pos, final EntityPlayer player, final EnumHand hand, final @Nullable ItemStack heldItem, final EnumFacing side, final float hitX, final float hitY, final float hitZ )
{
if( heldItem != null && heldItem.getItem() == Items.FLINT_AND_STEEL )
{
this.startFuse( w, pos, player );
w.setBlockToAir( pos );
heldItem.damageItem( 1, player );
return true;
}
else
{
return super.onActivated( w, pos, player, hand, heldItem, side, hitX, hitY, hitZ );
}
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
@Override
public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase) {
par1ItemStack.damageItem(1, par3EntityLivingBase);
return true;
}
代码示例来源:origin: ForestryMC/Binnie
@Override
public void onHammerUsed(ItemStack itemStack, EntityPlayer player) {
itemStack.damageItem(1, player);
}
}
代码示例来源:origin: SleepyTrousers/EnderIO
@Override
public void damageArmor(EntityLivingBase entity, @Nonnull ItemStack stack, DamageSource source, int damage, int slot) {
if (entity != null) {
stack.damageItem(damage, entity);
}
}
代码示例来源:origin: joshiejack/Mariculture
@Override
public void damageArmor(EntityLivingBase entity, ItemStack stack, DamageSource source, int damage, int slot) {
if (source.getEntity() instanceof EntityGuardian) {
if (entity.worldObj.rand.nextInt(64) == 0) stack.damageItem(damage, entity);
} else stack.damageItem(damage, entity);
}
}
代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2
private void makePlate()
{
if( Platform.isServer() )
{
if( !this.getItemHandler().extractItem( 0, 1, false ).isEmpty() )
{
final ItemStack item = ContainerQuartzKnife.this.toolInv.getItemStack();
final ItemStack before = item.copy();
item.damageItem( 1, ContainerQuartzKnife.this.getPlayerInv().player );
if( item.getCount() == 0 )
{
ContainerQuartzKnife.this.getPlayerInv()
.setInventorySlotContents( ContainerQuartzKnife.this.getPlayerInv().currentItem, ItemStack.EMPTY );
MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( ContainerQuartzKnife.this.getPlayerInv().player, before, null ) );
}
ContainerQuartzKnife.this.detectAndSendChanges();
}
}
}
}
代码示例来源:origin: TeamLapen/Vampirism
@Override
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) {
if ((double) state.getBlockHardness(worldIn, pos) != 0.0D) {
stack.damageItem(2, entityLiving);
}
return true;
}
代码示例来源:origin: ForestryMC/ForestryMC
@Override
public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) {
if (state.getBlockHardness(worldIn, pos) != 0) {
stack.damageItem(1, entityLiving);
}
return true;
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) {
if (state.getBlockHardness(world, pos) != 0) {
stack.damageItem(2, entityLiving);
}
return true;
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) {
if (state.getBlockHardness(world, pos) != 0) {
stack.damageItem(2, entityLiving);
}
return true;
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
@Override
public boolean onBlockDestroyed(ItemStack stack, World world, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) {
if (state.getBlockHardness(world, pos) != 0) {
stack.damageItem(2, entityLiving);
}
return true;
}
代码示例来源:origin: SleepyTrousers/EnderIO
protected void setBlock(ItemStack stack, @Nonnull EntityPlayer player, World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
worldIn.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
if (!worldIn.isRemote) {
worldIn.setBlockState(pos, state, 11);
stack.damageItem(1, player);
}
}
代码示例来源:origin: SleepyTrousers/EnderIO
protected void setBlock(ItemStack stack, @Nonnull EntityPlayer player, World worldIn, @Nonnull BlockPos pos, @Nonnull IBlockState state) {
worldIn.playSound(player, pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F);
if (!worldIn.isRemote) {
worldIn.setBlockState(pos, state, 11);
stack.damageItem(1, player);
}
}
代码示例来源:origin: Vazkii/Botania
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing s, float xs, float ys, float zs) {
TileIncensePlate plate = (TileIncensePlate) world.getTileEntity(pos);
ItemStack plateStack = plate.getItemHandler().getStackInSlot(0);
ItemStack stack = player.getHeldItem(hand);
boolean did = false;
if(world.isRemote)
return true;
if(plateStack.isEmpty() && plate.acceptsItem(stack)) {
plate.getItemHandler().setStackInSlot(0, stack.copy());
stack.shrink(1);
did = true;
} else if(!plateStack.isEmpty() && !plate.burning) {
if(!stack.isEmpty() && stack.getItem() == Items.FLINT_AND_STEEL) {
plate.ignite();
stack.damageItem(1, player);
did = true;
} else {
ItemHandlerHelper.giveItemToPlayer(player, plateStack);
plate.getItemHandler().setStackInSlot(0, ItemStack.EMPTY);
did = true;
}
}
if(did)
VanillaPacketDispatcher.dispatchTEToNearbyPlayers(plate);
return did;
}
代码示例来源:origin: P3pp3rF1y/AncientWarfare2
private void addResearchEnergy(EntityPlayer player, ItemStack stack, IWorkSite teResearchStation) {
if (teResearchStation.hasWork()) {
teResearchStation.addEnergyFromPlayer(player);
stack.damageItem(1, player);
}
}
代码示例来源:origin: Silentine/GrimoireOfGaia
@Override
public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase host) {
stack.damageItem(1, host);
host.playSound(Sounds.BOOK_HIT, 1.0F, 1.0F);
target.addPotionEffect(new PotionEffect(MobEffects.BLINDNESS, 80, 0));
return true;
}
代码示例来源:origin: SleepyTrousers/EnderIO
private void damageTool(@Nonnull ItemStack tool, int toolIndex) {
if (Prep.isValid(tool) && tool.isItemStackDamageable()) {
tool.damageItem(1, getFakePlayer());
if (tool.getItemDamage() >= tool.getMaxDamage()) {
tool.shrink(1);
}
markDirty();
}
}
代码示例来源:origin: vadis365/TheErebus
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack stack) {
if (player.getFoodStats().needFood() && stack.getItemDamage() != 40) {
player.getFoodStats().addStats(1, 0.2F);
stack.damageItem(1, player);
}
}
内容来源于网络,如有侵权,请联系作者删除!