Interface IForgeItemStack

All Superinterfaces:
ICapabilityProvider, ICapabilitySerializable<CompoundTag>, INBTSerializable<CompoundTag>
All Known Implementing Classes:
ItemStack

public interface IForgeItemStack extends ICapabilitySerializable<CompoundTag>
  • Method Details

    • self

      private ItemStack self()
    • getCraftingRemainingItem

      default ItemStack getCraftingRemainingItem()
      ItemStack sensitive version of Item.getCraftingRemainingItem(). Returns a full ItemStack instance of the result.
      Returns:
      The resulting ItemStack
    • hasCraftingRemainingItem

      default boolean hasCraftingRemainingItem()
      ItemStack sensitive version of Item.hasCraftingRemainingItem().
      Returns:
      True if this item has a crafting remaining item
    • getBurnTime

      default int getBurnTime(@Nullable @Nullable RecipeType<?> recipeType)
      Returns:
      the fuel burn time for this itemStack in a furnace. Return 0 to make it not act as a fuel. Return -1 to let the default vanilla logic decide.
    • onItemUseFirst

      default InteractionResult onItemUseFirst(UseOnContext context)
    • serializeNBT

      default CompoundTag serializeNBT()
      Specified by:
      serializeNBT in interface INBTSerializable<CompoundTag>
    • canPerformAction

      default boolean canPerformAction(ToolAction toolAction)
      Queries if an item can perform the given action. See ToolActions for a description of each stock action
      Parameters:
      toolAction - The action being queried
      Returns:
      True if the stack can perform the action
    • onBlockStartBreak

      default boolean onBlockStartBreak(BlockPos pos, Player player)
      Called before a block is broken. Return true to prevent default block harvesting. Note: In SMP, this is called on both client and server sides!
      Parameters:
      pos - Block's position in world
      player - The Player that is wielding the item
      Returns:
      True to prevent harvesting, false to continue as normal
    • shouldCauseBlockBreakReset

      default boolean shouldCauseBlockBreakReset(ItemStack newStack)
      Called when the player is mining a block and the item in his hand changes. Allows to not reset blockbreaking if only NBT or similar changes.
      Parameters:
      newStack - The new stack
      Returns:
      True to reset block break progress
    • canApplyAtEnchantingTable

      default boolean canApplyAtEnchantingTable(Enchantment enchantment)
      Checks whether an item can be enchanted with a certain enchantment. This applies specifically to enchanting an item in the enchanting table and is called when retrieving the list of possible enchantments for an item. Enchantments may additionally (or exclusively) be doing their own checks in Enchantment.canApplyAtEnchantingTable(ItemStack); check the individual implementation for reference. By default this will check if the enchantment type is valid for this item type.
      Parameters:
      enchantment - the enchantment to be applied
      Returns:
      true if the enchantment can be applied to this item
    • getEnchantmentLevel

      default int getEnchantmentLevel(Enchantment enchantment)
      Gets the level of the enchantment currently present on the stack. By default, returns the enchantment level present in NBT. Equivalent to calling EnchantmentHelper.getItemEnchantmentLevel(Enchantment, ItemStack) Use in place of EnchantmentHelper.getTagEnchantmentLevel(Enchantment, ItemStack) for checking presence of an enchantment in logic implementing the enchantment behavior. Use EnchantmentHelper.getTagEnchantmentLevel(Enchantment, ItemStack) instead when modifying an item's enchantments.
      Parameters:
      enchantment - the enchantment being checked for
      Returns:
      Level of the enchantment, or 0 if not present
      See Also:
    • getAllEnchantments

      default Map<Enchantment,Integer> getAllEnchantments()
      Gets a map of all enchantments present on the stack. By default, returns the enchantments present in NBT, ignoring book enchantments. Use in place of EnchantmentHelper.getEnchantments(ItemStack) for checking presence of an enchantment in logic implementing the enchantment behavior. Use EnchantmentHelper.getEnchantments(ItemStack) instead when modifying an item's enchantments.
      Returns:
      Map of all enchantments on the stack, empty if no enchantments are present
      See Also:
    • getEnchantmentValue

      default int getEnchantmentValue()
      ItemStack sensitive version of Item.getEnchantmentValue().
      Returns:
      the enchantment value of this ItemStack
    • getEquipmentSlot

      @Nullable default @Nullable EquipmentSlot getEquipmentSlot()
      Override this to set a non-default armor slot for an ItemStack, but do not use this to get the armor slot of said stack; for that, use LivingEntity.getEquipmentSlotForItem(ItemStack).
      Returns:
      the armor slot of the ItemStack, or null to let the default vanilla logic as per LivingEntity.getSlotForItemStack(stack) decide
    • canDisableShield

      default boolean canDisableShield(ItemStack shield, LivingEntity entity, LivingEntity attacker)
      Can this Item disable a shield
      Parameters:
      shield - The shield in question
      entity - The LivingEntity holding the shield
      attacker - The LivingEntity holding the ItemStack
      Returns:
      True if this ItemStack can disable the shield in question.
    • onEntitySwing

      default boolean onEntitySwing(LivingEntity entity)
      Called when a entity tries to play the 'swing' animation.
      Parameters:
      entity - The entity swinging the item.
      Returns:
      True to cancel any further processing by EntityLiving
    • onUsingTick

      @Deprecated(since="1.19.4", forRemoval=true) default void onUsingTick(LivingEntity player, int count)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Called each tick while using an item.
      Parameters:
      player - The Player using the item
      count - The amount of time in tick the item has been used for continuously
    • onStopUsing

      default void onStopUsing(LivingEntity entity, int count)
      Called when an entity stops using an item item for any reason.
      Parameters:
      entity - The entity using the item, typically a player
      count - The amount of time in tick the item has been used for continuously
    • getEntityLifespan

      default int getEntityLifespan(Level level)
      Retrieves the normal 'lifespan' of this item when it is dropped on the ground as a EntityItem. This is in ticks, standard result is 6000, or 5 mins.
      Parameters:
      level - The level the entity is in
      Returns:
      The normal lifespan in ticks.
    • onEntityItemUpdate

      default boolean onEntityItemUpdate(ItemEntity entity)
      Called by the default implemetation of EntityItem's onUpdate method, allowing for cleaner control over the update of the item without having to write a subclass.
      Parameters:
      entity - The entity Item
      Returns:
      Return true to skip any further update code.
    • getXpRepairRatio

      default float getXpRepairRatio()
      Determines the amount of durability the mending enchantment will repair, on average, per point of experience.
    • onArmorTick

      default void onArmorTick(Level level, Player player)
      Called to tick armor in the armor slot. Override to do something
    • onHorseArmorTick

      default void onHorseArmorTick(Level level, Mob horse)
      Called every tick from Horse#playGallopSound(SoundEvent) on the item in the armor slot.
      Parameters:
      level - the level the horse is in
      horse - the horse wearing this armor
    • canEquip

      default boolean canEquip(EquipmentSlot armorType, Entity entity)
      Determines if the specific ItemStack can be placed in the specified armor slot, for the entity.
      Parameters:
      armorType - Armor slot to be verified.
      entity - The entity trying to equip the armor
      Returns:
      True if the given ItemStack can be inserted in the slot
    • isBookEnchantable

      default boolean isBookEnchantable(ItemStack book)
      Allow or forbid the specific book/item combination as an anvil enchant
      Parameters:
      book - The book
      Returns:
      if the enchantment is allowed
    • onDroppedByPlayer

      default boolean onDroppedByPlayer(Player player)
      Called when a player drops the item into the world, returning false from this will prevent the item from being removed from the players inventory and spawning in the world
      Parameters:
      player - The player that dropped the item
    • getHighlightTip

      default Component getHighlightTip(Component displayName)
      Allow the item one last chance to modify its name used for the tool highlight useful for adding something extra that can't be removed by a user in the displayed name, such as a mode of operation.
      Parameters:
      displayName - the name that will be displayed unless it is changed in this method.
    • getShareTag

      @Nullable default @Nullable CompoundTag getShareTag()
      Get the NBT data to be sent to the client. The Item can control what data is kept in the tag. Note that this will sometimes be applied multiple times, the following MUST be supported: Item item = stack.getItem(); NBTTagCompound nbtShare1 = item.getNBTShareTag(stack); stack.setTagCompound(nbtShare1); NBTTagCompound nbtShare2 = item.getNBTShareTag(stack); assert nbtShare1.equals(nbtShare2);
      Returns:
      The NBT tag
    • readShareTag

      default void readShareTag(@Nullable @Nullable CompoundTag nbt)
      Override this method to decide what to do with the NBT data received from getNBTShareTag().
      Parameters:
      nbt - Received NBT, can be null
    • doesSneakBypassUse

      default boolean doesSneakBypassUse(LevelReader level, BlockPos pos, Player player)
      Should this item, when held, allow sneak-clicks to pass through to the underlying block?
      Parameters:
      level - The level
      pos - Block position in level
      player - The Player that is wielding the item
    • areShareTagsEqual

      default boolean areShareTagsEqual(ItemStack other)
      Modeled after ItemStack.areItemStackTagsEqual Uses Item.getNBTShareTag for comparison instead of NBT and capabilities. Only used for comparing itemStacks that were transferred from server to client using Item.getNBTShareTag.
    • equals

      default boolean equals(ItemStack other, boolean limitTags)
      Determines if the ItemStack is equal to the other item stack, including Item, Count, and NBT.
      Parameters:
      other - The other stack
      limitTags - True to use shareTag False to use full NBT tag
      Returns:
      true if equals
    • isRepairable

      default boolean isRepairable()
      Determines if a item is reparable, used by Repair recipes and Grindstone.
      Returns:
      True if reparable
    • isPiglinCurrency

      default boolean isPiglinCurrency()
      Called by Piglins when checking to see if they will give an item or something in exchange for this item.
      Returns:
      True if this item can be used as "currency" by piglins
    • makesPiglinsNeutral

      default boolean makesPiglinsNeutral(LivingEntity wearer)
      Called by Piglins to check if a given item prevents hostility on sight. If this is true the Piglins will be neutral to the entity wearing this item, and will not attack on sight. Note: This does not prevent Piglins from becoming hostile due to other actions, nor does it make Piglins that are already hostile stop being so.
      Parameters:
      wearer - The entity wearing this ItemStack
      Returns:
      True if piglins are neutral to players wearing this item in an armor slot
    • isEnderMask

      default boolean isEnderMask(Player player, EnderMan endermanEntity)
      Whether this Item can be used to hide player head for enderman.
      Parameters:
      player - The player watching the enderman
      endermanEntity - The enderman that the player look
      Returns:
      true if this Item can be used.
    • canElytraFly

      default boolean canElytraFly(LivingEntity entity)
      Used to determine if the player can use Elytra flight. This is called Client and Server side.
      Parameters:
      entity - The entity trying to fly.
      Returns:
      True if the entity can use Elytra flight.
    • elytraFlightTick

      default boolean elytraFlightTick(LivingEntity entity, int flightTicks)
      Used to determine if the player can continue Elytra flight, this is called each tick, and can be used to apply ItemStack damage, consume Energy, or what have you. For example the Vanilla implementation of this, applies damage to the ItemStack every 20 ticks.
      Parameters:
      entity - The entity currently in Elytra flight.
      flightTicks - The number of ticks the entity has been Elytra flying for.
      Returns:
      True if the entity should continue Elytra flight or False to stop.
    • canWalkOnPowderedSnow

      default boolean canWalkOnPowderedSnow(LivingEntity wearer)
      Called by the powdered snow block to check if a living entity wearing this can walk on the snow, granting the same behavior as leather boots. Only affects items worn in the boots slot.
      Parameters:
      wearer - The entity wearing this ItemStack
      Returns:
      True if the entity can walk on powdered snow
    • getSweepHitBox

      @NotNull default @NotNull AABB getSweepHitBox(@NotNull @NotNull Player player, @NotNull @NotNull Entity target)
      Get a bounding box (AABB) of a sweep attack.
      Parameters:
      player - the performing the attack the attack.
      target - the entity targeted by the attack.
      Returns:
      the bounding box.
    • onDestroyed

      default void onDestroyed(ItemEntity itemEntity, DamageSource damageSource)
      Called when an item entity for this stack is destroyed. Note: The ItemStack can be retrieved from the item entity.
      Parameters:
      itemEntity - The item entity that was destroyed.
      damageSource - Damage source that caused the item entity to "die".
    • getFoodProperties

      @Nullable default @Nullable FoodProperties getFoodProperties(@Nullable @Nullable LivingEntity entity)
      Get the food properties for this item. This is a bouncer for easier use of IForgeItem.getFoodProperties(ItemStack, LivingEntity) The @Nullable annotation was only added, due to the default method, also being @Nullable. Use this with a grain of salt, as if you return null here and true at Item.isEdible(), NPEs will occur!
      Parameters:
      entity - The entity which wants to eat the food. Be aware that this can be null!
      Returns:
      The current FoodProperties for the item.
    • isNotReplaceableByPickAction

      default boolean isNotReplaceableByPickAction(Player player, int inventorySlot)
      Whether this stack should be excluded (if possible) when selecting the target hotbar slot of a "pick" action. By default, this returns true for enchanted stacks.
      Parameters:
      player - the player performing the picking
      inventorySlot - the inventory slot of the item being up for replacement
      Returns:
      true to leave this stack in the hotbar if possible
      See Also:
    • canGrindstoneRepair

      default boolean canGrindstoneRepair()
      Returns true if the given ItemStack can be put into a grindstone to be repaired and/or stripped of its enchantments.
      Returns:
      true if the given ItemStack can be put into a grindstone to be repaired and/or stripped of its enchantments