本文整理了Java中net.minecraft.item.ItemStack.attemptDamageItem()
方法的一些代码示例,展示了ItemStack.attemptDamageItem()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ItemStack.attemptDamageItem()
方法的具体详情如下:
包路径:net.minecraft.item.ItemStack
类名称:ItemStack
方法名:attemptDamageItem
暂无
代码示例来源:origin: SleepyTrousers/EnderIO
protected void damageCapacitor() {
if (isCapacitorDamageable) {
ItemStack cap = inventory[slotDefinition.minUpgradeSlot];
if (cap.attemptDamageItem(1, random, null)) {
this.setInventorySlotContents(slotDefinition.minUpgradeSlot, ItemStack.EMPTY);
}
}
}
代码示例来源:origin: AlgorithmX2/Chisels-and-Bits
public static void damageItem(
@Nonnull final ItemStack is,
@Nonnull final Random r )
{
if ( is.isItemStackDamageable() )
{
if ( is.attemptDamageItem( 1, r, null ) )
{
is.func_190918_g( 1 );
}
}
}
代码示例来源:origin: MrCrayfish/MrCrayfishFurnitureMod
private ItemStack damageTool(ItemStack stack)
{
EntityPlayer craftingPlayer = ForgeHooks.getCraftingPlayer();
if(stack.attemptDamageItem(1, random, craftingPlayer instanceof EntityPlayerMP ? (EntityPlayerMP) craftingPlayer : null))
{
ForgeEventFactory.onPlayerDestroyItem(craftingPlayer, stack, null);
return ItemStack.EMPTY;
}
return stack;
}
代码示例来源:origin: ForestryMC/Binnie
public void damageItem(final ItemStack item, final int slot, final int damage) {
if (damage < 0) {
item.setItemDamage(Math.max(0, item.getItemDamage() + damage));
} else {
if (item.attemptDamageItem(damage, DAMAGE_RANDOM, null)) {
this.setStack(slot, ItemStack.EMPTY);
}
}
this.setStack(slot, item);
}
代码示例来源:origin: CyclopsMC/EvilCraft
@Override
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState blockState, EntityPlayer player, EnumHand hand, EnumFacing side, float coordX, float coordY, float coordZ) {
ItemStack heldItem = player.getHeldItem(hand);
if (!world.isRemote && heldItem != null && heldItem.getItem() == Items.FLINT_AND_STEEL
&& (player.capabilities.isCreativeMode || !heldItem.attemptDamageItem(1, world.rand, (EntityPlayerMP) player))) {
splitBlock(world, blockPos);
return true;
}
return super.onBlockActivated(world, blockPos, blockState, player, hand, side, coordX, coordY, coordZ);
}
代码示例来源:origin: SleepyTrousers/EnderIO
protected void damageCapacitor() {
if (isCapacitorDamageable) {
ItemStack cap = getInventory().getSlot(CAPSLOT).get();
if (cap.attemptDamageItem(1, random, null)) {
getInventory().getSlot(CAPSLOT).clear();
}
}
}
代码示例来源:origin: GregTechCE/GregTech
/**
* Applies specific amount of damage to item, either to durable items (which implement IDamagableItem)
* or to electric items, which have capability IElectricItem
* Damage amount is equal to EU amount used for electric items
* @return if damage was applied successfully
*/
public static boolean doDamageItem(ItemStack itemStack, int vanillaDamage, boolean simulate) {
Item item = itemStack.getItem();
if (item instanceof IDamagableItem) {
//if item implements IDamagableItem, it manages it's own durability itself
IDamagableItem damagableItem = (IDamagableItem) item;
return damagableItem.doDamageToItem(itemStack, vanillaDamage, simulate);
} else if (itemStack.hasCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null)) {
//if we're using electric item, use default energy multiplier for textures
IElectricItem capability = itemStack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
int energyNeeded = vanillaDamage * ConfigHolder.energyUsageMultiplier;
//noinspection ConstantConditions
return capability.discharge(energyNeeded, Integer.MAX_VALUE, true, false, simulate) == energyNeeded;
} else if (itemStack.isItemStackDamageable()) {
if (!simulate && itemStack.attemptDamageItem(vanillaDamage, new Random(), null)) {
//if we can't accept more damage, just shrink stack and mark it as broken
//actually we would play broken animation here, but we don't have an entity who holds item
itemStack.shrink(1);
}
return true;
}
return false;
}
代码示例来源:origin: squeek502/VeganOption
if (stackInSlot.isItemStackDamageable() && stackInSlot.attemptDamageItem(inputToKeep.stackSize, RandomHelper.random))
代码示例来源:origin: Alex-the-666/Ice_and_Fire
if (this.getRNG().nextInt(3) == 0) {
ItemStack weaponStack = new ItemStack(this.getWeaponType().item, 1, 0);
weaponStack.attemptDamageItem(this.getRNG().nextInt(250), this.getRNG(), null);
dropItemAt(weaponStack, this.posX, this.posY, this.posZ);
} else {
代码示例来源:origin: squeek502/VeganOption
@Override
public ItemStack dispenseStack(IBlockSource blockSource, ItemStack itemStack)
{
// counteract the splitStack in super.dispenseStack
itemStack.stackSize++;
super.dispenseStack(blockSource, itemStack);
itemStack.attemptDamageItem(1, RandomHelper.random);
if (itemStack.getItemDamage() >= itemStack.getMaxDamage())
{
itemStack.stackSize = 0;
}
if (itemStack.stackSize == 0 && itemStack.getItem().getContainerItem() != null)
{
return new ItemStack(itemStack.getItem().getContainerItem());
}
return itemStack;
}
代码示例来源:origin: squeek502/VeganOption
@Override
public ItemStack dispenseStack(IBlockSource blockSource, ItemStack itemStack)
{
EnumFacing enumfacing = blockSource.getWorld().getBlockState(blockSource.getBlockPos()).getValue(BlockDispenser.FACING);
int x = (int) blockSource.getX() + enumfacing.getFrontOffsetX();
int y = (int) blockSource.getY() + enumfacing.getFrontOffsetY();
int z = (int) blockSource.getZ() + enumfacing.getFrontOffsetZ();
AxisAlignedBB axisalignedbb = new AxisAlignedBB(x, y, z, x + 1, y + 1, z + 1);
List<EntityLivingBase> entitiesInFront = blockSource.getWorld().getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb);
EntityLivingBase mostDirtyEntity = null;
for (EntityLivingBase entityInFront : entitiesInFront)
{
if (mostDirtyEntity == null || entityInFront.getActivePotionEffects().size() > mostDirtyEntity.getActivePotionEffects().size())
mostDirtyEntity = entityInFront;
}
if (mostDirtyEntity != null)
{
curePotionEffectsAsItem(mostDirtyEntity, milkBucket);
itemStack.attemptDamageItem(1, RandomHelper.random);
if (itemStack.getItemDamage() >= itemStack.getMaxDamage())
{
itemStack.stackSize = 0;
}
return itemStack;
}
return super.dispenseStack(blockSource, itemStack);
}
}
代码示例来源:origin: PrinceOfAmber/Cyclic
wasHarvested.add(targetPos);
player.getHeldItem(player.swingingHand).attemptDamageItem(1, world.rand, null);
代码示例来源:origin: PrinceOfAmber/Cyclic
private void damageTool() {
ItemStack equip = this.getStackInSlot(SLOT_TOOL);
if (equip.isEmpty()) {
return;
}
if (equip.hasCapability(CapabilityEnergy.ENERGY, null)) {
IEnergyStorage storage = equip.getCapability(CapabilityEnergy.ENERGY, null);
if (storage != null) {
storage.extractEnergy(ENERGY_PER_FISH, false);
if (storage.getEnergyStored() <= 0) {
this.sendOutputItem(equip);
this.setInventorySlotContents(SLOT_TOOL, ItemStack.EMPTY);
}
return;
}
}
else if (equip.getMaxDamage() > 0) { // -1 is unbreakable - EX Mystical Ag Supremium Fishing Rods
equip.attemptDamageItem(1, getWorld().rand, null);//does respect unbreaking
//IF enchanted and IF about to break, then spit it out
int damageRem = equip.getMaxDamage() - equip.getItemDamage();
if (damageRem == 1 && EnchantmentHelper.getEnchantments(equip).size() > 0) {
sendOutputItem(equip);
this.setInventorySlotContents(SLOT_TOOL, ItemStack.EMPTY);
} //otherwise we also make sure if its fullly damanged
if (equip.getItemDamage() >= equip.getMaxDamage()) {
this.setInventorySlotContents(SLOT_TOOL, ItemStack.EMPTY);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!