接口 IForgeItem

所有已知实现类:
AirItem, AnimalArmorItem, ArmorItem, ArmorStandItem, ArrowItem, AxeItem, BannerItem, BannerPatternItem, BedItem, BlockItem, BoatItem, BoneMealItem, BottleItem, BowItem, BrushItem, BucketItem, BundleItem, CompassItem, CrossbowItem, DebugStickItem, DiggerItem, DiscFragmentItem, DoubleHighBlockItem, DyeItem, EggItem, EmptyMapItem, EndCrystalItem, EnderEyeItem, EnderpearlItem, ExperienceBottleItem, FireChargeItem, FireworkRocketItem, FireworkStarItem, FishingRodItem, FlintAndSteelItem, FoodOnAStickItem, GameMasterBlockItem, GlowInkSacItem, HangingEntityItem, HangingSignItem, HoeItem, HoneycombItem, InkSacItem, InstrumentItem, Item, ItemFrameItem, KnowledgeBookItem, LeadItem, LingeringPotionItem, MaceItem, MapItem, MinecartItem, MobBucketItem, NameTagItem, PickaxeItem, PlaceOnWaterBlockItem, PlayerHeadItem, PotionItem, ProjectileWeaponItem, SaddleItem, ScaffoldingBlockItem, ShearsItem, ShieldItem, ShovelItem, SignItem, SmithingTemplateItem, SnowballItem, SolidBucketItem, SpawnEggItem, SpectralArrowItem, SplashPotionItem, SpyglassItem, StandingAndWallBlockItem, SwordItem, ThrowablePotionItem, TippedArrowItem, TridentItem, WindChargeItem, WritableBookItem, WrittenBookItem

public interface IForgeItem
  • 方法详细资料

    • self

      private Item self()
    • onDroppedByPlayer

      default boolean onDroppedByPlayer(ItemStack item, 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
      参数:
      item - The item stack, before the item is removed.
      player - The player that dropped the item
    • getHighlightTip

      default Component getHighlightTip(ItemStack item, 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.
      参数:
      item - the ItemStack for the item.
      displayName - the name that will be displayed unless it is changed in this method.
    • onItemUseFirst

      default InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context)
      This is called when the item is used, before the block is activated.
      返回:
      Return PASS to allow vanilla handling, any other to skip normal code.
    • isPiglinCurrency

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

      default boolean makesPiglinsNeutral(ItemStack stack, 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.
      参数:
      wearer - The entity wearing this ItemStack
      返回:
      True if piglins are neutral to players wearing this item in an armor slot
    • onBlockStartBreak

      default boolean onBlockStartBreak(ItemStack itemstack, 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!
      参数:
      itemstack - The current ItemStack
      pos - Block's position in world
      player - The Player that is wielding the item
      返回:
      True to prevent harvesting, false to continue as normal
    • onStopUsing

      default void onStopUsing(ItemStack stack, LivingEntity entity, int count)
      Called when an entity stops using an item for any reason, notably when selecting another item without releasing or finishing. This method is called in addition to any other hooks called when an item is finished using; when another hook is also called it will be called before this method. Note that if you break an item while using it (that is, it becomes empty without swapping the stack instance), this hook may not be called on the serverside as you are technically still using the empty item (thus this hook is called on air instead). It is necessary to call LivingEntity.stopUsingItem() as part of your
      引用无效
      ItemStack#hurtAndBreak(int, LivingEntity, Consumer)
      callback to prevent this issue. For most uses, you likely want one of the following:
      参数:
      stack - The Item being used
      entity - The entity using the item, typically a player
      count - The amount of time in tick the item has been used for continuously
    • onLeftClickEntity

      default boolean onLeftClickEntity(ItemStack stack, Player player, Entity entity)
      Called when the player Left Clicks (attacks) an entity. Processed before damage is done, if return value is true further processing is canceled and the entity is not attacked.
      参数:
      stack - The Item being used
      player - The player that is attacking
      entity - The entity being attacked
      返回:
      True to cancel the rest of the interaction.
    • getCraftingRemainder

      default ItemStack getCraftingRemainder(ItemStack itemStack)
      ItemStack sensitive version of Item.getCraftingRemainder(). Returns a full ItemStack instance of the result.
      参数:
      itemStack - The current ItemStack
      返回:
      The resulting ItemStack
    • getEntityLifespan

      default int getEntityLifespan(ItemStack itemStack, 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.
      参数:
      itemStack - The current ItemStack
      level - The level the entity is in
      返回:
      The normal lifespan in ticks.
    • hasCustomEntity

      default boolean hasCustomEntity(ItemStack stack)
      Determines if this Item has a special entity for when they are in the world. Is called when a EntityItem is spawned in the world, if true and Item#createCustomEntity returns non null, the EntityItem will be destroyed and the new Entity will be added to the world.
      参数:
      stack - The current item stack
      返回:
      True of the item has a custom entity, If true, Item#createCustomEntity will be called
    • createEntity

      @Nullable default @Nullable Entity createEntity(Level level, Entity location, ItemStack stack)
      This function should return a new entity to replace the dropped item. Returning null here will not kill the EntityItem and will leave it to function normally. Called when the item it placed in a level.
      参数:
      level - The level object
      location - The EntityItem object, useful for getting the position of the entity
      stack - The current item stack
      返回:
      A new Entity object to spawn or null
    • onEntityItemUpdate

      default boolean onEntityItemUpdate(ItemStack stack, 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.
      参数:
      entity - The entity Item
      返回:
      Return true to skip any further update code.
    • doesSneakBypassUse

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

      default void onInventoryTick(ItemStack stack, Level level, Player player, int slotIndex, int selectedIndex)
      Called to tick this items in a players inventory, the indexes are the global slot index.
    • canEquip

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

      @Nullable default @Nullable EquipmentSlot getEquipmentSlot(ItemStack stack)
      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)..
      参数:
      stack - the ItemStack
      返回:
      the armor slot of the ItemStack, or null to let the default vanilla logic as per LivingEntity.getSlotForItemStack(stack) decide
    • isBookEnchantable

      default boolean isBookEnchantable(ItemStack stack, ItemStack book)
      Allow or forbid the specific book/item combination as an anvil enchant
      参数:
      stack - The item
      book - The book
      返回:
      if the enchantment is allowed
    • onEntitySwing

      default boolean onEntitySwing(ItemStack stack, LivingEntity entity)
      Called when a entity tries to play the 'swing' animation.
      参数:
      entity - The entity swinging the item.
      返回:
      True to cancel any further processing by EntityLiving
    • canPerformAction

      default boolean canPerformAction(ItemStack stack, ToolAction toolAction)
      Queries if an item can perform the given action. See ToolActions for a description of each stock action
      参数:
      stack - The stack being used
      toolAction - The action being queried
      返回:
      True if the stack can perform the action
    • canApplyAtEnchantingTable

      @Deprecated(forRemoval=true, since="1.21.3") default boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment)
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      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.
      参数:
      stack - the item stack to be enchanted
      enchantment - the enchantment to be applied
      返回:
      true if the enchantment can be applied to this item
    • canApplyAtEnchantingTable

      default boolean canApplyAtEnchantingTable(ItemStack stack, Holder<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.
      参数:
      stack - the item stack to be enchanted
      enchantment - the enchantment to be applied
      返回:
      true if the enchantment can be applied to this item
    • shouldCauseReequipAnimation

      default boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
      Determine if the player switching between these two item stacks
      参数:
      oldStack - The old stack that was equipped
      newStack - The new stack
      slotChanged - If the current equipped slot was changed, Vanilla does not play the animation if you switch between two slots that hold the exact same item.
      返回:
      True to play the item change animation
    • shouldCauseBlockBreakReset

      default boolean shouldCauseBlockBreakReset(ItemStack oldStack, 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.
      参数:
      oldStack - The old stack that was used for mining. Item in players main hand
      newStack - The new stack
      返回:
      True to reset block break progress
    • canContinueUsing

      default boolean canContinueUsing(ItemStack oldStack, ItemStack newStack)
      Called while an item is in 'active' use to determine if usage should continue. Allows items to continue being used while sustaining damage, for example.
      参数:
      oldStack - the previous 'active' stack
      newStack - the stack currently in the active hand
      返回:
      true to set the new stack to active and continue using it
    • getCreatorModId

      @Nullable default @Nullable String getCreatorModId(ItemStack itemStack)
      Called to get the Mod ID of the mod that *created* the ItemStack, instead of the real Mod ID that *registered* it. For example the Forge Universal Bucket creates a subitem for each modded fluid, and it returns the modded fluid's Mod ID here. Mods that register subitems for other mods can override this. Informational mods can call it to show the mod that created the item.
      参数:
      itemStack - the ItemStack to check
      返回:
      the Mod ID for the ItemStack, or null when there is no specially associated mod and IForgeRegistry.getKey(Object) would return null.
    • canDisableShield

      default boolean canDisableShield(ItemStack stack, ItemStack shield, LivingEntity entity, LivingEntity attacker)
      Can this Item disable a shield
      参数:
      stack - The ItemStack
      shield - The shield in question
      entity - The LivingEntity holding the shield
      attacker - The LivingEntity holding the ItemStack
      返回:
      True if this ItemStack can disable the shield in question.
    • getBurnTime

      default int getBurnTime(ItemStack itemStack, @Nullable @Nullable RecipeType<?> recipeType)
      返回:
      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.
    • onHorseArmorTick

      default void onHorseArmorTick(ItemStack stack, Level level, Mob horse)
      Called every tick from Horse#playGallopSound(SoundEvent) on the item in the armor slot.
      参数:
      stack - the armor itemstack
      level - the level the horse is in
      horse - the horse wearing this armor
    • damageItem

      default int damageItem(ItemStack stack, int damage, ServerLevel level, @Nullable @Nullable ServerPlayer player, boolean canBreak, Consumer<Item> onBroken)
      Called when this item is to be damaged, such as use a tool being used or a shield blocking damage. The damage parameter has not yet been processed, so enchantments are not taken into account.
      参数:
      stack - The processed amount of damage the item will take
      damage - The amount of damage the item will take before processing
      level - The level where the damage is taking place
      player - The player holding the item
      canBreak - If the item can break from this damage instance (true if this is called from ItemStack.hurtAndBreak(int, ServerLevel, ServerPlayer, Consumer), false if from ItemStack.hurtWithoutBreaking(int, Player))
      onBroken - The callback for when an item is broken (use this if you plan on cancelling damage that will break an item)
      返回:
      The amount of damage the item should take, after processing
      API Note:
      If the item stack is not damageable or the player has infinite materials, this method will not be called.
    • 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.
      参数:
      itemEntity - The item entity that was destroyed.
      damageSource - Damage source that caused the item entity to "die".
    • isMonsterDisguise

      default boolean isMonsterDisguise(ItemStack stack, Player player, Monster monster)
      Whether this Item can be used to hide player the player from a monster
      参数:
      stack - the ItemStack
      player - The player watching the monster
      monster - The monster that the player look
      返回:
      true if this Item can be used to hide player from monsters
    • canElytraFly

      default boolean canElytraFly(ItemStack stack, LivingEntity entity)
      Used to determine if the player can use Elytra flight. This is called Client and Server side.
      参数:
      stack - The ItemStack in the Chest slot of the entity.
      entity - The entity trying to fly.
      返回:
      True if the entity can use Elytra flight.
    • elytraFlightTick

      default boolean elytraFlightTick(ItemStack stack, 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.
      参数:
      stack - ItemStack in the Chest slot of the entity.
      entity - The entity currently in Elytra flight.
      flightTicks - The number of ticks the entity has been Elytra flying for.
      返回:
      True if the entity should continue Elytra flight or False to stop.
    • canWalkOnPowderedSnow

      default boolean canWalkOnPowderedSnow(ItemStack stack, 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.
      参数:
      stack - Stack instance
      wearer - The entity wearing this ItemStack
      返回:
      True if the entity can walk on powdered snow
    • getSweepHitBox

      @NotNull default @NotNull AABB getSweepHitBox(@NotNull @NotNull ItemStack stack, @NotNull @NotNull Player player, @NotNull @NotNull Entity target)
      Get a bounding box (AABB) of a sweep attack.
      参数:
      stack - the stack held by the player.
      player - the performing the attack the attack.
      target - the entity targeted by the attack.
      返回:
      the bounding box.
    • getDefaultTooltipHideFlags

      default int getDefaultTooltipHideFlags(@NotNull @NotNull ItemStack stack)
      Get the tooltip parts that should be hidden by default on the given stack if the HideFlags tag is not set.
      参数:
      stack - the stack
      返回:
      the default hide flags
      另请参阅:
      • 引用无效
        ItemStack.TooltipPart
    • isNotReplaceableByPickAction

      default boolean isNotReplaceableByPickAction(ItemStack stack, Player player, int inventorySlot)
      Whether the given ItemStack should be excluded (if possible) when selecting the target hotbar slot of a "pick" action. By default, this returns true for enchanted stacks.
      参数:
      player - the player performing the picking
      inventorySlot - the inventory slot of the item being up for replacement
      返回:
      true to leave this stack in the hotbar if possible
      另请参阅:
    • canGrindstoneRepair

      default boolean canGrindstoneRepair(ItemStack stack)
      返回 true if the given ItemStack can be put into a grindstone to be repaired and/or stripped of its enchantments。
      返回:
      true if the given ItemStack can be put into a grindstone to be repaired and/or stripped of its enchantments
    • getCapabilityProvider

      @Nullable @Deprecated(forRemoval=true, since="1.21.4") default @Nullable ICapabilityProvider getCapabilityProvider()
      已过时, 待删除: 此 API 元素将从以后的版本中删除。
      Use the itemstack-sensitive version instead: getCapabilityProvider(ItemStack)
      返回:
      The Default Capability Provider for this item, if any.
    • getCapabilityProvider

      @Nullable default @Nullable ICapabilityProvider getCapabilityProvider(ItemStack stack)
      返回:
      The Default Capability Provider for this item, if any, accounting for the given itemstack.