Interface DynamicAttributeTool


public interface DynamicAttributeTool
Interface for adding various tool attributes to items.

Functions in this interface will provide user context if it is available. These context parameters are provided on a best-effort basis, and implementations should not fail hard if they are absent.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Multimap<net.minecraft.entity.attribute.EntityAttribute,net.minecraft.entity.attribute.EntityAttributeModifier>
     
  • Method Summary

    Modifier and Type
    Method
    Description
    default Multimap<net.minecraft.entity.attribute.EntityAttribute,net.minecraft.entity.attribute.EntityAttributeModifier>
    getDynamicModifiers(net.minecraft.entity.EquipmentSlot slot, net.minecraft.item.ItemStack stack, @Nullable net.minecraft.entity.LivingEntity user)
    Add modifiers for any EntityAttributes your item should give when equipped, based on the stack.
    default int
    getMiningLevel(net.minecraft.item.ItemStack stack, @Nullable net.minecraft.entity.LivingEntity user)
    Deprecated.
    default int
    getMiningLevel(net.minecraft.tag.Tag<net.minecraft.item.Item> tag, net.minecraft.block.BlockState state, net.minecraft.item.ItemStack stack, @Nullable net.minecraft.entity.LivingEntity user)
    Determines the mining level of the passed stack, which is used for calculating what blocks this tool is allowed to break.
    default float
    getMiningSpeedMultiplier(net.minecraft.item.ItemStack stack, @Nullable net.minecraft.entity.LivingEntity user)
    default float
    getMiningSpeedMultiplier(net.minecraft.tag.Tag<net.minecraft.item.Item> tag, net.minecraft.block.BlockState state, net.minecraft.item.ItemStack stack, @Nullable net.minecraft.entity.LivingEntity user)
    Determines the mining speed multiplier of the passed stack, which is one factor in overall mining speed.
    default float
    postProcessMiningSpeed(net.minecraft.tag.Tag<net.minecraft.item.Item> tag, net.minecraft.block.BlockState state, net.minecraft.item.ItemStack stack, @Nullable net.minecraft.entity.LivingEntity user, float currentSpeed, boolean isEffective)
    Post process the mining speed, this takes place after the mining speed has been calculated.
  • Field Details

    • EMPTY

      static final Multimap<net.minecraft.entity.attribute.EntityAttribute,net.minecraft.entity.attribute.EntityAttributeModifier> EMPTY
  • Method Details

    • getMiningLevel

      @Deprecated default int getMiningLevel(net.minecraft.item.ItemStack stack, @Nullable @Nullable net.minecraft.entity.LivingEntity user)
      Deprecated.
      Determines the mining level of the passed stack, which is used for calculating what blocks this tool is allowed to break.
      Parameters:
      stack - The item stack being used to mine the block
      user - The current user of the tool, or null if there isn't any
      Returns:
      The mining level of the item. 3 is equal to a diamond pick.
    • getMiningLevel

      default int getMiningLevel(net.minecraft.tag.Tag<net.minecraft.item.Item> tag, net.minecraft.block.BlockState state, net.minecraft.item.ItemStack stack, @Nullable @Nullable net.minecraft.entity.LivingEntity user)
      Determines the mining level of the passed stack, which is used for calculating what blocks this tool is allowed to break.
      Parameters:
      tag - The tool tag the item stack is being compared to
      state - The block to mine
      stack - The item stack being used to mine the block
      user - The current user of the tool, or null if there isn't any
      Returns:
      The mining level of the item. 3 is equal to a diamond pick.
    • getMiningSpeedMultiplier

      @Deprecated default float getMiningSpeedMultiplier(net.minecraft.item.ItemStack stack, @Nullable @Nullable net.minecraft.entity.LivingEntity user)
      Determines the mining speed multiplier of the passed stack, which is one factor in overall mining speed.
      Parameters:
      stack - The item stack being used to mine the block
      user - The current user of the tool, or null if there isn't any
      Returns:
      The mining speed multiplier of the item. 8.0 is equal to a diamond pick.
    • getMiningSpeedMultiplier

      default float getMiningSpeedMultiplier(net.minecraft.tag.Tag<net.minecraft.item.Item> tag, net.minecraft.block.BlockState state, net.minecraft.item.ItemStack stack, @Nullable @Nullable net.minecraft.entity.LivingEntity user)
      Determines the mining speed multiplier of the passed stack, which is one factor in overall mining speed.
      Parameters:
      tag - The tool tag the item stack is being compared to
      state - The block to mine
      stack - The item stack being used to mine the block
      user - The current user of the tool, or null if there isn't any
      Returns:
      The mining speed multiplier of the item. 8.0 is equal to a diamond pick.
    • postProcessMiningSpeed

      default float postProcessMiningSpeed(net.minecraft.tag.Tag<net.minecraft.item.Item> tag, net.minecraft.block.BlockState state, net.minecraft.item.ItemStack stack, @Nullable @Nullable net.minecraft.entity.LivingEntity user, float currentSpeed, boolean isEffective)
      Post process the mining speed, this takes place after the mining speed has been calculated.

      This allows bypassing the regular computation formula.

      Parameters:
      tag - The tool tag the item stack is handled by
      state - The block to mine
      stack - The item stack being used to mine the block
      user - The current user of the tool, or null if there isn't any
      currentSpeed - The mining speed before post process
      isEffective - whether the tool has been handled
      Returns:
      the speed after post processing
    • getDynamicModifiers

      default Multimap<net.minecraft.entity.attribute.EntityAttribute,net.minecraft.entity.attribute.EntityAttributeModifier> getDynamicModifiers(net.minecraft.entity.EquipmentSlot slot, net.minecraft.item.ItemStack stack, @Nullable @Nullable net.minecraft.entity.LivingEntity user)
      Add modifiers for any EntityAttributes your item should give when equipped, based on the stack.

      Appends to either attribute modifier NBT or the result from Item.getAttributeModifiers(EquipmentSlot). The attributes returned from this method will only be applied to an entity when the ItemStack providing the attributes is modified, or the player re-selects the stack in their hotbar. If your attribute relies on data from outside the stack, such as the user's age, you will need to modify the stack in some way to re-assign attributes to the entity. A fix for this may be provided in the future.

      Parameters:
      slot - The equipment slot this item is equipped in.
      stack - The stack that's equipped.
      user - The current user of the tool, if available.
      Returns:
      The dynamic modifiers to add on top of other modifiers on this stack. If none, return EMPTY.